blob: 2eb25edb59e93bbaecd0811e4c9e1deb6e3117a3 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Configuration parser
3 *
Willy Tarreauff011f22011-01-06 17:51:27 +01004 * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Cyril Bonté1a0191d2014-08-29 20:20:02 +020013#ifdef CONFIG_HAP_CRYPT
14/* This is to have crypt() defined on Linux */
15#define _GNU_SOURCE
16
17#ifdef NEED_CRYPT_H
18/* some platforms such as Solaris need this */
19#include <crypt.h>
20#endif
21#endif /* CONFIG_HAP_CRYPT */
22
Willy Tarreaubaaee002006-06-26 02:48:02 +020023#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <netdb.h>
27#include <ctype.h>
Willy Tarreau95c20ac2007-03-25 15:39:23 +020028#include <pwd.h>
29#include <grp.h>
Willy Tarreau0b4ed902007-03-26 00:18:40 +020030#include <errno.h>
Willy Tarreau3f49b302007-06-11 00:29:26 +020031#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <unistd.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035
Willy Tarreau2dd0d472006-06-29 17:53:05 +020036#include <common/cfgparse.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020037#include <common/chunk.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020038#include <common/config.h>
Willy Tarreau058e9072009-07-20 09:30:05 +020039#include <common/errors.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020040#include <common/memory.h>
41#include <common/standard.h>
42#include <common/time.h>
43#include <common/uri_auth.h>
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +010044#include <common/namespace.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020045
46#include <types/capture.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020047#include <types/compression.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020048#include <types/filters.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020049#include <types/global.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010050#include <types/obj_type.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020051#include <types/peers.h>
Simon Horman0d16a402015-01-30 11:22:58 +090052#include <types/mailers.h>
Baptiste Assmann325137d2015-04-13 23:40:55 +020053#include <types/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010054#include <types/stats.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020055
Willy Tarreaueb0c6142007-05-07 00:53:22 +020056#include <proto/acl.h>
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +010057#include <proto/auth.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020058#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020059#include <proto/channel.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020060#include <proto/checks.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020061#include <proto/compression.h>
William Lallemand9ed62032016-11-21 17:49:11 +010062#include <proto/stats.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020063#include <proto/filters.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020064#include <proto/frontend.h>
Willy Tarreau34eb6712011-10-24 18:15:04 +020065#include <proto/hdr_idx.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020066#include <proto/lb_chash.h>
Willy Tarreauf09c6602012-02-13 17:12:08 +010067#include <proto/lb_fas.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020068#include <proto/lb_fwlc.h>
69#include <proto/lb_fwrr.h>
70#include <proto/lb_map.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020071#include <proto/listener.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020072#include <proto/log.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020073#include <proto/protocol.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010074#include <proto/proto_tcp.h>
Emeric Bruned760922010-10-22 17:59:25 +020075#include <proto/proto_uxst.h>
Willy Tarreaue6b98942007-10-29 01:09:36 +010076#include <proto/proto_http.h>
Willy Tarreau2b5652f2006-12-31 17:46:05 +010077#include <proto/proxy.h>
Emeric Brun32da3c42010-09-23 18:39:19 +020078#include <proto/peers.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020079#include <proto/sample.h>
Willy Tarreau9903f0e2015-04-04 18:50:31 +020080#include <proto/session.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020081#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020082#include <proto/stream.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010083#include <proto/stick_table.h>
Willy Tarreau39713102016-11-25 15:49:32 +010084#include <proto/task.h>
85#include <proto/tcp_rules.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020086
87
Willy Tarreauf3c69202006-07-09 16:42:34 +020088/* This is the SSLv3 CLIENT HELLO packet used in conjunction with the
89 * ssl-hello-chk option to ensure that the remote server speaks SSL.
90 *
91 * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details.
92 */
93const char sslv3_client_hello_pkt[] = {
94 "\x16" /* ContentType : 0x16 = Hanshake */
95 "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */
96 "\x00\x79" /* ContentLength : 0x79 bytes after this one */
97 "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */
98 "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */
99 "\x03\x00" /* Hello Version : 0x0300 = v3 */
100 "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */
101 "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */
102 "\x00" /* Session ID length : empty (no session ID) */
103 "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */
104 "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */
105 "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */
106 "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */
107 "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */
108 "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */
109 "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18"
110 "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F"
111 "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33"
112 "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37"
113 "\x00\x38" "\x00\x39" "\x00\x3A"
114 "\x01" /* Compression Length : 0x01 = 1 byte for types */
115 "\x00" /* Compression Type : 0x00 = NULL compression */
116};
117
Willy Tarreau3842f002009-06-14 11:39:52 +0200118/* various keyword modifiers */
119enum kw_mod {
120 KWM_STD = 0, /* normal */
121 KWM_NO, /* "no" prefixed before the keyword */
122 KWM_DEF, /* "default" prefixed before the keyword */
123};
124
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +0100125/* permit to store configuration section */
126struct cfg_section {
127 struct list list;
128 char *section_name;
129 int (*section_parser)(const char *, int, char **, int);
130};
131
132/* Used to chain configuration sections definitions. This list
133 * stores struct cfg_section
134 */
135struct list sections = LIST_HEAD_INIT(sections);
136
Willy Tarreau13943ab2006-12-31 00:24:10 +0100137/* some of the most common options which are also the easiest to handle */
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100138struct cfg_opt {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100139 const char *name;
140 unsigned int val;
141 unsigned int cap;
Willy Tarreau4fee4e92007-01-06 21:09:17 +0100142 unsigned int checks;
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100143 unsigned int mode;
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100144};
145
146/* proxy->options */
147static const struct cfg_opt cfg_opts[] =
Willy Tarreau13943ab2006-12-31 00:24:10 +0100148{
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100149 { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 },
150 { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 },
151 { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP },
152 { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 },
153 { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 },
154 { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100155 { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau9fbe18e2015-05-01 22:42:08 +0200156 { "http-buffer-request", PR_O_WREQ_BODY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau0f228a02015-05-01 15:37:53 +0200157 { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP },
Willy Tarreau9420b122013-12-15 18:58:25 +0100158 { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100159 { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 },
160 { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 },
161 { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100162 { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 },
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100163#ifdef TPROXY
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100164 { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 },
Cyril Bonté62846b22010-11-01 19:26:00 +0100165#else
166 { "transparent", 0, 0, 0, 0 },
Willy Tarreau8f922fc2007-01-06 21:11:49 +0100167#endif
168
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100169 { NULL, 0, 0, 0, 0 }
Willy Tarreau13943ab2006-12-31 00:24:10 +0100170};
171
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100172/* proxy->options2 */
173static const struct cfg_opt cfg_opts2[] =
174{
175#ifdef CONFIG_HAP_LINUX_SPLICE
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100176 { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 },
177 { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
178 { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Cyril Bonté62846b22010-11-01 19:26:00 +0100179#else
180 { "splice-request", 0, 0, 0, 0 },
181 { "splice-response", 0, 0, 0, 0 },
182 { "splice-auto", 0, 0, 0, 0 },
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100183#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100184 { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP },
185 { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP },
186 { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 },
187 { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 },
188 { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 },
189 { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 },
190 { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 },
191 { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 },
192 { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Jamie Gloudon801a0a32012-08-25 00:18:33 -0400193 { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 },
Willy Tarreaue24fdfb2010-03-25 07:22:56 +0100194 { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP },
Willy Tarreaue52564c2010-04-27 22:19:14 +0200195 { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau96e31212011-05-30 18:10:30 +0200196 { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP },
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100197 { NULL, 0, 0, 0 }
198};
Willy Tarreaubaaee002006-06-26 02:48:02 +0200199
Willy Tarreau6daf3432008-01-22 16:44:08 +0100200static char *cursection = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200201static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
202int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
Willy Tarreau5af24ef2009-03-15 15:23:16 +0100203int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
Christopher Faulet79bdef32016-11-04 22:36:15 +0100204char *cfg_scope = NULL; /* the current scope during the configuration parsing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200205
Willy Tarreau5b2c3362008-07-09 19:39:06 +0200206/* List head of all known configuration keywords */
207static struct cfg_kw_list cfg_keywords = {
208 .list = LIST_HEAD_INIT(cfg_keywords.list)
209};
210
Willy Tarreaubaaee002006-06-26 02:48:02 +0200211/*
212 * converts <str> to a list of listeners which are dynamically allocated.
213 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
214 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
215 * - <port> is a numerical port from 1 to 65535 ;
216 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
217 * This can be repeated as many times as necessary, separated by a coma.
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200218 * Function returns 1 for success or 0 if error. In case of errors, if <err> is
219 * not NULL, it must be a valid pointer to either NULL or a freeable area that
220 * will be replaced with an error message.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200221 */
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200222int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200223{
224 struct listener *l;
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100225 char *next, *dupstr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200226 int port, end;
227
228 next = dupstr = strdup(str);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200229
Willy Tarreaubaaee002006-06-26 02:48:02 +0200230 while (next && *next) {
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100231 struct sockaddr_storage ss, *ss2;
Willy Tarreau40aa0702013-03-10 23:51:38 +0100232 int fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200233
234 str = next;
235 /* 1) look for the end of the first address */
Krzysztof Piotr Oledzki52d522b2009-01-27 16:57:08 +0100236 if ((next = strchr(str, ',')) != NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200237 *next++ = 0;
238 }
239
Willy Tarreau48ef4c92017-01-06 18:32:38 +0100240 ss2 = str2sa_range(str, NULL, &port, &end, err,
Willy Tarreau72b8c1f2015-09-08 15:50:19 +0200241 curproxy == global.stats_fe ? NULL : global.unix_bind.prefix,
Thierry FOURNIER7fe3be72015-09-26 20:03:36 +0200242 NULL, 1);
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100243 if (!ss2)
244 goto fail;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200245
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100246 if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100247 if (!port && !end) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200248 memprintf(err, "missing port number: '%s'\n", str);
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100249 goto fail;
Emeric Bruned760922010-10-22 17:59:25 +0200250 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200251
Willy Tarreau6d03cc32013-02-20 17:26:02 +0100252 if (!port || !end) {
253 memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str);
254 goto fail;
255 }
256
Emeric Bruned760922010-10-22 17:59:25 +0200257 if (port < 1 || port > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200258 memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str);
Emeric Bruned760922010-10-22 17:59:25 +0200259 goto fail;
260 }
261
262 if (end < 1 || end > 65535) {
Willy Tarreau4fbb2282012-09-20 20:01:39 +0200263 memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str);
Emeric Bruned760922010-10-22 17:59:25 +0200264 goto fail;
265 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200266 }
Willy Tarreau40aa0702013-03-10 23:51:38 +0100267 else if (ss2->ss_family == AF_UNSPEC) {
268 socklen_t addr_len;
269
270 /* We want to attach to an already bound fd whose number
271 * is in the addr part of ss2 when cast to sockaddr_in.
272 * Note that by definition there is a single listener.
273 * We still have to determine the address family to
274 * register the correct protocol.
275 */
276 fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr;
277 addr_len = sizeof(*ss2);
278 if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) {
279 memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno));
280 goto fail;
281 }
282
283 port = end = get_host_port(ss2);
284 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200285
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100286 /* OK the address looks correct */
Vincent Bernat6e615892016-05-18 16:17:44 +0200287 memcpy(&ss, ss2, sizeof(ss));
Willy Tarreau12eb2a62013-03-06 15:45:03 +0100288
Willy Tarreaubaaee002006-06-26 02:48:02 +0200289 for (; port <= end; port++) {
Vincent Bernat02779b62016-04-03 13:48:43 +0200290 l = calloc(1, sizeof(*l));
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100291 l->obj_type = OBJ_TYPE_LISTENER;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200292 LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe);
293 LIST_ADDQ(&bind_conf->listeners, &l->by_bind);
Willy Tarreau4348fad2012-09-20 16:48:07 +0200294 l->bind_conf = bind_conf;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200295
Willy Tarreau40aa0702013-03-10 23:51:38 +0100296 l->fd = fd;
Vincent Bernat6e46ff12016-05-19 11:29:43 +0200297 memcpy(&l->addr, &ss, sizeof(ss));
Willy Tarreaue6b98942007-10-29 01:09:36 +0100298 l->state = LI_INIT;
299
Willy Tarreau2dff0c22011-03-04 15:43:13 +0100300 if (ss.ss_family == AF_INET) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200301 ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port);
Willy Tarreaue6b98942007-10-29 01:09:36 +0100302 tcpv4_add_listener(l);
303 }
Emeric Bruned760922010-10-22 17:59:25 +0200304 else if (ss.ss_family == AF_INET6) {
305 ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port);
306 tcpv6_add_listener(l);
307 }
308 else {
Emeric Bruned760922010-10-22 17:59:25 +0200309 uxst_add_listener(l);
310 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200311
Willy Tarreauaf7ad002010-08-31 15:39:26 +0200312 jobs++;
Willy Tarreaue6b98942007-10-29 01:09:36 +0100313 listeners++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200314 } /* end for(port) */
315 } /* end while(next) */
316 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200317 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200318 fail:
319 free(dupstr);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200320 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200321}
322
William Lallemand6e62fb62015-04-28 16:55:23 +0200323/*
Willy Tarreauece9b072016-12-21 22:41:44 +0100324 * Report an error in <msg> when there are too many arguments. This version is
325 * intended to be used by keyword parsers so that the message will be included
326 * into the general error message. The index is the current keyword in args.
327 * Return 0 if the number of argument is correct, otherwise build a message and
328 * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The
329 * message may also be null, it will simply not be produced (useful to check only).
330 * <msg> and <err_code> are only affected on error.
331 */
332int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code)
333{
334 int i;
335
336 if (!*args[index + maxarg + 1])
337 return 0;
338
339 if (msg) {
340 *msg = NULL;
341 memprintf(msg, "%s", args[0]);
342 for (i = 1; i <= index; i++)
343 memprintf(msg, "%s %s", *msg, args[i]);
344
345 memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]);
346 }
347 if (err_code)
348 *err_code |= ERR_ALERT | ERR_FATAL;
349
350 return 1;
351}
352
353/*
354 * same as too_many_args_idx with a 0 index
355 */
356int too_many_args(int maxarg, char **args, char **msg, int *err_code)
357{
358 return too_many_args_idx(maxarg, 0, args, msg, err_code);
359}
360
361/*
William Lallemand6e62fb62015-04-28 16:55:23 +0200362 * Report a fatal Alert when there is too much arguments
363 * The index is the current keyword in args
364 * Return 0 if the number of argument is correct, otherwise emit an alert and return 1
365 * Fill err_code with an ERR_ALERT and an ERR_FATAL
366 */
367int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code)
368{
369 char *kw = NULL;
370 int i;
371
372 if (!*args[index + maxarg + 1])
373 return 0;
374
375 memprintf(&kw, "%s", args[0]);
376 for (i = 1; i <= index; i++) {
377 memprintf(&kw, "%s %s", kw, args[i]);
378 }
379
380 Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]);
381 free(kw);
382 *err_code |= ERR_ALERT | ERR_FATAL;
383 return 1;
384}
385
386/*
387 * same as alertif_too_many_args_idx with a 0 index
388 */
389int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code)
390{
391 return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code);
392}
393
Willy Tarreau620408f2016-10-21 16:37:51 +0200394/* Report a warning if a rule is placed after a 'tcp-request session' rule.
395 * Return 1 if the warning has been emitted, otherwise 0.
396 */
397int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
398{
399 if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) {
400 Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n",
401 file, line, arg);
402 return 1;
403 }
404 return 0;
405}
406
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200407/* Report a warning if a rule is placed after a 'tcp-request content' rule.
408 * Return 1 if the warning has been emitted, otherwise 0.
409 */
410int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
411{
412 if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
413 Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
414 file, line, arg);
415 return 1;
416 }
417 return 0;
418}
419
Willy Tarreau61d18892009-03-31 10:49:21 +0200420/* Report a warning if a rule is placed after a 'block' rule.
421 * Return 1 if the warning has been emitted, otherwise 0.
422 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100423int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200424{
Willy Tarreau353bc9f2014-04-28 22:05:31 +0200425 if (!LIST_ISEMPTY(&proxy->block_rules)) {
Willy Tarreau61d18892009-03-31 10:49:21 +0200426 Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n",
427 file, line, arg);
428 return 1;
429 }
430 return 0;
431}
432
Willy Tarreau5002f572014-04-23 01:32:02 +0200433/* Report a warning if a rule is placed after an 'http_request' rule.
434 * Return 1 if the warning has been emitted, otherwise 0.
435 */
436int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
437{
438 if (!LIST_ISEMPTY(&proxy->http_req_rules)) {
439 Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n",
440 file, line, arg);
441 return 1;
442 }
443 return 0;
444}
445
Willy Tarreau61d18892009-03-31 10:49:21 +0200446/* Report a warning if a rule is placed after a reqrewrite rule.
447 * Return 1 if the warning has been emitted, otherwise 0.
448 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100449int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200450{
451 if (proxy->req_exp) {
452 Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n",
453 file, line, arg);
454 return 1;
455 }
456 return 0;
457}
458
459/* Report a warning if a rule is placed after a reqadd rule.
460 * Return 1 if the warning has been emitted, otherwise 0.
461 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100462int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200463{
Willy Tarreaudeb9ed82010-01-03 21:03:22 +0100464 if (!LIST_ISEMPTY(&proxy->req_add)) {
Willy Tarreau61d18892009-03-31 10:49:21 +0200465 Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n",
466 file, line, arg);
467 return 1;
468 }
469 return 0;
470}
471
472/* Report a warning if a rule is placed after a redirect rule.
473 * Return 1 if the warning has been emitted, otherwise 0.
474 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100475int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200476{
477 if (!LIST_ISEMPTY(&proxy->redirect_rules)) {
478 Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n",
479 file, line, arg);
480 return 1;
481 }
482 return 0;
483}
484
485/* Report a warning if a rule is placed after a 'use_backend' rule.
486 * Return 1 if the warning has been emitted, otherwise 0.
487 */
Willy Tarreau3ec18a02010-01-28 19:01:34 +0100488int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200489{
490 if (!LIST_ISEMPTY(&proxy->switching_rules)) {
491 Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n",
492 file, line, arg);
493 return 1;
494 }
495 return 0;
496}
497
Willy Tarreauee445d92014-04-23 01:39:04 +0200498/* Report a warning if a rule is placed after a 'use-server' rule.
499 * Return 1 if the warning has been emitted, otherwise 0.
500 */
501int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg)
502{
503 if (!LIST_ISEMPTY(&proxy->server_rules)) {
504 Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n",
505 file, line, arg);
506 return 1;
507 }
508 return 0;
509}
510
Willy Tarreaud39ad442016-11-25 15:16:12 +0100511/* report a warning if a redirect rule is dangerously placed */
512int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau620408f2016-10-21 16:37:51 +0200513{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100514 return warnif_rule_after_use_backend(proxy, file, line, arg) ||
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200515 warnif_rule_after_use_server(proxy, file, line, arg);
516}
517
Willy Tarreaud39ad442016-11-25 15:16:12 +0100518/* report a warning if a reqadd rule is dangerously placed */
519int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200520{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100521 return warnif_rule_after_redirect(proxy, file, line, arg) ||
522 warnif_misplaced_redirect(proxy, file, line, arg);
Willy Tarreau3986b9c2014-09-16 15:39:51 +0200523}
524
Willy Tarreaud39ad442016-11-25 15:16:12 +0100525/* report a warning if a reqxxx rule is dangerously placed */
526int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200527{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100528 return warnif_rule_after_reqadd(proxy, file, line, arg) ||
529 warnif_misplaced_reqadd(proxy, file, line, arg);
Willy Tarreau5002f572014-04-23 01:32:02 +0200530}
531
532/* report a warning if an http-request rule is dangerously placed */
533int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg)
534{
Willy Tarreau61d18892009-03-31 10:49:21 +0200535 return warnif_rule_after_reqxxx(proxy, file, line, arg) ||
Willy Tarreaud39ad442016-11-25 15:16:12 +0100536 warnif_misplaced_reqxxx(proxy, file, line, arg);;
Willy Tarreau61d18892009-03-31 10:49:21 +0200537}
538
Willy Tarreaud39ad442016-11-25 15:16:12 +0100539/* report a warning if a block rule is dangerously placed */
540int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200541{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100542 return warnif_rule_after_http_req(proxy, file, line, arg) ||
543 warnif_misplaced_http_req(proxy, file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200544}
545
Willy Tarreaud39ad442016-11-25 15:16:12 +0100546/* report a warning if a "tcp request content" rule is dangerously placed */
547int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreau61d18892009-03-31 10:49:21 +0200548{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100549 return warnif_rule_after_block(proxy, file, line, arg) ||
550 warnif_misplaced_block(proxy, file, line, arg);
Willy Tarreauee445d92014-04-23 01:39:04 +0200551}
552
Willy Tarreaud39ad442016-11-25 15:16:12 +0100553/* report a warning if a "tcp request session" rule is dangerously placed */
554int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg)
Willy Tarreauee445d92014-04-23 01:39:04 +0200555{
Willy Tarreaud39ad442016-11-25 15:16:12 +0100556 return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
557 warnif_misplaced_tcp_cont(proxy, file, line, arg);
558}
559
560/* report a warning if a "tcp request connection" rule is dangerously placed */
561int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
562{
563 return warnif_rule_after_tcp_sess(proxy, file, line, arg) ||
564 warnif_misplaced_tcp_sess(proxy, file, line, arg);
Willy Tarreau61d18892009-03-31 10:49:21 +0200565}
566
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100567/* Report it if a request ACL condition uses some keywords that are incompatible
568 * with the place where the ACL is used. It returns either 0 or ERR_WARN so that
569 * its result can be or'ed with err_code. Note that <cond> may be NULL and then
570 * will be ignored.
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100571 */
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100572static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100573{
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100574 const struct acl *acl;
Willy Tarreau93fddf12013-03-31 22:59:32 +0200575 const char *kw;
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100576
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100577 if (!cond)
Willy Tarreauf1e98b82010-01-28 17:59:39 +0100578 return 0;
579
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100580 acl = acl_cond_conflicts(cond, where);
581 if (acl) {
582 if (acl->name && *acl->name)
583 Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n",
584 file, line, acl->name, sample_ckp_names(where));
585 else
586 Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
Willy Tarreau93fddf12013-03-31 22:59:32 +0200587 file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100588 return ERR_WARN;
589 }
590 if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100591 return 0;
592
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100593 if (acl->name && *acl->name)
594 Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
Willy Tarreau93fddf12013-03-31 22:59:32 +0200595 file, line, acl->name, kw, sample_ckp_names(where));
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100596 else
597 Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
Willy Tarreau93fddf12013-03-31 22:59:32 +0200598 file, line, kw, sample_ckp_names(where));
Willy Tarreaufdb563c2010-01-31 15:43:27 +0100599 return ERR_WARN;
600}
601
Willy Tarreaubaaee002006-06-26 02:48:02 +0200602/*
Willy Tarreau058e9072009-07-20 09:30:05 +0200603 * parse a line in a <global> section. Returns the error code, 0 if OK, or
604 * any combination of :
605 * - ERR_ABORT: must abort ASAP
606 * - ERR_FATAL: we can continue parsing but not start the service
607 * - ERR_WARN: a warning has been emitted
608 * - ERR_ALERT: an alert has been emitted
609 * Only the two first ones can stop processing, the two others are just
610 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200611 */
Willy Tarreau3842f002009-06-14 11:39:52 +0200612int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200613{
Willy Tarreau058e9072009-07-20 09:30:05 +0200614 int err_code = 0;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200615 char *errmsg = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200616
617 if (!strcmp(args[0], "global")) { /* new section */
618 /* no option, nothing special to do */
William Lallemand6e62fb62015-04-28 16:55:23 +0200619 alertif_too_many_args(0, file, linenum, args, &err_code);
Willy Tarreau058e9072009-07-20 09:30:05 +0200620 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200621 }
622 else if (!strcmp(args[0], "daemon")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200623 if (alertif_too_many_args(0, file, linenum, args, &err_code))
624 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200625 global.mode |= MODE_DAEMON;
626 }
627 else if (!strcmp(args[0], "debug")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200628 if (alertif_too_many_args(0, file, linenum, args, &err_code))
629 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200630 global.mode |= MODE_DEBUG;
631 }
632 else if (!strcmp(args[0], "noepoll")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200633 if (alertif_too_many_args(0, file, linenum, args, &err_code))
634 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100635 global.tune.options &= ~GTUNE_USE_EPOLL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200636 }
Willy Tarreaude99e992007-04-16 00:53:59 +0200637 else if (!strcmp(args[0], "nokqueue")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200638 if (alertif_too_many_args(0, file, linenum, args, &err_code))
639 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100640 global.tune.options &= ~GTUNE_USE_KQUEUE;
Willy Tarreaude99e992007-04-16 00:53:59 +0200641 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200642 else if (!strcmp(args[0], "nopoll")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200643 if (alertif_too_many_args(0, file, linenum, args, &err_code))
644 goto out;
Willy Tarreau43b78992009-01-25 15:42:27 +0100645 global.tune.options &= ~GTUNE_USE_POLL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200646 }
Willy Tarreau3ab68cf2009-01-25 16:03:28 +0100647 else if (!strcmp(args[0], "nosplice")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200648 if (alertif_too_many_args(0, file, linenum, args, &err_code))
649 goto out;
Willy Tarreau3ab68cf2009-01-25 16:03:28 +0100650 global.tune.options &= ~GTUNE_USE_SPLICE;
651 }
Nenad Merdanovic88afe032014-04-14 15:56:58 +0200652 else if (!strcmp(args[0], "nogetaddrinfo")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200653 if (alertif_too_many_args(0, file, linenum, args, &err_code))
654 goto out;
Nenad Merdanovic88afe032014-04-14 15:56:58 +0200655 global.tune.options &= ~GTUNE_USE_GAI;
656 }
Lukas Tribusa0bcbdc2016-09-12 21:42:20 +0000657 else if (!strcmp(args[0], "noreuseport")) {
658 if (alertif_too_many_args(0, file, linenum, args, &err_code))
659 goto out;
660 global.tune.options &= ~GTUNE_USE_REUSEPORT;
661 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200662 else if (!strcmp(args[0], "quiet")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200663 if (alertif_too_many_args(0, file, linenum, args, &err_code))
664 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200665 global.mode |= MODE_QUIET;
666 }
Willy Tarreau1db37712007-06-03 17:16:49 +0200667 else if (!strcmp(args[0], "tune.maxpollevents")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200668 if (alertif_too_many_args(1, file, linenum, args, &err_code))
669 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200670 if (global.tune.maxpollevents != 0) {
671 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200672 err_code |= ERR_ALERT;
673 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200674 }
675 if (*(args[1]) == 0) {
676 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200677 err_code |= ERR_ALERT | ERR_FATAL;
678 goto out;
Willy Tarreau1db37712007-06-03 17:16:49 +0200679 }
680 global.tune.maxpollevents = atol(args[1]);
681 }
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100682 else if (!strcmp(args[0], "tune.maxaccept")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200683 if (alertif_too_many_args(1, file, linenum, args, &err_code))
684 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100685 if (global.tune.maxaccept != 0) {
686 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200687 err_code |= ERR_ALERT;
688 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100689 }
690 if (*(args[1]) == 0) {
691 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200692 err_code |= ERR_ALERT | ERR_FATAL;
693 goto out;
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100694 }
695 global.tune.maxaccept = atol(args[1]);
696 }
Willy Tarreau43961d52010-10-04 20:39:20 +0200697 else if (!strcmp(args[0], "tune.chksize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200698 if (alertif_too_many_args(1, file, linenum, args, &err_code))
699 goto out;
Willy Tarreau43961d52010-10-04 20:39:20 +0200700 if (*(args[1]) == 0) {
701 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
702 err_code |= ERR_ALERT | ERR_FATAL;
703 goto out;
704 }
705 global.tune.chksize = atol(args[1]);
706 }
Willy Tarreaub22fc302015-12-14 12:04:35 +0100707 else if (!strcmp(args[0], "tune.recv_enough")) {
708 if (alertif_too_many_args(1, file, linenum, args, &err_code))
709 goto out;
710 if (*(args[1]) == 0) {
711 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
712 err_code |= ERR_ALERT | ERR_FATAL;
713 goto out;
714 }
715 global.tune.recv_enough = atol(args[1]);
716 }
Willy Tarreau33cb0652014-12-23 22:52:37 +0100717 else if (!strcmp(args[0], "tune.buffers.limit")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200718 if (alertif_too_many_args(1, file, linenum, args, &err_code))
719 goto out;
Willy Tarreau33cb0652014-12-23 22:52:37 +0100720 if (*(args[1]) == 0) {
721 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725 global.tune.buf_limit = atol(args[1]);
726 if (global.tune.buf_limit) {
727 if (global.tune.buf_limit < 3)
728 global.tune.buf_limit = 3;
729 if (global.tune.buf_limit <= global.tune.reserved_bufs)
730 global.tune.buf_limit = global.tune.reserved_bufs + 1;
731 }
732 }
Willy Tarreau1058ae72014-12-23 22:40:40 +0100733 else if (!strcmp(args[0], "tune.buffers.reserve")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200734 if (alertif_too_many_args(1, file, linenum, args, &err_code))
735 goto out;
Willy Tarreau1058ae72014-12-23 22:40:40 +0100736 if (*(args[1]) == 0) {
737 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
738 err_code |= ERR_ALERT | ERR_FATAL;
739 goto out;
740 }
741 global.tune.reserved_bufs = atol(args[1]);
742 if (global.tune.reserved_bufs < 2)
743 global.tune.reserved_bufs = 2;
Willy Tarreau33cb0652014-12-23 22:52:37 +0100744 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
745 global.tune.buf_limit = global.tune.reserved_bufs + 1;
Willy Tarreau1058ae72014-12-23 22:40:40 +0100746 }
Willy Tarreau27a674e2009-08-17 07:23:33 +0200747 else if (!strcmp(args[0], "tune.bufsize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200748 if (alertif_too_many_args(1, file, linenum, args, &err_code))
749 goto out;
Willy Tarreau27a674e2009-08-17 07:23:33 +0200750 if (*(args[1]) == 0) {
751 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
752 err_code |= ERR_ALERT | ERR_FATAL;
753 goto out;
754 }
755 global.tune.bufsize = atol(args[1]);
Willy Tarreau9b694542015-09-28 13:49:53 +0200756 if (global.tune.bufsize <= 0) {
757 Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
758 err_code |= ERR_ALERT | ERR_FATAL;
759 goto out;
760 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100761 chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize);
Willy Tarreau2819e992013-12-13 14:41:10 +0100762 alloc_trash_buffers(global.tune.bufsize);
Willy Tarreau27a674e2009-08-17 07:23:33 +0200763 }
764 else if (!strcmp(args[0], "tune.maxrewrite")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200765 if (alertif_too_many_args(1, file, linenum, args, &err_code))
766 goto out;
Willy Tarreau27a674e2009-08-17 07:23:33 +0200767 if (*(args[1]) == 0) {
768 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
769 err_code |= ERR_ALERT | ERR_FATAL;
770 goto out;
771 }
772 global.tune.maxrewrite = atol(args[1]);
Willy Tarreau27097842015-09-28 13:53:23 +0200773 if (global.tune.maxrewrite < 0) {
774 Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
775 err_code |= ERR_ALERT | ERR_FATAL;
776 goto out;
777 }
Willy Tarreau27a674e2009-08-17 07:23:33 +0200778 }
Willy Tarreau7e312732014-02-12 16:35:14 +0100779 else if (!strcmp(args[0], "tune.idletimer")) {
780 unsigned int idle;
781 const char *res;
782
William Lallemand1a748ae2015-05-19 16:37:23 +0200783 if (alertif_too_many_args(1, file, linenum, args, &err_code))
784 goto out;
Willy Tarreau7e312732014-02-12 16:35:14 +0100785 if (*(args[1]) == 0) {
786 Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
787 err_code |= ERR_ALERT | ERR_FATAL;
788 goto out;
789 }
790
791 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
792 if (res) {
793 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
794 file, linenum, *res, args[0]);
795 err_code |= ERR_ALERT | ERR_FATAL;
796 goto out;
797 }
798
799 if (idle > 65535) {
800 Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
801 err_code |= ERR_ALERT | ERR_FATAL;
802 goto out;
803 }
804 global.tune.idle_timer = idle;
805 }
Willy Tarreaue803de22010-01-21 17:43:04 +0100806 else if (!strcmp(args[0], "tune.rcvbuf.client")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200807 if (alertif_too_many_args(1, file, linenum, args, &err_code))
808 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100809 if (global.tune.client_rcvbuf != 0) {
810 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
811 err_code |= ERR_ALERT;
812 goto out;
813 }
814 if (*(args[1]) == 0) {
815 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
816 err_code |= ERR_ALERT | ERR_FATAL;
817 goto out;
818 }
819 global.tune.client_rcvbuf = atol(args[1]);
820 }
821 else if (!strcmp(args[0], "tune.rcvbuf.server")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200822 if (alertif_too_many_args(1, file, linenum, args, &err_code))
823 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100824 if (global.tune.server_rcvbuf != 0) {
825 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
826 err_code |= ERR_ALERT;
827 goto out;
828 }
829 if (*(args[1]) == 0) {
830 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
831 err_code |= ERR_ALERT | ERR_FATAL;
832 goto out;
833 }
834 global.tune.server_rcvbuf = atol(args[1]);
835 }
836 else if (!strcmp(args[0], "tune.sndbuf.client")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200837 if (alertif_too_many_args(1, file, linenum, args, &err_code))
838 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100839 if (global.tune.client_sndbuf != 0) {
840 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
841 err_code |= ERR_ALERT;
842 goto out;
843 }
844 if (*(args[1]) == 0) {
845 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
846 err_code |= ERR_ALERT | ERR_FATAL;
847 goto out;
848 }
849 global.tune.client_sndbuf = atol(args[1]);
850 }
851 else if (!strcmp(args[0], "tune.sndbuf.server")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200852 if (alertif_too_many_args(1, file, linenum, args, &err_code))
853 goto out;
Willy Tarreaue803de22010-01-21 17:43:04 +0100854 if (global.tune.server_sndbuf != 0) {
855 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
856 err_code |= ERR_ALERT;
857 goto out;
858 }
859 if (*(args[1]) == 0) {
860 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
861 err_code |= ERR_ALERT | ERR_FATAL;
862 goto out;
863 }
864 global.tune.server_sndbuf = atol(args[1]);
865 }
Willy Tarreaubd9a0a72011-10-23 21:14:29 +0200866 else if (!strcmp(args[0], "tune.pipesize")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200867 if (alertif_too_many_args(1, file, linenum, args, &err_code))
868 goto out;
Willy Tarreaubd9a0a72011-10-23 21:14:29 +0200869 if (*(args[1]) == 0) {
870 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
871 err_code |= ERR_ALERT | ERR_FATAL;
872 goto out;
873 }
874 global.tune.pipesize = atol(args[1]);
875 }
Willy Tarreau193b8c62012-11-22 00:17:38 +0100876 else if (!strcmp(args[0], "tune.http.cookielen")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200877 if (alertif_too_many_args(1, file, linenum, args, &err_code))
878 goto out;
Willy Tarreau193b8c62012-11-22 00:17:38 +0100879 if (*(args[1]) == 0) {
880 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
881 err_code |= ERR_ALERT | ERR_FATAL;
882 goto out;
883 }
884 global.tune.cookie_len = atol(args[1]) + 1;
885 }
Willy Tarreauac1932d2011-10-24 19:14:41 +0200886 else if (!strcmp(args[0], "tune.http.maxhdr")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200887 if (alertif_too_many_args(1, file, linenum, args, &err_code))
888 goto out;
Willy Tarreauac1932d2011-10-24 19:14:41 +0200889 if (*(args[1]) == 0) {
890 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
891 err_code |= ERR_ALERT | ERR_FATAL;
892 goto out;
893 }
894 global.tune.max_http_hdr = atol(args[1]);
895 }
William Lallemandf3747832012-11-09 12:33:10 +0100896 else if (!strcmp(args[0], "tune.comp.maxlevel")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200897 if (alertif_too_many_args(1, file, linenum, args, &err_code))
898 goto out;
William Lallemandf3747832012-11-09 12:33:10 +0100899 if (*args[1]) {
900 global.tune.comp_maxlevel = atoi(args[1]);
901 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
902 Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
903 file, linenum, args[0]);
904 err_code |= ERR_ALERT | ERR_FATAL;
905 goto out;
906 }
907 } else {
908 Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
909 file, linenum, args[0]);
910 err_code |= ERR_ALERT | ERR_FATAL;
911 goto out;
912 }
913 }
Willy Tarreauf3045d22015-04-29 16:24:50 +0200914 else if (!strcmp(args[0], "tune.pattern.cache-size")) {
915 if (*args[1]) {
916 global.tune.pattern_cache = atoi(args[1]);
917 if (global.tune.pattern_cache < 0) {
918 Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
919 file, linenum, args[0]);
920 err_code |= ERR_ALERT | ERR_FATAL;
921 goto out;
922 }
923 } else {
924 Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
925 file, linenum, args[0]);
926 err_code |= ERR_ALERT | ERR_FATAL;
927 goto out;
928 }
929 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200930 else if (!strcmp(args[0], "uid")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200931 if (alertif_too_many_args(1, file, linenum, args, &err_code))
932 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200933 if (global.uid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200934 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +0200935 err_code |= ERR_ALERT;
936 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200937 }
938 if (*(args[1]) == 0) {
939 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200940 err_code |= ERR_ALERT | ERR_FATAL;
941 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200942 }
Baptiste Assmann79fee6a2016-03-11 17:10:04 +0100943 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
944 Warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]);
945 err_code |= ERR_WARN;
946 goto out;
947 }
948
Willy Tarreaubaaee002006-06-26 02:48:02 +0200949 }
950 else if (!strcmp(args[0], "gid")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200951 if (alertif_too_many_args(1, file, linenum, args, &err_code))
952 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200953 if (global.gid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200954 Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +0200955 err_code |= ERR_ALERT;
956 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200957 }
958 if (*(args[1]) == 0) {
959 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +0200960 err_code |= ERR_ALERT | ERR_FATAL;
961 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200962 }
Baptiste Assmann776e5182016-03-11 17:21:15 +0100963 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
964 Warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]);
965 err_code |= ERR_WARN;
966 goto out;
967 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200968 }
Simon Horman98637e52014-06-20 12:30:16 +0900969 else if (!strcmp(args[0], "external-check")) {
William Lallemand1a748ae2015-05-19 16:37:23 +0200970 if (alertif_too_many_args(0, file, linenum, args, &err_code))
971 goto out;
Simon Horman98637e52014-06-20 12:30:16 +0900972 global.external_check = 1;
973 }
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200974 /* user/group name handling */
975 else if (!strcmp(args[0], "user")) {
976 struct passwd *ha_user;
William Lallemand1a748ae2015-05-19 16:37:23 +0200977 if (alertif_too_many_args(1, file, linenum, args, &err_code))
978 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200979 if (global.uid != 0) {
980 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +0200981 err_code |= ERR_ALERT;
982 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200983 }
984 errno = 0;
985 ha_user = getpwnam(args[1]);
986 if (ha_user != NULL) {
987 global.uid = (int)ha_user->pw_uid;
988 }
989 else {
990 Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
Willy Tarreau058e9072009-07-20 09:30:05 +0200991 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200992 }
993 }
994 else if (!strcmp(args[0], "group")) {
995 struct group *ha_group;
William Lallemand1a748ae2015-05-19 16:37:23 +0200996 if (alertif_too_many_args(1, file, linenum, args, &err_code))
997 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200998 if (global.gid != 0) {
Willy Tarreau1772ece2009-04-03 14:49:12 +0200999 Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001000 err_code |= ERR_ALERT;
1001 goto out;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001002 }
1003 errno = 0;
1004 ha_group = getgrnam(args[1]);
1005 if (ha_group != NULL) {
1006 global.gid = (int)ha_group->gr_gid;
1007 }
1008 else {
1009 Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
Willy Tarreau058e9072009-07-20 09:30:05 +02001010 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau95c20ac2007-03-25 15:39:23 +02001011 }
1012 }
1013 /* end of user/group name handling*/
Willy Tarreaubaaee002006-06-26 02:48:02 +02001014 else if (!strcmp(args[0], "nbproc")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001015 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1016 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001017 if (*(args[1]) == 0) {
1018 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001019 err_code |= ERR_ALERT | ERR_FATAL;
1020 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001021 }
1022 global.nbproc = atol(args[1]);
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001023 if (global.nbproc < 1 || global.nbproc > LONGBITS) {
1024 Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
1025 file, linenum, args[0], LONGBITS, global.nbproc);
1026 err_code |= ERR_ALERT | ERR_FATAL;
1027 goto out;
1028 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001029 }
1030 else if (!strcmp(args[0], "maxconn")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001031 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1032 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001033 if (global.maxconn != 0) {
1034 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001035 err_code |= ERR_ALERT;
1036 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001037 }
1038 if (*(args[1]) == 0) {
1039 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001040 err_code |= ERR_ALERT | ERR_FATAL;
1041 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001042 }
1043 global.maxconn = atol(args[1]);
1044#ifdef SYSTEM_MAXCONN
1045 if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) {
1046 Alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, DEFAULT_MAXCONN);
1047 global.maxconn = DEFAULT_MAXCONN;
Willy Tarreau058e9072009-07-20 09:30:05 +02001048 err_code |= ERR_ALERT;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001049 }
1050#endif /* SYSTEM_MAXCONN */
1051 }
Emeric Brun850efd52014-01-29 12:24:34 +01001052 else if (!strcmp(args[0], "ssl-server-verify")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001053 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1054 goto out;
Emeric Brun850efd52014-01-29 12:24:34 +01001055 if (*(args[1]) == 0) {
1056 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1057 err_code |= ERR_ALERT | ERR_FATAL;
1058 goto out;
1059 }
1060 if (strcmp(args[1],"none") == 0)
1061 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
1062 else if (strcmp(args[1],"required") == 0)
1063 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
1064 else {
1065 Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
1066 err_code |= ERR_ALERT | ERR_FATAL;
1067 goto out;
1068 }
1069 }
Willy Tarreau81c25d02011-09-07 15:17:21 +02001070 else if (!strcmp(args[0], "maxconnrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001071 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1072 goto out;
Willy Tarreau81c25d02011-09-07 15:17:21 +02001073 if (global.cps_lim != 0) {
1074 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1075 err_code |= ERR_ALERT;
1076 goto out;
1077 }
1078 if (*(args[1]) == 0) {
1079 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1080 err_code |= ERR_ALERT | ERR_FATAL;
1081 goto out;
1082 }
1083 global.cps_lim = atol(args[1]);
1084 }
Willy Tarreau93e7c002013-10-07 18:51:07 +02001085 else if (!strcmp(args[0], "maxsessrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001086 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1087 goto out;
Willy Tarreau93e7c002013-10-07 18:51:07 +02001088 if (global.sps_lim != 0) {
1089 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1090 err_code |= ERR_ALERT;
1091 goto out;
1092 }
1093 if (*(args[1]) == 0) {
1094 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1095 err_code |= ERR_ALERT | ERR_FATAL;
1096 goto out;
1097 }
1098 global.sps_lim = atol(args[1]);
1099 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001100 else if (!strcmp(args[0], "maxsslrate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001101 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1102 goto out;
Willy Tarreaue43d5322013-10-07 20:01:52 +02001103 if (global.ssl_lim != 0) {
1104 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1105 err_code |= ERR_ALERT;
1106 goto out;
1107 }
1108 if (*(args[1]) == 0) {
1109 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1110 err_code |= ERR_ALERT | ERR_FATAL;
1111 goto out;
1112 }
1113 global.ssl_lim = atol(args[1]);
1114 }
William Lallemandd85f9172012-11-09 17:05:39 +01001115 else if (!strcmp(args[0], "maxcomprate")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001116 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1117 goto out;
William Lallemandd85f9172012-11-09 17:05:39 +01001118 if (*(args[1]) == 0) {
1119 Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
1120 err_code |= ERR_ALERT | ERR_FATAL;
1121 goto out;
1122 }
1123 global.comp_rate_lim = atoi(args[1]) * 1024;
1124 }
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001125 else if (!strcmp(args[0], "maxpipes")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001126 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1127 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001128 if (global.maxpipes != 0) {
1129 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001130 err_code |= ERR_ALERT;
1131 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001132 }
1133 if (*(args[1]) == 0) {
1134 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001135 err_code |= ERR_ALERT | ERR_FATAL;
1136 goto out;
Willy Tarreau3ec79b92009-01-18 20:39:42 +01001137 }
1138 global.maxpipes = atol(args[1]);
1139 }
William Lallemand9d5f5482012-11-07 16:12:57 +01001140 else if (!strcmp(args[0], "maxzlibmem")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001141 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1142 goto out;
William Lallemand9d5f5482012-11-07 16:12:57 +01001143 if (*(args[1]) == 0) {
1144 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1145 err_code |= ERR_ALERT | ERR_FATAL;
1146 goto out;
1147 }
William Lallemande3a7d992012-11-20 11:25:20 +01001148 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
William Lallemand9d5f5482012-11-07 16:12:57 +01001149 }
William Lallemand072a2bf2012-11-20 17:01:01 +01001150 else if (!strcmp(args[0], "maxcompcpuusage")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001151 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1152 goto out;
William Lallemand072a2bf2012-11-20 17:01:01 +01001153 if (*(args[1]) == 0) {
1154 Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
1155 err_code |= ERR_ALERT | ERR_FATAL;
1156 goto out;
1157 }
1158 compress_min_idle = 100 - atoi(args[1]);
Willy Tarreaucb2699a2013-01-24 16:25:38 +01001159 if (compress_min_idle > 100) {
William Lallemand072a2bf2012-11-20 17:01:01 +01001160 Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
1161 err_code |= ERR_ALERT | ERR_FATAL;
1162 goto out;
1163 }
William Lallemand1a748ae2015-05-19 16:37:23 +02001164 }
William Lallemand072a2bf2012-11-20 17:01:01 +01001165
Willy Tarreaubaaee002006-06-26 02:48:02 +02001166 else if (!strcmp(args[0], "ulimit-n")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001167 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1168 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001169 if (global.rlimit_nofile != 0) {
1170 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001171 err_code |= ERR_ALERT;
1172 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001173 }
1174 if (*(args[1]) == 0) {
1175 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001176 err_code |= ERR_ALERT | ERR_FATAL;
1177 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001178 }
1179 global.rlimit_nofile = atol(args[1]);
1180 }
1181 else if (!strcmp(args[0], "chroot")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001182 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1183 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001184 if (global.chroot != NULL) {
1185 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001186 err_code |= ERR_ALERT;
1187 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001188 }
1189 if (*(args[1]) == 0) {
1190 Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001191 err_code |= ERR_ALERT | ERR_FATAL;
1192 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001193 }
1194 global.chroot = strdup(args[1]);
1195 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001196 else if (!strcmp(args[0], "description")) {
1197 int i, len=0;
1198 char *d;
1199
1200 if (!*args[1]) {
1201 Alert("parsing [%s:%d]: '%s' expects a string argument.\n",
1202 file, linenum, args[0]);
1203 err_code |= ERR_ALERT | ERR_FATAL;
1204 goto out;
1205 }
1206
Willy Tarreau348acfe2014-04-14 15:00:39 +02001207 for (i = 1; *args[i]; i++)
1208 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001209
1210 if (global.desc)
1211 free(global.desc);
1212
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02001213 global.desc = d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001214
Willy Tarreau348acfe2014-04-14 15:00:39 +02001215 d += snprintf(d, global.desc + len - d, "%s", args[1]);
1216 for (i = 2; *args[i]; i++)
1217 d += snprintf(d, global.desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001218 }
1219 else if (!strcmp(args[0], "node")) {
1220 int i;
1221 char c;
1222
William Lallemand1a748ae2015-05-19 16:37:23 +02001223 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1224 goto out;
1225
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001226 for (i=0; args[1][i]; i++) {
1227 c = args[1][i];
Willy Tarreau88e05812010-03-03 00:16:00 +01001228 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
1229 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001230 break;
1231 }
1232
1233 if (!i || args[1][i]) {
1234 Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
1235 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
1236 file, linenum, args[0]);
1237 err_code |= ERR_ALERT | ERR_FATAL;
1238 goto out;
1239 }
1240
1241 if (global.node)
1242 free(global.node);
1243
1244 global.node = strdup(args[1]);
1245 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001246 else if (!strcmp(args[0], "pidfile")) {
William Lallemand1a748ae2015-05-19 16:37:23 +02001247 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1248 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001249 if (global.pidfile != NULL) {
1250 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001251 err_code |= ERR_ALERT;
1252 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001253 }
1254 if (*(args[1]) == 0) {
1255 Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001256 err_code |= ERR_ALERT | ERR_FATAL;
1257 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001258 }
1259 global.pidfile = strdup(args[1]);
1260 }
Emeric Bruned760922010-10-22 17:59:25 +02001261 else if (!strcmp(args[0], "unix-bind")) {
1262 int cur_arg = 1;
1263 while (*(args[cur_arg])) {
1264 if (!strcmp(args[cur_arg], "prefix")) {
1265 if (global.unix_bind.prefix != NULL) {
1266 Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
1267 err_code |= ERR_ALERT;
1268 cur_arg += 2;
1269 continue;
1270 }
1271
1272 if (*(args[cur_arg+1]) == 0) {
1273 Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
1274 err_code |= ERR_ALERT | ERR_FATAL;
1275 goto out;
1276 }
1277 global.unix_bind.prefix = strdup(args[cur_arg+1]);
1278 cur_arg += 2;
1279 continue;
1280 }
1281
1282 if (!strcmp(args[cur_arg], "mode")) {
1283
1284 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
1285 cur_arg += 2;
1286 continue;
1287 }
1288
1289 if (!strcmp(args[cur_arg], "uid")) {
1290
1291 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
1292 cur_arg += 2;
1293 continue;
1294 }
1295
1296 if (!strcmp(args[cur_arg], "gid")) {
1297
1298 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
1299 cur_arg += 2;
1300 continue;
1301 }
1302
1303 if (!strcmp(args[cur_arg], "user")) {
1304 struct passwd *user;
1305
1306 user = getpwnam(args[cur_arg + 1]);
1307 if (!user) {
1308 Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
1309 file, linenum, args[0], args[cur_arg + 1 ]);
1310 err_code |= ERR_ALERT | ERR_FATAL;
1311 goto out;
1312 }
1313
1314 global.unix_bind.ux.uid = user->pw_uid;
1315 cur_arg += 2;
1316 continue;
1317 }
1318
1319 if (!strcmp(args[cur_arg], "group")) {
1320 struct group *group;
1321
1322 group = getgrnam(args[cur_arg + 1]);
1323 if (!group) {
1324 Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
1325 file, linenum, args[0], args[cur_arg + 1 ]);
1326 err_code |= ERR_ALERT | ERR_FATAL;
1327 goto out;
1328 }
1329
1330 global.unix_bind.ux.gid = group->gr_gid;
1331 cur_arg += 2;
1332 continue;
1333 }
1334
Willy Tarreaub48f9582011-09-05 01:17:06 +02001335 Alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
Emeric Bruned760922010-10-22 17:59:25 +02001336 file, linenum, args[0]);
1337 err_code |= ERR_ALERT | ERR_FATAL;
1338 goto out;
1339 }
1340 }
William Lallemand0f99e342011-10-12 17:50:54 +02001341 else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */
1342 /* delete previous herited or defined syslog servers */
1343 struct logsrv *back;
1344 struct logsrv *tmp;
1345
1346 if (*(args[1]) != 0) {
1347 Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]);
1348 err_code |= ERR_ALERT | ERR_FATAL;
1349 goto out;
1350 }
1351
1352 list_for_each_entry_safe(tmp, back, &global.logsrvs, list) {
1353 LIST_DEL(&tmp->list);
1354 free(tmp);
1355 }
1356 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001357 else if (!strcmp(args[0], "log")) { /* syslog server address */
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001358 struct sockaddr_storage *sk;
1359 int port1, port2;
William Lallemand0f99e342011-10-12 17:50:54 +02001360 struct logsrv *logsrv;
Willy Tarreau18324f52014-06-27 18:10:07 +02001361 int arg = 0;
1362 int len = 0;
William Lallemand0f99e342011-10-12 17:50:54 +02001363
William Lallemand1a748ae2015-05-19 16:37:23 +02001364 if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */
1365 goto out;
1366
Willy Tarreaubaaee002006-06-26 02:48:02 +02001367 if (*(args[1]) == 0 || *(args[2]) == 0) {
1368 Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001369 err_code |= ERR_ALERT | ERR_FATAL;
1370 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001371 }
William Lallemand0f99e342011-10-12 17:50:54 +02001372
Vincent Bernat02779b62016-04-03 13:48:43 +02001373 logsrv = calloc(1, sizeof(*logsrv));
William Lallemand0f99e342011-10-12 17:50:54 +02001374
Willy Tarreau18324f52014-06-27 18:10:07 +02001375 /* just after the address, a length may be specified */
1376 if (strcmp(args[arg+2], "len") == 0) {
1377 len = atoi(args[arg+3]);
1378 if (len < 80 || len > 65535) {
1379 Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n",
1380 file, linenum, args[arg+3]);
1381 err_code |= ERR_ALERT | ERR_FATAL;
1382 goto out;
1383 }
1384 logsrv->maxlen = len;
1385
1386 /* skip these two args */
1387 arg += 2;
1388 }
1389 else
1390 logsrv->maxlen = MAX_SYSLOG_LEN;
1391
1392 if (logsrv->maxlen > global.max_syslog_len) {
1393 global.max_syslog_len = logsrv->maxlen;
Hubert Verstraete831962e2016-06-28 22:44:26 +02001394 logheader = my_realloc2(logheader, global.max_syslog_len + 1);
1395 logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
1396 logline = my_realloc2(logline, global.max_syslog_len + 1);
1397 logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
Willy Tarreau18324f52014-06-27 18:10:07 +02001398 }
1399
Dragan Dosen1322d092015-09-22 16:05:32 +02001400 /* after the length, a format may be specified */
1401 if (strcmp(args[arg+2], "format") == 0) {
1402 logsrv->format = get_log_format(args[arg+3]);
1403 if (logsrv->format < 0) {
1404 Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]);
1405 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01001406 free(logsrv);
Dragan Dosen1322d092015-09-22 16:05:32 +02001407 goto out;
1408 }
1409
1410 /* skip these two args */
1411 arg += 2;
1412 }
1413
David Carlier97880bb2016-04-08 10:35:26 +01001414 if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) {
1415 free(logsrv);
William Lallemand1a748ae2015-05-19 16:37:23 +02001416 goto out;
David Carlier97880bb2016-04-08 10:35:26 +01001417 }
William Lallemand1a748ae2015-05-19 16:37:23 +02001418
Willy Tarreau18324f52014-06-27 18:10:07 +02001419 logsrv->facility = get_log_facility(args[arg+2]);
William Lallemand0f99e342011-10-12 17:50:54 +02001420 if (logsrv->facility < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02001421 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001422 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemand0f99e342011-10-12 17:50:54 +02001423 logsrv->facility = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001424 }
1425
William Lallemand0f99e342011-10-12 17:50:54 +02001426 logsrv->level = 7; /* max syslog level = debug */
Willy Tarreau18324f52014-06-27 18:10:07 +02001427 if (*(args[arg+3])) {
1428 logsrv->level = get_log_level(args[arg+3]);
William Lallemand0f99e342011-10-12 17:50:54 +02001429 if (logsrv->level < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02001430 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001431 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemand0f99e342011-10-12 17:50:54 +02001432 logsrv->level = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001433 }
1434 }
1435
William Lallemand0f99e342011-10-12 17:50:54 +02001436 logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */
Willy Tarreau18324f52014-06-27 18:10:07 +02001437 if (*(args[arg+4])) {
1438 logsrv->minlvl = get_log_level(args[arg+4]);
William Lallemand0f99e342011-10-12 17:50:54 +02001439 if (logsrv->minlvl < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02001440 Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001441 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemand0f99e342011-10-12 17:50:54 +02001442 logsrv->minlvl = 0;
Willy Tarreauf7edefa2009-05-10 17:20:05 +02001443 }
1444 }
1445
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001446 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001447 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01001448 Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001449 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001450 free(logsrv);
1451 goto out;
1452 }
1453 logsrv->addr = *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01001454
Willy Tarreau9b435bc2013-03-06 15:02:49 +01001455 if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +01001456 if (port1 != port2) {
1457 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
1458 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01001459 err_code |= ERR_ALERT | ERR_FATAL;
William Lallemand0f99e342011-10-12 17:50:54 +02001460 free(logsrv);
Willy Tarreaud5191e72010-02-09 20:50:45 +01001461 goto out;
1462 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01001463
William Lallemand0f99e342011-10-12 17:50:54 +02001464 logsrv->addr = *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01001465 if (!port1)
William Lallemand0f99e342011-10-12 17:50:54 +02001466 set_host_port(&logsrv->addr, SYSLOG_PORT);
Robert Tsai81ae1952007-12-05 10:47:29 +01001467 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001468
William Lallemand0f99e342011-10-12 17:50:54 +02001469 LIST_ADDQ(&global.logsrvs, &logsrv->list);
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001470 }
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001471 else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
1472 char *name;
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001473
1474 if (global.log_send_hostname != NULL) {
1475 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1476 err_code |= ERR_ALERT;
1477 goto out;
1478 }
1479
1480 if (*(args[1]))
1481 name = args[1];
1482 else
1483 name = hostname;
1484
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001485 free(global.log_send_hostname);
Dragan Dosenc8cfa7b2015-09-28 13:28:21 +02001486 global.log_send_hostname = strdup(name);
Joe Williamsdf5b38f2010-12-29 17:05:48 +01001487 }
Baptiste Assmann6bc89362015-08-23 09:22:25 +02001488 else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */
1489 if (global.server_state_base != NULL) {
1490 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1491 err_code |= ERR_ALERT;
1492 goto out;
1493 }
1494
1495 if (!*(args[1])) {
1496 Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
1497 err_code |= ERR_FATAL;
1498 goto out;
1499 }
1500
1501 global.server_state_base = strdup(args[1]);
1502 }
Baptiste Assmanne0882262015-08-23 09:54:31 +02001503 else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */
1504 if (global.server_state_file != NULL) {
1505 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
1506 err_code |= ERR_ALERT;
1507 goto out;
1508 }
1509
1510 if (!*(args[1])) {
1511 Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
1512 err_code |= ERR_FATAL;
1513 goto out;
1514 }
1515
1516 global.server_state_file = strdup(args[1]);
1517 }
Kevinm48936af2010-12-22 16:08:21 +00001518 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
William Lallemand1a748ae2015-05-19 16:37:23 +02001519 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1520 goto out;
Kevinm48936af2010-12-22 16:08:21 +00001521 if (*(args[1]) == 0) {
1522 Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
1523 err_code |= ERR_ALERT | ERR_FATAL;
1524 goto out;
1525 }
Dragan Dosen43885c72015-10-01 13:18:13 +02001526 chunk_destroy(&global.log_tag);
1527 chunk_initstr(&global.log_tag, strdup(args[1]));
Kevinm48936af2010-12-22 16:08:21 +00001528 }
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001529 else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */
William Lallemand1a748ae2015-05-19 16:37:23 +02001530 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1531 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001532 if (global.spread_checks != 0) {
1533 Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001534 err_code |= ERR_ALERT;
1535 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001536 }
1537 if (*(args[1]) == 0) {
1538 Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02001539 err_code |= ERR_ALERT | ERR_FATAL;
1540 goto out;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001541 }
1542 global.spread_checks = atol(args[1]);
1543 if (global.spread_checks < 0 || global.spread_checks > 50) {
1544 Alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02001545 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +02001546 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001547 }
Willy Tarreau1746eec2014-04-25 10:46:47 +02001548 else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */
1549 const char *err;
1550 unsigned int val;
1551
William Lallemand1a748ae2015-05-19 16:37:23 +02001552 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1553 goto out;
Willy Tarreau1746eec2014-04-25 10:46:47 +02001554 if (*(args[1]) == 0) {
1555 Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1556 err_code |= ERR_ALERT | ERR_FATAL;
1557 goto out;
1558 }
1559
1560 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
1561 if (err) {
1562 Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]);
1563 err_code |= ERR_ALERT | ERR_FATAL;
1564 }
1565 global.max_spread_checks = val;
1566 if (global.max_spread_checks < 0) {
1567 Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]);
1568 err_code |= ERR_ALERT | ERR_FATAL;
1569 }
1570 }
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001571 else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */
1572#ifdef USE_CPU_AFFINITY
1573 int cur_arg, i;
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001574 unsigned long proc = 0;
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001575 unsigned long cpus = 0;
1576
1577 if (strcmp(args[1], "all") == 0)
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001578 proc = ~0UL;
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001579 else if (strcmp(args[1], "odd") == 0)
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001580 proc = ~0UL/3UL; /* 0x555....555 */
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001581 else if (strcmp(args[1], "even") == 0)
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001582 proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001583 else {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001584 proc = atol(args[1]);
1585 if (proc >= 1 && proc <= LONGBITS)
1586 proc = 1UL << (proc - 1);
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001587 }
1588
1589 if (!proc || !*args[2]) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001590 Alert("parsing [%s:%d]: %s expects a process number including 'all', 'odd', 'even', or a number from 1 to %d, followed by a list of CPU ranges with numbers from 0 to %d.\n",
1591 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001592 err_code |= ERR_ALERT | ERR_FATAL;
1593 goto out;
1594 }
1595
1596 cur_arg = 2;
1597 while (*args[cur_arg]) {
1598 unsigned int low, high;
1599
Willy Tarreau83d84cf2012-11-22 01:04:31 +01001600 if (isdigit((int)*args[cur_arg])) {
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001601 char *dash = strchr(args[cur_arg], '-');
1602
1603 low = high = str2uic(args[cur_arg]);
1604 if (dash)
1605 high = str2uic(dash + 1);
1606
1607 if (high < low) {
1608 unsigned int swap = low;
1609 low = high;
1610 high = swap;
1611 }
1612
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001613 if (high >= LONGBITS) {
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001614 Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n",
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001615 file, linenum, args[0], LONGBITS - 1);
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001616 err_code |= ERR_ALERT | ERR_FATAL;
1617 goto out;
1618 }
1619
1620 while (low <= high)
1621 cpus |= 1UL << low++;
1622 }
1623 else {
1624 Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n",
1625 file, linenum, args[0], args[cur_arg]);
1626 err_code |= ERR_ALERT | ERR_FATAL;
1627 goto out;
1628 }
1629 cur_arg++;
1630 }
Willy Tarreaua9db57e2013-01-18 11:29:29 +01001631 for (i = 0; i < LONGBITS; i++)
1632 if (proc & (1UL << i))
Willy Tarreaufc6c0322012-11-16 16:12:27 +01001633 global.cpu_map[i] = cpus;
1634#else
1635 Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]);
1636 err_code |= ERR_ALERT | ERR_FATAL;
1637 goto out;
1638#endif
1639 }
Willy Tarreau1d549722016-02-16 12:41:57 +01001640 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1641 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1642 goto out;
1643
1644 if (*(args[2]) == 0) {
1645 Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1646 err_code |= ERR_ALERT | ERR_FATAL;
1647 goto out;
1648 }
1649
1650 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1651 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1652 Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1653 err_code |= ERR_ALERT | ERR_FATAL;
1654 goto out;
1655 }
1656 }
1657 else if (!strcmp(args[0], "unsetenv")) {
1658 int arg;
1659
1660 if (*(args[1]) == 0) {
1661 Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1662 err_code |= ERR_ALERT | ERR_FATAL;
1663 goto out;
1664 }
1665
1666 for (arg = 1; *args[arg]; arg++) {
1667 if (unsetenv(args[arg]) != 0) {
1668 Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1669 err_code |= ERR_ALERT | ERR_FATAL;
1670 goto out;
1671 }
1672 }
1673 }
1674 else if (!strcmp(args[0], "resetenv")) {
1675 extern char **environ;
1676 char **env = environ;
1677
1678 /* args contain variable names to keep, one per argument */
1679 while (*env) {
1680 int arg;
1681
1682 /* look for current variable in among all those we want to keep */
1683 for (arg = 1; *args[arg]; arg++) {
1684 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1685 (*env)[strlen(args[arg])] == '=')
1686 break;
1687 }
1688
1689 /* delete this variable */
1690 if (!*args[arg]) {
1691 char *delim = strchr(*env, '=');
1692
1693 if (!delim || delim - *env >= trash.size) {
1694 Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1695 err_code |= ERR_ALERT | ERR_FATAL;
1696 goto out;
1697 }
1698
1699 memcpy(trash.str, *env, delim - *env);
1700 trash.str[delim - *env] = 0;
1701
1702 if (unsetenv(trash.str) != 0) {
1703 Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1704 err_code |= ERR_ALERT | ERR_FATAL;
1705 goto out;
1706 }
1707 }
1708 else
1709 env++;
1710 }
1711 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001712 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001713 struct cfg_kw_list *kwl;
1714 int index;
Willy Tarreau39f23b62008-07-09 20:22:56 +02001715 int rc;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001716
1717 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1718 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1719 if (kwl->kw[index].section != CFG_GLOBAL)
1720 continue;
1721 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Willy Tarreau28a47d62012-09-18 20:02:48 +02001722 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02001723 if (rc < 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02001724 Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001725 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001726 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02001727 else if (rc > 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02001728 Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001729 err_code |= ERR_WARN;
1730 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02001731 }
Willy Tarreau058e9072009-07-20 09:30:05 +02001732 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02001733 }
1734 }
1735 }
1736
Willy Tarreaubaaee002006-06-26 02:48:02 +02001737 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau058e9072009-07-20 09:30:05 +02001738 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001739 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001740
Willy Tarreau058e9072009-07-20 09:30:05 +02001741 out:
Willy Tarreau0a3dd742012-05-08 19:47:01 +02001742 free(errmsg);
Willy Tarreau058e9072009-07-20 09:30:05 +02001743 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001744}
1745
Willy Tarreau915e1eb2009-06-22 15:48:36 +02001746void init_default_instance()
Willy Tarreaubaaee002006-06-26 02:48:02 +02001747{
Willy Tarreau97cb7802010-01-03 20:23:58 +01001748 init_new_proxy(&defproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001749 defproxy.mode = PR_MODE_TCP;
1750 defproxy.state = PR_STNEW;
1751 defproxy.maxconn = cfg_maxpconn;
1752 defproxy.conn_retries = CONN_RETRIES;
Joseph Lynch726ab712015-05-11 23:25:34 -07001753 defproxy.redispatch_after = 0;
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04001754 defproxy.lbprm.chash.balance_factor = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001755
Simon Horman66183002013-02-23 10:16:43 +09001756 defproxy.defsrv.check.inter = DEF_CHKINTR;
1757 defproxy.defsrv.check.fastinter = 0;
1758 defproxy.defsrv.check.downinter = 0;
Simon Hormand60d6912013-11-25 10:46:36 +09001759 defproxy.defsrv.agent.inter = DEF_CHKINTR;
1760 defproxy.defsrv.agent.fastinter = 0;
1761 defproxy.defsrv.agent.downinter = 0;
Simon Horman58c32972013-11-25 10:46:38 +09001762 defproxy.defsrv.check.rise = DEF_RISETIME;
1763 defproxy.defsrv.check.fall = DEF_FALLTIME;
1764 defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME;
1765 defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME;
Willy Tarreau5b3a2022012-09-28 15:01:02 +02001766 defproxy.defsrv.check.port = 0;
Simon Hormand60d6912013-11-25 10:46:36 +09001767 defproxy.defsrv.agent.port = 0;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001768 defproxy.defsrv.maxqueue = 0;
1769 defproxy.defsrv.minconn = 0;
1770 defproxy.defsrv.maxconn = 0;
1771 defproxy.defsrv.slowstart = 0;
1772 defproxy.defsrv.onerror = DEF_HANA_ONERR;
1773 defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT;
1774 defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1;
Simon Horman64e34162015-02-06 11:11:57 +09001775
1776 defproxy.email_alert.level = LOG_ALERT;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02001777 defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001778}
1779
Willy Tarreauade5ec42010-01-28 19:33:49 +01001780
Willy Tarreau63af98d2014-05-18 08:11:41 +02001781/* This function createss a new req* or rsp* rule to the proxy. It compiles the
1782 * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and
1783 * ERR_FATAL in case of error.
1784 */
Willy Tarreauade5ec42010-01-28 19:33:49 +01001785static int create_cond_regex_rule(const char *file, int line,
1786 struct proxy *px, int dir, int action, int flags,
1787 const char *cmd, const char *reg, const char *repl,
1788 const char **cond_start)
1789{
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001790 struct my_regex *preg = NULL;
Willy Tarreaub7451bb2012-04-27 12:38:15 +02001791 char *errmsg = NULL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001792 const char *err;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001793 char *error;
Willy Tarreau63af98d2014-05-18 08:11:41 +02001794 int ret_code = 0;
Willy Tarreau5321c422010-01-28 20:35:13 +01001795 struct acl_cond *cond = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001796 int cs;
1797 int cap;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001798
1799 if (px == &defproxy) {
1800 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001801 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001802 goto err;
1803 }
1804
1805 if (*reg == 0) {
1806 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001807 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001808 goto err;
1809 }
1810
Christopher Faulet898566e2016-10-26 11:06:28 +02001811 if (warnifnotcap(px, PR_CAP_FE | PR_CAP_BE, file, line, cmd, NULL))
Willy Tarreau63af98d2014-05-18 08:11:41 +02001812 ret_code |= ERR_WARN;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001813
Willy Tarreau5321c422010-01-28 20:35:13 +01001814 if (cond_start &&
1815 (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02001816 if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) {
1817 Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
1818 file, line, cmd, errmsg);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001819 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5321c422010-01-28 20:35:13 +01001820 goto err;
1821 }
1822 }
1823 else if (cond_start && **cond_start) {
1824 Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
1825 file, line, cmd, *cond_start);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001826 ret_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau5321c422010-01-28 20:35:13 +01001827 goto err;
1828 }
1829
Willy Tarreau63af98d2014-05-18 08:11:41 +02001830 ret_code |= warnif_cond_conflicts(cond,
Willy Tarreaua91d0a52013-03-25 08:12:18 +01001831 (dir == SMP_OPT_DIR_REQ) ?
1832 ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) :
1833 ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR),
1834 file, line);
Willy Tarreau5321c422010-01-28 20:35:13 +01001835
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001836 preg = calloc(1, sizeof(*preg));
Willy Tarreauade5ec42010-01-28 19:33:49 +01001837 if (!preg) {
1838 Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001839 ret_code = ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001840 goto err;
1841 }
1842
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001843 cs = !(flags & REG_ICASE);
1844 cap = !(flags & REG_NOSUB);
1845 error = NULL;
1846 if (!regex_comp(reg, preg, cs, cap, &error)) {
1847 Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error);
1848 free(error);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001849 ret_code = ERR_ALERT | ERR_FATAL;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001850 goto err;
1851 }
1852
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02001853 err = chain_regex((dir == SMP_OPT_DIR_REQ) ? &px->req_exp : &px->rsp_exp,
Willy Tarreau5321c422010-01-28 20:35:13 +01001854 preg, action, repl ? strdup(repl) : NULL, cond);
Willy Tarreauade5ec42010-01-28 19:33:49 +01001855 if (repl && err) {
1856 Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n",
1857 file, line, cmd, *err);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001858 ret_code |= ERR_ALERT | ERR_FATAL;
1859 goto err_free;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001860 }
1861
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02001862 if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd))
Willy Tarreau63af98d2014-05-18 08:11:41 +02001863 ret_code |= ERR_WARN;
1864
1865 return ret_code;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001866
Willy Tarreau63af98d2014-05-18 08:11:41 +02001867 err_free:
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02001868 regex_free(preg);
Willy Tarreauade5ec42010-01-28 19:33:49 +01001869 err:
1870 free(preg);
Willy Tarreau63af98d2014-05-18 08:11:41 +02001871 free(errmsg);
1872 return ret_code;
Willy Tarreauade5ec42010-01-28 19:33:49 +01001873}
1874
Willy Tarreaubaaee002006-06-26 02:48:02 +02001875/*
William Lallemand51097192015-04-14 16:35:22 +02001876 * Parse a line in a <listen>, <frontend> or <backend> section.
Willy Tarreau93893792009-07-23 13:19:11 +02001877 * Returns the error code, 0 if OK, or any combination of :
1878 * - ERR_ABORT: must abort ASAP
1879 * - ERR_FATAL: we can continue parsing but not start the service
1880 * - ERR_WARN: a warning has been emitted
1881 * - ERR_ALERT: an alert has been emitted
1882 * Only the two first ones can stop processing, the two others are just
1883 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001884 */
Emeric Brun32da3c42010-09-23 18:39:19 +02001885int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
1886{
1887 static struct peers *curpeers = NULL;
1888 struct peer *newpeer = NULL;
1889 const char *err;
Willy Tarreau4348fad2012-09-20 16:48:07 +02001890 struct bind_conf *bind_conf;
1891 struct listener *l;
Emeric Brun32da3c42010-09-23 18:39:19 +02001892 int err_code = 0;
Willy Tarreau902636f2013-03-10 19:44:48 +01001893 char *errmsg = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02001894
1895 if (strcmp(args[0], "peers") == 0) { /* new peers section */
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001896 if (!*args[1]) {
1897 Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum);
Willy Tarreau54984722014-02-16 08:20:13 +01001898 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001899 goto out;
1900 }
Emeric Brun32da3c42010-09-23 18:39:19 +02001901
William Lallemand6e62fb62015-04-28 16:55:23 +02001902 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1903 goto out;
1904
Emeric Brun32da3c42010-09-23 18:39:19 +02001905 err = invalid_char(args[1]);
1906 if (err) {
1907 Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1908 file, linenum, *err, args[0], args[1]);
Willy Tarreau54984722014-02-16 08:20:13 +01001909 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau0dbbf312013-03-05 11:31:55 +01001910 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +02001911 }
1912
1913 for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) {
1914 /*
1915 * If there are two proxies with the same name only following
1916 * combinations are allowed:
1917 */
1918 if (strcmp(curpeers->id, args[1]) == 0) {
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001919 Alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n",
Emeric Brun32da3c42010-09-23 18:39:19 +02001920 file, linenum, args[1], curpeers->conf.file, curpeers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02001921 err_code |= ERR_ALERT | ERR_FATAL;
Emeric Brun32da3c42010-09-23 18:39:19 +02001922 }
1923 }
1924
Vincent Bernat02779b62016-04-03 13:48:43 +02001925 if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
Emeric Brun32da3c42010-09-23 18:39:19 +02001926 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1927 err_code |= ERR_ALERT | ERR_ABORT;
1928 goto out;
1929 }
1930
1931 curpeers->next = peers;
1932 peers = curpeers;
Willy Tarreau8113a5d2012-10-04 08:01:43 +02001933 curpeers->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +02001934 curpeers->conf.line = linenum;
1935 curpeers->last_change = now.tv_sec;
1936 curpeers->id = strdup(args[1]);
Willy Tarreau77e4bd12015-05-01 20:02:17 +02001937 curpeers->state = PR_STNEW;
Emeric Brun32da3c42010-09-23 18:39:19 +02001938 }
1939 else if (strcmp(args[0], "peer") == 0) { /* peer definition */
David du Colombier6f5ccb12011-03-10 22:26:24 +01001940 struct sockaddr_storage *sk;
Willy Tarreau2aa38802013-02-20 19:20:59 +01001941 int port1, port2;
Willy Tarreaub36487e2013-03-10 18:37:42 +01001942 struct protocol *proto;
Emeric Brun32da3c42010-09-23 18:39:19 +02001943
1944 if (!*args[2]) {
1945 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1946 file, linenum, args[0]);
1947 err_code |= ERR_ALERT | ERR_FATAL;
1948 goto out;
1949 }
1950
1951 err = invalid_char(args[1]);
1952 if (err) {
1953 Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
1954 file, linenum, *err, args[1]);
1955 err_code |= ERR_ALERT | ERR_FATAL;
1956 goto out;
1957 }
1958
Vincent Bernat02779b62016-04-03 13:48:43 +02001959 if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) {
Emeric Brun32da3c42010-09-23 18:39:19 +02001960 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1961 err_code |= ERR_ALERT | ERR_ABORT;
1962 goto out;
1963 }
1964
1965 /* the peers are linked backwards first */
1966 curpeers->count++;
1967 newpeer->next = curpeers->remote;
1968 curpeers->remote = newpeer;
Willy Tarreau8113a5d2012-10-04 08:01:43 +02001969 newpeer->conf.file = strdup(file);
Emeric Brun32da3c42010-09-23 18:39:19 +02001970 newpeer->conf.line = linenum;
1971
1972 newpeer->last_change = now.tv_sec;
1973 newpeer->id = strdup(args[1]);
1974
Willy Tarreau48ef4c92017-01-06 18:32:38 +01001975 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau2aa38802013-02-20 19:20:59 +01001976 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01001977 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau2aa38802013-02-20 19:20:59 +01001978 err_code |= ERR_ALERT | ERR_FATAL;
1979 goto out;
Emeric Brun32da3c42010-09-23 18:39:19 +02001980 }
Willy Tarreaub36487e2013-03-10 18:37:42 +01001981
1982 proto = protocol_by_family(sk->ss_family);
1983 if (!proto || !proto->connect) {
1984 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
1985 file, linenum, args[0], args[1]);
1986 err_code |= ERR_ALERT | ERR_FATAL;
1987 goto out;
1988 }
Willy Tarreau2aa38802013-02-20 19:20:59 +01001989
1990 if (port1 != port2) {
1991 Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
1992 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02001993 err_code |= ERR_ALERT | ERR_FATAL;
1994 goto out;
1995 }
1996
Willy Tarreau2aa38802013-02-20 19:20:59 +01001997 if (!port1) {
1998 Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
1999 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002000 err_code |= ERR_ALERT | ERR_FATAL;
2001 goto out;
2002 }
Willy Tarreau2aa38802013-02-20 19:20:59 +01002003
Emeric Brun32da3c42010-09-23 18:39:19 +02002004 newpeer->addr = *sk;
Willy Tarreaub36487e2013-03-10 18:37:42 +01002005 newpeer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002006 newpeer->xprt = xprt_get(XPRT_RAW);
Willy Tarreaud02394b2012-05-11 18:32:18 +02002007 newpeer->sock_init_arg = NULL;
Willy Tarreau26d8c592012-05-07 18:12:14 +02002008
Emeric Brun32da3c42010-09-23 18:39:19 +02002009 if (strcmp(newpeer->id, localpeer) == 0) {
2010 /* Current is local peer, it define a frontend */
2011 newpeer->local = 1;
Emeric Brunb3971ab2015-05-12 18:49:09 +02002012 peers->local = newpeer;
Emeric Brun32da3c42010-09-23 18:39:19 +02002013
2014 if (!curpeers->peers_fe) {
2015 if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) {
2016 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2017 err_code |= ERR_ALERT | ERR_ABORT;
2018 goto out;
2019 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002020
Willy Tarreau237250c2011-07-29 01:49:03 +02002021 init_new_proxy(curpeers->peers_fe);
2022 curpeers->peers_fe->parent = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02002023 curpeers->peers_fe->id = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002024 curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file);
2025 curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum;
Willy Tarreau91d96282015-03-13 15:47:26 +01002026 peers_setup_frontend(curpeers->peers_fe);
Willy Tarreau4348fad2012-09-20 16:48:07 +02002027
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002028 bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW));
Willy Tarreau4348fad2012-09-20 16:48:07 +02002029
Willy Tarreau902636f2013-03-10 19:44:48 +01002030 if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
2031 if (errmsg && *errmsg) {
2032 indent_msg(&errmsg, 2);
2033 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
Willy Tarreau4fbb2282012-09-20 20:01:39 +02002034 }
2035 else
2036 Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n",
2037 file, linenum, args[0], args[1], args[2]);
Emeric Brun32da3c42010-09-23 18:39:19 +02002038 err_code |= ERR_FATAL;
2039 goto out;
2040 }
Willy Tarreau4348fad2012-09-20 16:48:07 +02002041
2042 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
Willy Tarreauacf3bf92013-01-18 10:51:07 +01002043 l->maxaccept = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002044 l->maxconn = curpeers->peers_fe->maxconn;
2045 l->backlog = curpeers->peers_fe->backlog;
Willy Tarreau9903f0e2015-04-04 18:50:31 +02002046 l->accept = session_accept_fd;
Willy Tarreau87b09662015-04-03 00:22:06 +02002047 l->handler = process_stream;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002048 l->analysers |= curpeers->peers_fe->fe_req_ana;
2049 l->default_target = curpeers->peers_fe->default_target;
Willy Tarreau4348fad2012-09-20 16:48:07 +02002050 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
2051 global.maxsock += l->maxconn;
2052 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002053 }
Willy Tarreau8b8fd562013-01-18 11:12:27 +01002054 else {
2055 Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n",
2056 file, linenum, args[0], args[1],
2057 curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line);
2058 err_code |= ERR_FATAL;
2059 goto out;
2060 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002061 }
2062 } /* neither "peer" nor "peers" */
Willy Tarreau77e4bd12015-05-01 20:02:17 +02002063 else if (!strcmp(args[0], "disabled")) { /* disables this peers section */
2064 curpeers->state = PR_STSTOPPED;
2065 }
2066 else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */
2067 curpeers->state = PR_STNEW;
2068 }
Emeric Brun32da3c42010-09-23 18:39:19 +02002069 else if (*args[0] != 0) {
2070 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
2071 err_code |= ERR_ALERT | ERR_FATAL;
2072 goto out;
2073 }
2074
2075out:
Willy Tarreau902636f2013-03-10 19:44:48 +01002076 free(errmsg);
Emeric Brun32da3c42010-09-23 18:39:19 +02002077 return err_code;
2078}
2079
Baptiste Assmann325137d2015-04-13 23:40:55 +02002080/*
2081 * Parse a <resolvers> section.
2082 * Returns the error code, 0 if OK, or any combination of :
2083 * - ERR_ABORT: must abort ASAP
2084 * - ERR_FATAL: we can continue parsing but not start the service
2085 * - ERR_WARN: a warning has been emitted
2086 * - ERR_ALERT: an alert has been emitted
2087 * Only the two first ones can stop processing, the two others are just
2088 * indicators.
2089 */
2090int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
2091{
2092 static struct dns_resolvers *curr_resolvers = NULL;
2093 struct dns_nameserver *newnameserver = NULL;
2094 const char *err;
2095 int err_code = 0;
2096 char *errmsg = NULL;
2097
2098 if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */
2099 if (!*args[1]) {
2100 Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum);
2101 err_code |= ERR_ALERT | ERR_ABORT;
2102 goto out;
2103 }
2104
2105 err = invalid_char(args[1]);
2106 if (err) {
2107 Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2108 file, linenum, *err, args[0], args[1]);
2109 err_code |= ERR_ALERT | ERR_ABORT;
2110 goto out;
2111 }
2112
2113 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
2114 /* Error if two resolvers owns the same name */
2115 if (strcmp(curr_resolvers->id, args[1]) == 0) {
2116 Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n",
2117 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
2118 err_code |= ERR_ALERT | ERR_ABORT;
2119 }
2120 }
2121
Vincent Bernat02779b62016-04-03 13:48:43 +02002122 if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
Baptiste Assmann325137d2015-04-13 23:40:55 +02002123 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2124 err_code |= ERR_ALERT | ERR_ABORT;
2125 goto out;
2126 }
2127
2128 /* default values */
2129 LIST_ADDQ(&dns_resolvers, &curr_resolvers->list);
2130 curr_resolvers->conf.file = strdup(file);
2131 curr_resolvers->conf.line = linenum;
2132 curr_resolvers->id = strdup(args[1]);
2133 curr_resolvers->query_ids = EB_ROOT;
Baptiste Assmann987e16d2016-11-02 22:23:31 +01002134 /* default hold period for nx, other, refuse and timeout is 30s */
2135 curr_resolvers->hold.nx = 30000;
2136 curr_resolvers->hold.other = 30000;
2137 curr_resolvers->hold.refused = 30000;
2138 curr_resolvers->hold.timeout = 30000;
Baptiste Assmann325137d2015-04-13 23:40:55 +02002139 /* default hold period for valid is 10s */
Baptiste Assmann4c5490a2015-07-14 21:42:49 +02002140 curr_resolvers->hold.valid = 10000;
2141 curr_resolvers->timeout.retry = 1000;
Baptiste Assmann325137d2015-04-13 23:40:55 +02002142 curr_resolvers->resolve_retries = 3;
2143 LIST_INIT(&curr_resolvers->nameserver_list);
2144 LIST_INIT(&curr_resolvers->curr_resolution);
2145 }
2146 else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
2147 struct sockaddr_storage *sk;
2148 int port1, port2;
2149 struct protocol *proto;
2150
2151 if (!*args[2]) {
2152 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
2153 file, linenum, args[0]);
2154 err_code |= ERR_ALERT | ERR_FATAL;
2155 goto out;
2156 }
2157
2158 err = invalid_char(args[1]);
2159 if (err) {
2160 Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
2161 file, linenum, *err, args[1]);
2162 err_code |= ERR_ALERT | ERR_FATAL;
2163 goto out;
2164 }
2165
Baptiste Assmanna315c552015-11-02 22:55:49 +01002166 list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) {
2167 /* Error if two resolvers owns the same name */
2168 if (strcmp(newnameserver->id, args[1]) == 0) {
2169 Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n",
2170 file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line);
2171 err_code |= ERR_ALERT | ERR_FATAL;
2172 }
2173 }
2174
Vincent Bernat02779b62016-04-03 13:48:43 +02002175 if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
Baptiste Assmann325137d2015-04-13 23:40:55 +02002176 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2177 err_code |= ERR_ALERT | ERR_ABORT;
2178 goto out;
2179 }
2180
2181 /* the nameservers are linked backward first */
2182 LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list);
2183 curr_resolvers->count_nameservers++;
2184 newnameserver->resolvers = curr_resolvers;
2185 newnameserver->conf.file = strdup(file);
2186 newnameserver->conf.line = linenum;
2187 newnameserver->id = strdup(args[1]);
2188
Willy Tarreau48ef4c92017-01-06 18:32:38 +01002189 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002190 if (!sk) {
2191 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
2192 err_code |= ERR_ALERT | ERR_FATAL;
2193 goto out;
2194 }
2195
2196 proto = protocol_by_family(sk->ss_family);
2197 if (!proto || !proto->connect) {
2198 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
2199 file, linenum, args[0], args[1]);
2200 err_code |= ERR_ALERT | ERR_FATAL;
2201 goto out;
2202 }
2203
2204 if (port1 != port2) {
2205 Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
2206 file, linenum, args[0], args[1], args[2]);
2207 err_code |= ERR_ALERT | ERR_FATAL;
2208 goto out;
2209 }
2210
Baptiste Assmann7f43fa92016-01-21 00:59:46 +01002211 if (!port1 && !port2) {
2212 Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n",
2213 file, linenum, args[0], args[1]);
2214 err_code |= ERR_ALERT | ERR_FATAL;
2215 goto out;
2216 }
2217
Baptiste Assmann325137d2015-04-13 23:40:55 +02002218 newnameserver->addr = *sk;
2219 }
2220 else if (strcmp(args[0], "hold") == 0) { /* hold periods */
2221 const char *res;
2222 unsigned int time;
2223
2224 if (!*args[2]) {
2225 Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n",
2226 file, linenum, args[0]);
2227 Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n");
2228 err_code |= ERR_ALERT | ERR_FATAL;
2229 goto out;
2230 }
2231 res = parse_time_err(args[2], &time, TIME_UNIT_MS);
2232 if (res) {
2233 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
2234 file, linenum, *res, args[0]);
2235 err_code |= ERR_ALERT | ERR_FATAL;
2236 goto out;
2237 }
Baptiste Assmann987e16d2016-11-02 22:23:31 +01002238 if (strcmp(args[1], "nx") == 0)
2239 curr_resolvers->hold.nx = time;
2240 else if (strcmp(args[1], "other") == 0)
2241 curr_resolvers->hold.other = time;
2242 else if (strcmp(args[1], "refused") == 0)
2243 curr_resolvers->hold.refused = time;
2244 else if (strcmp(args[1], "timeout") == 0)
2245 curr_resolvers->hold.timeout = time;
2246 else if (strcmp(args[1], "valid") == 0)
Baptiste Assmann325137d2015-04-13 23:40:55 +02002247 curr_resolvers->hold.valid = time;
2248 else {
Baptiste Assmann987e16d2016-11-02 22:23:31 +01002249 Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', or 'other'.\n",
2250 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002251 err_code |= ERR_ALERT | ERR_FATAL;
2252 goto out;
2253 }
2254
2255 }
2256 else if (strcmp(args[0], "resolve_retries") == 0) {
2257 if (!*args[1]) {
2258 Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n",
2259 file, linenum, args[0]);
2260 err_code |= ERR_ALERT | ERR_FATAL;
2261 goto out;
2262 }
2263 curr_resolvers->resolve_retries = atoi(args[1]);
2264 }
2265 else if (strcmp(args[0], "timeout") == 0) {
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002266 if (!*args[1]) {
Baptiste Assmann325137d2015-04-13 23:40:55 +02002267 Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n",
2268 file, linenum, args[0]);
2269 err_code |= ERR_ALERT | ERR_FATAL;
2270 goto out;
2271 }
Pieter Baauw7a91a0e2016-02-13 15:51:58 +01002272 else if (strcmp(args[1], "retry") == 0) {
2273 const char *res;
2274 unsigned int timeout_retry;
2275
2276 if (!*args[2]) {
2277 Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
2278 file, linenum, args[0], args[1]);
2279 err_code |= ERR_ALERT | ERR_FATAL;
2280 goto out;
2281 }
2282 res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS);
2283 if (res) {
2284 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
2285 file, linenum, *res, args[0], args[1]);
2286 err_code |= ERR_ALERT | ERR_FATAL;
2287 goto out;
2288 }
2289 curr_resolvers->timeout.retry = timeout_retry;
2290 }
2291 else {
2292 Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n",
2293 file, linenum, args[0], args[1]);
Baptiste Assmann325137d2015-04-13 23:40:55 +02002294 err_code |= ERR_ALERT | ERR_FATAL;
2295 goto out;
2296 }
Baptiste Assmann325137d2015-04-13 23:40:55 +02002297 } /* neither "nameserver" nor "resolvers" */
2298 else if (*args[0] != 0) {
2299 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
2300 err_code |= ERR_ALERT | ERR_FATAL;
2301 goto out;
2302 }
2303
2304 out:
2305 free(errmsg);
2306 return err_code;
2307}
Simon Horman0d16a402015-01-30 11:22:58 +09002308
2309/*
William Lallemand51097192015-04-14 16:35:22 +02002310 * Parse a line in a <listen>, <frontend> or <backend> section.
Simon Horman0d16a402015-01-30 11:22:58 +09002311 * Returns the error code, 0 if OK, or any combination of :
2312 * - ERR_ABORT: must abort ASAP
2313 * - ERR_FATAL: we can continue parsing but not start the service
2314 * - ERR_WARN: a warning has been emitted
2315 * - ERR_ALERT: an alert has been emitted
2316 * Only the two first ones can stop processing, the two others are just
2317 * indicators.
2318 */
2319int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
2320{
2321 static struct mailers *curmailers = NULL;
2322 struct mailer *newmailer = NULL;
2323 const char *err;
2324 int err_code = 0;
2325 char *errmsg = NULL;
2326
2327 if (strcmp(args[0], "mailers") == 0) { /* new mailers section */
2328 if (!*args[1]) {
2329 Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum);
2330 err_code |= ERR_ALERT | ERR_ABORT;
2331 goto out;
2332 }
2333
2334 err = invalid_char(args[1]);
2335 if (err) {
2336 Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2337 file, linenum, *err, args[0], args[1]);
2338 err_code |= ERR_ALERT | ERR_ABORT;
2339 goto out;
2340 }
2341
2342 for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) {
2343 /*
2344 * If there are two proxies with the same name only following
2345 * combinations are allowed:
2346 */
2347 if (strcmp(curmailers->id, args[1]) == 0) {
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002348 Alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n",
Simon Horman0d16a402015-01-30 11:22:58 +09002349 file, linenum, args[1], curmailers->conf.file, curmailers->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002350 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman0d16a402015-01-30 11:22:58 +09002351 }
2352 }
2353
Vincent Bernat02779b62016-04-03 13:48:43 +02002354 if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
Simon Horman0d16a402015-01-30 11:22:58 +09002355 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2356 err_code |= ERR_ALERT | ERR_ABORT;
2357 goto out;
2358 }
2359
2360 curmailers->next = mailers;
2361 mailers = curmailers;
2362 curmailers->conf.file = strdup(file);
2363 curmailers->conf.line = linenum;
2364 curmailers->id = strdup(args[1]);
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002365 curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP.
2366 * But need enough time so that timeouts don't occur
2367 * during tcp procssing. For now just us an arbitrary default. */
Simon Horman0d16a402015-01-30 11:22:58 +09002368 }
2369 else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */
2370 struct sockaddr_storage *sk;
2371 int port1, port2;
2372 struct protocol *proto;
2373
2374 if (!*args[2]) {
2375 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
2376 file, linenum, args[0]);
2377 err_code |= ERR_ALERT | ERR_FATAL;
2378 goto out;
2379 }
2380
2381 err = invalid_char(args[1]);
2382 if (err) {
2383 Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n",
2384 file, linenum, *err, args[1]);
2385 err_code |= ERR_ALERT | ERR_FATAL;
2386 goto out;
2387 }
2388
Vincent Bernat02779b62016-04-03 13:48:43 +02002389 if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
Simon Horman0d16a402015-01-30 11:22:58 +09002390 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2391 err_code |= ERR_ALERT | ERR_ABORT;
2392 goto out;
2393 }
2394
2395 /* the mailers are linked backwards first */
2396 curmailers->count++;
2397 newmailer->next = curmailers->mailer_list;
2398 curmailers->mailer_list = newmailer;
2399 newmailer->mailers = curmailers;
2400 newmailer->conf.file = strdup(file);
2401 newmailer->conf.line = linenum;
2402
2403 newmailer->id = strdup(args[1]);
2404
Willy Tarreau48ef4c92017-01-06 18:32:38 +01002405 sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Simon Horman0d16a402015-01-30 11:22:58 +09002406 if (!sk) {
2407 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
2408 err_code |= ERR_ALERT | ERR_FATAL;
2409 goto out;
2410 }
2411
2412 proto = protocol_by_family(sk->ss_family);
Simon Horman0ba0e4a2015-01-30 11:23:00 +09002413 if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) {
2414 Alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n",
Simon Horman0d16a402015-01-30 11:22:58 +09002415 file, linenum, args[0], args[1]);
2416 err_code |= ERR_ALERT | ERR_FATAL;
2417 goto out;
2418 }
2419
2420 if (port1 != port2) {
2421 Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
2422 file, linenum, args[0], args[1], args[2]);
2423 err_code |= ERR_ALERT | ERR_FATAL;
2424 goto out;
2425 }
2426
2427 if (!port1) {
2428 Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
2429 file, linenum, args[0], args[1], args[2]);
2430 err_code |= ERR_ALERT | ERR_FATAL;
2431 goto out;
2432 }
2433
2434 newmailer->addr = *sk;
2435 newmailer->proto = proto;
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002436 newmailer->xprt = xprt_get(XPRT_RAW);
Simon Horman0d16a402015-01-30 11:22:58 +09002437 newmailer->sock_init_arg = NULL;
Pieter Baauw235fcfc2016-02-13 15:33:40 +01002438 }
2439 else if (strcmp(args[0], "timeout") == 0) {
2440 if (!*args[1]) {
2441 Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n",
2442 file, linenum, args[0]);
2443 err_code |= ERR_ALERT | ERR_FATAL;
2444 goto out;
2445 }
2446 else if (strcmp(args[1], "mail") == 0) {
2447 const char *res;
2448 unsigned int timeout_mail;
2449 if (!*args[2]) {
2450 Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
2451 file, linenum, args[0], args[1]);
2452 err_code |= ERR_ALERT | ERR_FATAL;
2453 goto out;
2454 }
2455 res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS);
2456 if (res) {
2457 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
2458 file, linenum, *res, args[0]);
2459 err_code |= ERR_ALERT | ERR_FATAL;
2460 goto out;
2461 }
2462 if (timeout_mail <= 0) {
2463 Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]);
2464 err_code |= ERR_ALERT | ERR_FATAL;
2465 goto out;
2466 }
2467 curmailers->timeout.mail = timeout_mail;
2468 } else {
2469 Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n",
2470 file, linenum, args[0], args[1]);
2471 err_code |= ERR_ALERT | ERR_FATAL;
2472 goto out;
2473 }
2474 }
Simon Horman0d16a402015-01-30 11:22:58 +09002475 else if (*args[0] != 0) {
2476 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
2477 err_code |= ERR_ALERT | ERR_FATAL;
2478 goto out;
2479 }
2480
2481out:
2482 free(errmsg);
2483 return err_code;
2484}
2485
Simon Horman9dc49962015-01-30 11:22:59 +09002486static void free_email_alert(struct proxy *p)
2487{
2488 free(p->email_alert.mailers.name);
2489 p->email_alert.mailers.name = NULL;
2490 free(p->email_alert.from);
2491 p->email_alert.from = NULL;
2492 free(p->email_alert.to);
2493 p->email_alert.to = NULL;
2494 free(p->email_alert.myhostname);
2495 p->email_alert.myhostname = NULL;
2496}
2497
Willy Tarreau3842f002009-06-14 11:39:52 +02002498int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
Willy Tarreaubaaee002006-06-26 02:48:02 +02002499{
2500 static struct proxy *curproxy = NULL;
Willy Tarreaub17916e2006-10-15 15:17:57 +02002501 const char *err;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002502 char *error;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01002503 int rc;
2504 unsigned val;
Willy Tarreau93893792009-07-23 13:19:11 +02002505 int err_code = 0;
Willy Tarreau3ec18a02010-01-28 19:01:34 +01002506 struct acl_cond *cond = NULL;
William Lallemand723b73a2012-02-08 16:37:49 +01002507 struct logsrv *tmplogsrv;
Willy Tarreauf4068b62012-05-08 17:37:49 +02002508 char *errmsg = NULL;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02002509 struct bind_conf *bind_conf;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002510
Willy Tarreau977b8e42006-12-29 14:19:17 +01002511 if (!strcmp(args[0], "listen"))
2512 rc = PR_CAP_LISTEN;
2513 else if (!strcmp(args[0], "frontend"))
Christopher Faulet898566e2016-10-26 11:06:28 +02002514 rc = PR_CAP_FE;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02002515 else if (!strcmp(args[0], "backend"))
Christopher Faulet898566e2016-10-26 11:06:28 +02002516 rc = PR_CAP_BE;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002517 else
2518 rc = PR_CAP_NONE;
2519
2520 if (rc != PR_CAP_NONE) { /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +02002521 if (!*args[1]) {
2522 Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
Ian Miell71c432e2015-08-18 19:32:08 +01002523 " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
Willy Tarreaubaaee002006-06-26 02:48:02 +02002524 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002525 err_code |= ERR_ALERT | ERR_ABORT;
2526 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002527 }
Krzysztof Oledzki365d1cd2007-10-21 02:55:17 +02002528
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01002529 err = invalid_char(args[1]);
2530 if (err) {
2531 Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
2532 file, linenum, *err, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02002533 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01002534 }
2535
Willy Tarreau8f50b682015-05-26 11:45:02 +02002536 curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]);
2537 if (curproxy) {
2538 Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n",
2539 file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy),
2540 curproxy->id, curproxy->conf.file, curproxy->conf.line);
Willy Tarreau911fa2e2015-05-26 10:35:50 +02002541 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki365d1cd2007-10-21 02:55:17 +02002542 }
2543
Vincent Bernat02779b62016-04-03 13:48:43 +02002544 if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002545 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02002546 err_code |= ERR_ALERT | ERR_ABORT;
2547 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002548 }
Willy Tarreau5af24ef2009-03-15 15:23:16 +01002549
Willy Tarreau97cb7802010-01-03 20:23:58 +01002550 init_new_proxy(curproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002551 curproxy->next = proxy;
2552 proxy = curproxy;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002553 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
2554 curproxy->conf.args.line = curproxy->conf.line = linenum;
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002555 curproxy->last_change = now.tv_sec;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002556 curproxy->id = strdup(args[1]);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002557 curproxy->cap = rc;
Willy Tarreauf79d9502014-03-15 07:22:35 +01002558 proxy_store_name(curproxy);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002559
William Lallemand6e62fb62015-04-28 16:55:23 +02002560 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
2561 if (curproxy->cap & PR_CAP_FE)
2562 Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum);
2563 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002564 }
2565
2566 /* set default values */
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002567 memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv));
Willy Tarreau70160202010-04-07 16:06:40 +02002568 curproxy->defsrv.id = "default-server";
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002569
Willy Tarreaubaaee002006-06-26 02:48:02 +02002570 curproxy->state = defproxy.state;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002571 curproxy->options = defproxy.options;
Willy Tarreau66aa61f2009-01-18 21:44:07 +01002572 curproxy->options2 = defproxy.options2;
Willy Tarreau84b57da2009-06-14 11:10:45 +02002573 curproxy->no_options = defproxy.no_options;
2574 curproxy->no_options2 = defproxy.no_options2;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002575 curproxy->bind_proc = defproxy.bind_proc;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02002576 curproxy->except_net = defproxy.except_net;
2577 curproxy->except_mask = defproxy.except_mask;
Maik Broemme36db02e2009-05-08 17:02:07 +02002578 curproxy->except_to = defproxy.except_to;
Maik Broemme2850cb42009-04-17 18:53:21 +02002579 curproxy->except_mask_to = defproxy.except_mask_to;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002580
Willy Tarreau79f5fe82008-08-23 08:18:21 +02002581 if (defproxy.fwdfor_hdr_len) {
2582 curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len;
2583 curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name);
2584 }
2585
Willy Tarreaub86db342009-11-30 11:50:16 +01002586 if (defproxy.orgto_hdr_len) {
2587 curproxy->orgto_hdr_len = defproxy.orgto_hdr_len;
2588 curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name);
2589 }
2590
Mark Lamourinec2247f02012-01-04 13:02:01 -05002591 if (defproxy.server_id_hdr_len) {
2592 curproxy->server_id_hdr_len = defproxy.server_id_hdr_len;
2593 curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name);
2594 }
2595
Willy Tarreau977b8e42006-12-29 14:19:17 +01002596 if (curproxy->cap & PR_CAP_FE) {
2597 curproxy->maxconn = defproxy.maxconn;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01002598 curproxy->backlog = defproxy.backlog;
Willy Tarreau13a34bd2009-05-10 18:52:49 +02002599 curproxy->fe_sps_lim = defproxy.fe_sps_lim;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002600
2601 /* initialize error relocations */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002602 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
2603 chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002604
2605 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
2606 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002607
Willy Tarreau977b8e42006-12-29 14:19:17 +01002608 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreau743c1282014-11-18 15:04:29 +01002609 curproxy->lbprm.algo = defproxy.lbprm.algo;
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04002610 curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002611 curproxy->fullconn = defproxy.fullconn;
2612 curproxy->conn_retries = defproxy.conn_retries;
Joseph Lynch726ab712015-05-11 23:25:34 -07002613 curproxy->redispatch_after = defproxy.redispatch_after;
Willy Tarreauc35362a2014-04-25 13:58:37 +02002614 curproxy->max_ka_queue = defproxy.max_ka_queue;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002615
Willy Tarreauaa2f3892010-10-22 16:15:31 +02002616 if (defproxy.check_req) {
2617 curproxy->check_req = calloc(1, defproxy.check_len);
2618 memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len);
2619 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002620 curproxy->check_len = defproxy.check_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002621
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002622 if (defproxy.expect_str) {
2623 curproxy->expect_str = strdup(defproxy.expect_str);
2624 if (defproxy.expect_regex) {
2625 /* note: this regex is known to be valid */
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002626 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
2627 regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL);
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002628 }
2629 }
2630
Willy Tarreau67402132012-05-31 20:40:20 +02002631 curproxy->ck_opts = defproxy.ck_opts;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002632 if (defproxy.cookie_name)
2633 curproxy->cookie_name = strdup(defproxy.cookie_name);
2634 curproxy->cookie_len = defproxy.cookie_len;
Olivier Houchard4e694042017-03-14 20:01:29 +01002635
2636 if (defproxy.dyncookie_key)
2637 curproxy->dyncookie_key = strdup(defproxy.dyncookie_key);
Willy Tarreau4d187ac2009-12-03 23:13:06 +01002638 if (defproxy.cookie_domain)
2639 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
Willy Tarreau01732802007-11-01 22:48:15 +01002640
Willy Tarreau31936852010-10-06 16:59:56 +02002641 if (defproxy.cookie_maxidle)
2642 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
2643
2644 if (defproxy.cookie_maxlife)
2645 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
2646
Emeric Brun647caf12009-06-30 17:57:00 +02002647 if (defproxy.rdp_cookie_name)
2648 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
2649 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
2650
Willy Tarreau01732802007-11-01 22:48:15 +01002651 if (defproxy.url_param_name)
2652 curproxy->url_param_name = strdup(defproxy.url_param_name);
2653 curproxy->url_param_len = defproxy.url_param_len;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01002654
Benoitaffb4812009-03-25 13:02:10 +01002655 if (defproxy.hh_name)
2656 curproxy->hh_name = strdup(defproxy.hh_name);
2657 curproxy->hh_len = defproxy.hh_len;
2658 curproxy->hh_match_domain = defproxy.hh_match_domain;
2659
Willy Tarreauef9a3602012-12-08 22:29:20 +01002660 if (defproxy.conn_src.iface_name)
2661 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
2662 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
Godbach9f048532013-04-23 15:27:57 +08002663 curproxy->conn_src.opts = defproxy.conn_src.opts;
Willy Tarreau29fbe512015-08-20 19:35:14 +02002664#if defined(CONFIG_HAP_TRANSPARENT)
Godbach9f048532013-04-23 15:27:57 +08002665 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
Willy Tarreauc621d362013-04-25 17:35:22 +02002666#endif
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02002667 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002668 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002669
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02002670 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002671 if (defproxy.capture_name)
2672 curproxy->capture_name = strdup(defproxy.capture_name);
2673 curproxy->capture_namelen = defproxy.capture_namelen;
2674 curproxy->capture_len = defproxy.capture_len;
Willy Tarreau0f772532006-12-23 20:51:41 +01002675 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002676
Willy Tarreau977b8e42006-12-29 14:19:17 +01002677 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002678 curproxy->timeout.client = defproxy.timeout.client;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002679 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002680 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau036fae02008-01-06 13:24:40 +01002681 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002682 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002683 curproxy->mon_net = defproxy.mon_net;
2684 curproxy->mon_mask = defproxy.mon_mask;
2685 if (defproxy.monitor_uri)
2686 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
2687 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002688 if (defproxy.defbe.name)
2689 curproxy->defbe.name = strdup(defproxy.defbe.name);
Willy Tarreau99a7ca22012-05-31 19:39:23 +02002690
2691 /* get either a pointer to the logformat string or a copy of it */
Willy Tarreau62a61232013-04-12 18:13:46 +02002692 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
2693 if (curproxy->conf.logformat_string &&
2694 curproxy->conf.logformat_string != default_http_log_format &&
2695 curproxy->conf.logformat_string != default_tcp_log_format &&
2696 curproxy->conf.logformat_string != clf_http_log_format)
2697 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
2698
2699 if (defproxy.conf.lfs_file) {
2700 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
2701 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
2702 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002703
2704 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
2705 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
2706 if (curproxy->conf.logformat_sd_string &&
2707 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2708 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
2709
2710 if (defproxy.conf.lfsd_file) {
2711 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
2712 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
2713 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002714 }
2715
2716 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002717 curproxy->timeout.connect = defproxy.timeout.connect;
2718 curproxy->timeout.server = defproxy.timeout.server;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002719 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01002720 curproxy->timeout.check = defproxy.timeout.check;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002721 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau51c9bde2008-01-06 13:40:03 +01002722 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreaucd7afc02009-07-12 10:03:17 +02002723 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002724 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreauce887fd2012-05-12 12:50:00 +02002725 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
Willy Tarreauef9a3602012-12-08 22:29:20 +01002726 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002727 }
2728
Willy Tarreaubaaee002006-06-26 02:48:02 +02002729 curproxy->mode = defproxy.mode;
Willy Tarreaued2119c2014-04-24 22:10:39 +02002730 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
William Lallemand0f99e342011-10-12 17:50:54 +02002731
2732 /* copy default logsrvs to curproxy */
William Lallemand723b73a2012-02-08 16:37:49 +01002733 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
Vincent Bernat02779b62016-04-03 13:48:43 +02002734 struct logsrv *node = malloc(sizeof(*node));
William Lallemand723b73a2012-02-08 16:37:49 +01002735 memcpy(node, tmplogsrv, sizeof(struct logsrv));
William Lallemand0f99e342011-10-12 17:50:54 +02002736 LIST_INIT(&node->list);
2737 LIST_ADDQ(&curproxy->logsrvs, &node->list);
2738 }
2739
Willy Tarreau62a61232013-04-12 18:13:46 +02002740 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
2741 if (curproxy->conf.uniqueid_format_string)
2742 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
2743
Dragan Dosen43885c72015-10-01 13:18:13 +02002744 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
Willy Tarreau094af4e2015-01-07 15:03:42 +01002745
Willy Tarreau62a61232013-04-12 18:13:46 +02002746 if (defproxy.conf.uif_file) {
2747 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
2748 curproxy->conf.uif_line = defproxy.conf.uif_line;
2749 }
William Lallemanda73203e2012-03-12 12:48:57 +01002750
2751 /* copy default header unique id */
2752 if (defproxy.header_unique_id)
2753 curproxy->header_unique_id = strdup(defproxy.header_unique_id);
2754
William Lallemand82fe75c2012-10-23 10:25:10 +02002755 /* default compression options */
2756 if (defproxy.comp != NULL) {
2757 curproxy->comp = calloc(1, sizeof(struct comp));
2758 curproxy->comp->algos = defproxy.comp->algos;
2759 curproxy->comp->types = defproxy.comp->types;
2760 }
2761
Willy Tarreaubaaee002006-06-26 02:48:02 +02002762 curproxy->grace = defproxy.grace;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002763 curproxy->conf.used_listener_id = EB_ROOT;
2764 curproxy->conf.used_server_id = EB_ROOT;
Willy Tarreau1c47f852006-07-09 08:22:27 +02002765
Simon Horman98637e52014-06-20 12:30:16 +09002766 if (defproxy.check_path)
2767 curproxy->check_path = strdup(defproxy.check_path);
2768 if (defproxy.check_command)
2769 curproxy->check_command = strdup(defproxy.check_command);
2770
Simon Horman9dc49962015-01-30 11:22:59 +09002771 if (defproxy.email_alert.mailers.name)
2772 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
2773 if (defproxy.email_alert.from)
2774 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
2775 if (defproxy.email_alert.to)
2776 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
2777 if (defproxy.email_alert.myhostname)
2778 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
Simon Horman64e34162015-02-06 11:11:57 +09002779 curproxy->email_alert.level = defproxy.email_alert.level;
Cyril Bonté7e084702015-12-04 03:07:06 +01002780 curproxy->email_alert.set = defproxy.email_alert.set;
Simon Horman9dc49962015-01-30 11:22:59 +09002781
Willy Tarreau93893792009-07-23 13:19:11 +02002782 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002783 }
2784 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
2785 /* some variables may have already been initialized earlier */
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002786 /* FIXME-20070101: we should do this too at the end of the
2787 * config parsing to free all default values.
2788 */
William Lallemand6e62fb62015-04-28 16:55:23 +02002789 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
2790 err_code |= ERR_ABORT;
2791 goto out;
2792 }
2793
Willy Tarreaua534fea2008-08-03 12:19:50 +02002794 free(defproxy.check_req);
Simon Horman98637e52014-06-20 12:30:16 +09002795 free(defproxy.check_command);
2796 free(defproxy.check_path);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002797 free(defproxy.cookie_name);
Emeric Brun647caf12009-06-30 17:57:00 +02002798 free(defproxy.rdp_cookie_name);
Olivier Houchard4e694042017-03-14 20:01:29 +01002799 free(defproxy.dyncookie_key);
Willy Tarreau4d187ac2009-12-03 23:13:06 +01002800 free(defproxy.cookie_domain);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002801 free(defproxy.url_param_name);
Benoitaffb4812009-03-25 13:02:10 +01002802 free(defproxy.hh_name);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002803 free(defproxy.capture_name);
2804 free(defproxy.monitor_uri);
2805 free(defproxy.defbe.name);
Willy Tarreauef9a3602012-12-08 22:29:20 +01002806 free(defproxy.conn_src.iface_name);
Willy Tarreau79f5fe82008-08-23 08:18:21 +02002807 free(defproxy.fwdfor_hdr_name);
2808 defproxy.fwdfor_hdr_len = 0;
Willy Tarreaub86db342009-11-30 11:50:16 +01002809 free(defproxy.orgto_hdr_name);
2810 defproxy.orgto_hdr_len = 0;
Mark Lamourinec2247f02012-01-04 13:02:01 -05002811 free(defproxy.server_id_hdr_name);
2812 defproxy.server_id_hdr_len = 0;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002813 free(defproxy.expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02002814 if (defproxy.expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002815 regex_free(defproxy.expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02002816 free(defproxy.expect_regex);
2817 defproxy.expect_regex = NULL;
2818 }
Willy Tarreau0f772532006-12-23 20:51:41 +01002819
Willy Tarreau62a61232013-04-12 18:13:46 +02002820 if (defproxy.conf.logformat_string != default_http_log_format &&
2821 defproxy.conf.logformat_string != default_tcp_log_format &&
2822 defproxy.conf.logformat_string != clf_http_log_format)
2823 free(defproxy.conf.logformat_string);
Willy Tarreau196729e2012-05-31 19:30:26 +02002824
Willy Tarreau62a61232013-04-12 18:13:46 +02002825 free(defproxy.conf.uniqueid_format_string);
2826 free(defproxy.conf.lfs_file);
2827 free(defproxy.conf.uif_file);
Dragan Dosen43885c72015-10-01 13:18:13 +02002828 chunk_destroy(&defproxy.log_tag);
Simon Horman9dc49962015-01-30 11:22:59 +09002829 free_email_alert(&defproxy);
Willy Tarreau196729e2012-05-31 19:30:26 +02002830
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002831 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
2832 free(defproxy.conf.logformat_sd_string);
2833 free(defproxy.conf.lfsd_file);
2834
Willy Tarreaua534fea2008-08-03 12:19:50 +02002835 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002836 chunk_destroy(&defproxy.errmsg[rc]);
Willy Tarreau0f772532006-12-23 20:51:41 +01002837
Willy Tarreaubaaee002006-06-26 02:48:02 +02002838 /* we cannot free uri_auth because it might already be used */
2839 init_default_instance();
2840 curproxy = &defproxy;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002841 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
2842 curproxy->conf.args.line = curproxy->conf.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002843 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
Willy Tarreau93893792009-07-23 13:19:11 +02002844 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002845 }
2846 else if (curproxy == NULL) {
2847 Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02002848 err_code |= ERR_ALERT | ERR_FATAL;
2849 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002850 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002851
2852 /* update the current file and line being parsed */
2853 curproxy->conf.args.file = curproxy->conf.file;
2854 curproxy->conf.args.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002855
2856 /* Now let's parse the proxy-specific keywords */
Willy Tarreau272adea2014-03-31 10:39:59 +02002857 if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) {
2858 err_code |= parse_server(file, linenum, args, curproxy, &defproxy);
2859 if (err_code & ERR_FATAL)
2860 goto out;
2861 }
2862 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002863 struct listener *l;
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002864 int cur_arg;
2865
Willy Tarreaubaaee002006-06-26 02:48:02 +02002866 if (curproxy == &defproxy) {
2867 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002868 err_code |= ERR_ALERT | ERR_FATAL;
2869 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002870 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002871 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002872 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002873
Willy Tarreau24709282013-03-10 21:32:12 +01002874 if (!*(args[1])) {
Willy Tarreaud55c3fe2010-11-09 09:50:37 +01002875 Alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
Willy Tarreaubaaee002006-06-26 02:48:02 +02002876 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002877 err_code |= ERR_ALERT | ERR_FATAL;
2878 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002879 }
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002880
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002881 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Willy Tarreau8dc21fa2013-01-24 15:17:20 +01002882
2883 /* use default settings for unix sockets */
2884 bind_conf->ux.uid = global.unix_bind.ux.uid;
2885 bind_conf->ux.gid = global.unix_bind.ux.gid;
2886 bind_conf->ux.mode = global.unix_bind.ux.mode;
Willy Tarreau8a956912010-10-15 14:27:08 +02002887
2888 /* NOTE: the following line might create several listeners if there
2889 * are comma-separated IPs or port ranges. So all further processing
2890 * will have to be applied to all listeners created after last_listen.
2891 */
Willy Tarreau902636f2013-03-10 19:44:48 +01002892 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
2893 if (errmsg && *errmsg) {
2894 indent_msg(&errmsg, 2);
2895 Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau4fbb2282012-09-20 20:01:39 +02002896 }
2897 else
2898 Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
2899 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02002900 err_code |= ERR_ALERT | ERR_FATAL;
2901 goto out;
2902 }
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002903
Willy Tarreau4348fad2012-09-20 16:48:07 +02002904 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
2905 /* Set default global rights and owner for unix bind */
Willy Tarreauc8b11092011-02-16 11:08:57 +01002906 global.maxsock++;
Willy Tarreau90a570f2009-10-04 20:54:54 +02002907 }
2908
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002909 cur_arg = 2;
2910 while (*(args[cur_arg])) {
Willy Tarreau8638f482012-09-18 18:01:17 +02002911 static int bind_dumped;
Willy Tarreau26982662012-09-12 23:17:10 +02002912 struct bind_kw *kw;
Willy Tarreau8638f482012-09-18 18:01:17 +02002913 char *err;
2914
Willy Tarreau26982662012-09-12 23:17:10 +02002915 kw = bind_find_kw(args[cur_arg]);
2916 if (kw) {
2917 char *err = NULL;
2918 int code;
2919
2920 if (!kw->parse) {
Willy Tarreaudda322d2012-09-18 16:34:09 +02002921 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
2922 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02002923 cur_arg += 1 + kw->skip ;
2924 err_code |= ERR_ALERT | ERR_FATAL;
2925 goto out;
2926 }
2927
Willy Tarreau4348fad2012-09-20 16:48:07 +02002928 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
Willy Tarreau26982662012-09-12 23:17:10 +02002929 err_code |= code;
2930
2931 if (code) {
2932 if (err && *err) {
2933 indent_msg(&err, 2);
Willy Tarreaudda322d2012-09-18 16:34:09 +02002934 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau26982662012-09-12 23:17:10 +02002935 }
2936 else
Willy Tarreaudda322d2012-09-18 16:34:09 +02002937 Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
2938 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02002939 if (code & ERR_FATAL) {
2940 free(err);
2941 cur_arg += 1 + kw->skip;
2942 goto out;
2943 }
2944 }
2945 free(err);
2946 cur_arg += 1 + kw->skip;
2947 continue;
2948 }
2949
Willy Tarreau8638f482012-09-18 18:01:17 +02002950 err = NULL;
2951 if (!bind_dumped) {
2952 bind_dump_kws(&err);
2953 indent_msg(&err, 4);
2954 bind_dumped = 1;
2955 }
2956
2957 Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
2958 file, linenum, args[0], args[1], args[cur_arg],
2959 err ? " Registered keywords :" : "", err ? err : "");
2960 free(err);
2961
Willy Tarreau93893792009-07-23 13:19:11 +02002962 err_code |= ERR_ALERT | ERR_FATAL;
2963 goto out;
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002964 }
Willy Tarreau93893792009-07-23 13:19:11 +02002965 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002966 }
2967 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01002968 if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002969 Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
2970 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002971 err_code |= ERR_ALERT | ERR_FATAL;
2972 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002973 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002974 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002975 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002976
Willy Tarreaubaaee002006-06-26 02:48:02 +02002977 /* flush useless bits */
2978 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
Willy Tarreau93893792009-07-23 13:19:11 +02002979 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002980 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02002981 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
Willy Tarreau977b8e42006-12-29 14:19:17 +01002982 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002983 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002984
William Lallemanddf1425a2015-04-28 20:17:49 +02002985 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2986 goto out;
2987
Willy Tarreau1c47f852006-07-09 08:22:27 +02002988 if (!*args[1]) {
2989 Alert("parsing [%s:%d] : '%s' expects an URI.\n",
2990 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002991 err_code |= ERR_ALERT | ERR_FATAL;
2992 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02002993 }
2994
Willy Tarreaua534fea2008-08-03 12:19:50 +02002995 free(curproxy->monitor_uri);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01002996 curproxy->monitor_uri_len = strlen(args[1]);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002997 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01002998 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
Willy Tarreau1c47f852006-07-09 08:22:27 +02002999 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
3000
Willy Tarreau93893792009-07-23 13:19:11 +02003001 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02003002 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003003 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
William Lallemanddf1425a2015-04-28 20:17:49 +02003004 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3005 goto out;
3006
Willy Tarreaubaaee002006-06-26 02:48:02 +02003007 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
3008 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
3009 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
3010 else {
3011 Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003012 err_code |= ERR_ALERT | ERR_FATAL;
3013 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003014 }
3015 }
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003016 else if (!strcmp(args[0], "id")) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003017 struct eb32_node *node;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003018
3019 if (curproxy == &defproxy) {
3020 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
3021 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003022 err_code |= ERR_ALERT | ERR_FATAL;
3023 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003024 }
3025
William Lallemanddf1425a2015-04-28 20:17:49 +02003026 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3027 goto out;
3028
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003029 if (!*args[1]) {
3030 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
3031 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003032 err_code |= ERR_ALERT | ERR_FATAL;
3033 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003034 }
3035
3036 curproxy->uuid = atol(args[1]);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003037 curproxy->conf.id.key = curproxy->uuid;
Willy Tarreau0d1fdf72015-05-27 16:44:02 +02003038 curproxy->options |= PR_O_FORCED_ID;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003039
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003040 if (curproxy->uuid <= 0) {
3041 Alert("parsing [%s:%d]: custom id has to be > 0.\n",
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003042 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003043 err_code |= ERR_ALERT | ERR_FATAL;
3044 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003045 }
3046
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003047 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
3048 if (node) {
3049 struct proxy *target = container_of(node, struct proxy, conf.id);
3050 Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
3051 file, linenum, proxy_type_str(curproxy), curproxy->id,
3052 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
3053 err_code |= ERR_ALERT | ERR_FATAL;
3054 goto out;
3055 }
3056 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003057 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003058 else if (!strcmp(args[0], "description")) {
3059 int i, len=0;
3060 char *d;
3061
Cyril Bonté99ed3272010-01-24 23:29:44 +01003062 if (curproxy == &defproxy) {
3063 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
3064 file, linenum, args[0]);
3065 err_code |= ERR_ALERT | ERR_FATAL;
3066 goto out;
3067 }
3068
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003069 if (!*args[1]) {
3070 Alert("parsing [%s:%d]: '%s' expects a string argument.\n",
3071 file, linenum, args[0]);
3072 return -1;
3073 }
3074
Willy Tarreau348acfe2014-04-14 15:00:39 +02003075 for (i = 1; *args[i]; i++)
3076 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003077
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003078 d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003079 curproxy->desc = d;
3080
Willy Tarreau348acfe2014-04-14 15:00:39 +02003081 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
3082 for (i = 2; *args[i]; i++)
3083 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003084
3085 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003086 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
William Lallemanddf1425a2015-04-28 20:17:49 +02003087 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3088 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003089 curproxy->state = PR_STSTOPPED;
3090 }
3091 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
William Lallemanddf1425a2015-04-28 20:17:49 +02003092 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3093 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003094 curproxy->state = PR_STNEW;
3095 }
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003096 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
3097 int cur_arg = 1;
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003098 unsigned long set = 0;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003099
3100 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +01003101 unsigned int low, high;
3102
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003103 if (strcmp(args[cur_arg], "all") == 0) {
3104 set = 0;
3105 break;
3106 }
3107 else if (strcmp(args[cur_arg], "odd") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003108 set |= ~0UL/3UL; /* 0x555....555 */
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003109 }
3110 else if (strcmp(args[cur_arg], "even") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003111 set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003112 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +01003113 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +01003114 char *dash = strchr(args[cur_arg], '-');
3115
3116 low = high = str2uic(args[cur_arg]);
3117 if (dash)
3118 high = str2uic(dash + 1);
3119
3120 if (high < low) {
3121 unsigned int swap = low;
3122 low = high;
3123 high = swap;
3124 }
3125
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003126 if (low < 1 || high > LONGBITS) {
3127 Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n",
3128 file, linenum, args[0], LONGBITS);
Willy Tarreau93893792009-07-23 13:19:11 +02003129 err_code |= ERR_ALERT | ERR_FATAL;
3130 goto out;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003131 }
Willy Tarreau110ecc12012-11-15 17:50:01 +01003132 while (low <= high)
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003133 set |= 1UL << (low++ - 1);
Willy Tarreau110ecc12012-11-15 17:50:01 +01003134 }
3135 else {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003136 Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n",
3137 file, linenum, args[0], LONGBITS);
Willy Tarreau110ecc12012-11-15 17:50:01 +01003138 err_code |= ERR_ALERT | ERR_FATAL;
3139 goto out;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003140 }
3141 cur_arg++;
3142 }
3143 curproxy->bind_proc = set;
3144 }
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003145 else if (!strcmp(args[0], "acl")) { /* add an ACL */
Willy Tarreaub099aca2008-10-12 17:26:37 +02003146 if (curproxy == &defproxy) {
3147 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003148 err_code |= ERR_ALERT | ERR_FATAL;
3149 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003150 }
3151
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003152 err = invalid_char(args[1]);
3153 if (err) {
3154 Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
3155 file, linenum, *err, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003156 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003157 }
3158
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01003159 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003160 Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
3161 file, linenum, args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003162 err_code |= ERR_ALERT | ERR_FATAL;
3163 goto out;
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003164 }
Olivier Houchard4e694042017-03-14 20:01:29 +01003165 }
3166 else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */
3167
3168 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3169 err_code |= ERR_WARN;
3170
3171 if (*(args[1]) == 0) {
3172 Alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n",
3173 file, linenum, args[0]);
3174 err_code |= ERR_ALERT | ERR_FATAL;
3175 goto out;
3176 }
3177 free(curproxy->dyncookie_key);
3178 curproxy->dyncookie_key = strdup(args[1]);
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003179 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003180 else if (!strcmp(args[0], "cookie")) { /* cookie name */
3181 int cur_arg;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003182
Willy Tarreau977b8e42006-12-29 14:19:17 +01003183 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003184 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003185
Willy Tarreaubaaee002006-06-26 02:48:02 +02003186 if (*(args[1]) == 0) {
3187 Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
3188 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003189 err_code |= ERR_ALERT | ERR_FATAL;
3190 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003191 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003192
Willy Tarreau67402132012-05-31 20:40:20 +02003193 curproxy->ck_opts = 0;
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003194 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau4d187ac2009-12-03 23:13:06 +01003195 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
Willy Tarreaua534fea2008-08-03 12:19:50 +02003196 free(curproxy->cookie_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003197 curproxy->cookie_name = strdup(args[1]);
3198 curproxy->cookie_len = strlen(curproxy->cookie_name);
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003199
Willy Tarreaubaaee002006-06-26 02:48:02 +02003200 cur_arg = 2;
3201 while (*(args[cur_arg])) {
3202 if (!strcmp(args[cur_arg], "rewrite")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003203 curproxy->ck_opts |= PR_CK_RW;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003204 }
3205 else if (!strcmp(args[cur_arg], "indirect")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003206 curproxy->ck_opts |= PR_CK_IND;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003207 }
3208 else if (!strcmp(args[cur_arg], "insert")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003209 curproxy->ck_opts |= PR_CK_INS;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003210 }
3211 else if (!strcmp(args[cur_arg], "nocache")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003212 curproxy->ck_opts |= PR_CK_NOC;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003213 }
3214 else if (!strcmp(args[cur_arg], "postonly")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003215 curproxy->ck_opts |= PR_CK_POST;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003216 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003217 else if (!strcmp(args[cur_arg], "preserve")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003218 curproxy->ck_opts |= PR_CK_PSV;
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003219 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003220 else if (!strcmp(args[cur_arg], "prefix")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003221 curproxy->ck_opts |= PR_CK_PFX;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003222 }
Willy Tarreau4992dd22012-05-31 21:02:17 +02003223 else if (!strcmp(args[cur_arg], "httponly")) {
3224 curproxy->ck_opts |= PR_CK_HTTPONLY;
3225 }
3226 else if (!strcmp(args[cur_arg], "secure")) {
3227 curproxy->ck_opts |= PR_CK_SECURE;
3228 }
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003229 else if (!strcmp(args[cur_arg], "domain")) {
3230 if (!*args[cur_arg + 1]) {
3231 Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
3232 file, linenum, args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02003233 err_code |= ERR_ALERT | ERR_FATAL;
3234 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003235 }
3236
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003237 if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) {
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003238 /* rfc2109, 4.3.2 Rejecting Cookies */
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003239 Warning("parsing [%s:%d]: domain '%s' contains no embedded"
3240 " dots nor does not start with a dot."
3241 " RFC forbids it, this configuration may not work properly.\n",
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003242 file, linenum, args[cur_arg + 1]);
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003243 err_code |= ERR_WARN;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003244 }
3245
3246 err = invalid_domainchar(args[cur_arg + 1]);
3247 if (err) {
3248 Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
3249 file, linenum, *err, args[cur_arg + 1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003250 err_code |= ERR_ALERT | ERR_FATAL;
3251 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003252 }
3253
Willy Tarreau68a897b2009-12-03 23:28:34 +01003254 if (!curproxy->cookie_domain) {
3255 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
3256 } else {
3257 /* one domain was already specified, add another one by
3258 * building the string which will be returned along with
3259 * the cookie.
3260 */
3261 char *new_ptr;
3262 int new_len = strlen(curproxy->cookie_domain) +
3263 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
3264 new_ptr = malloc(new_len);
3265 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
3266 free(curproxy->cookie_domain);
3267 curproxy->cookie_domain = new_ptr;
3268 }
Willy Tarreau31936852010-10-06 16:59:56 +02003269 cur_arg++;
3270 }
3271 else if (!strcmp(args[cur_arg], "maxidle")) {
3272 unsigned int maxidle;
3273 const char *res;
3274
3275 if (!*args[cur_arg + 1]) {
3276 Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
3277 file, linenum, args[cur_arg]);
3278 err_code |= ERR_ALERT | ERR_FATAL;
3279 goto out;
3280 }
3281
3282 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
3283 if (res) {
3284 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3285 file, linenum, *res, args[cur_arg]);
3286 err_code |= ERR_ALERT | ERR_FATAL;
3287 goto out;
3288 }
3289 curproxy->cookie_maxidle = maxidle;
3290 cur_arg++;
3291 }
3292 else if (!strcmp(args[cur_arg], "maxlife")) {
3293 unsigned int maxlife;
3294 const char *res;
3295
3296 if (!*args[cur_arg + 1]) {
3297 Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
3298 file, linenum, args[cur_arg]);
3299 err_code |= ERR_ALERT | ERR_FATAL;
3300 goto out;
3301 }
3302
3303 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
3304 if (res) {
3305 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3306 file, linenum, *res, args[cur_arg]);
3307 err_code |= ERR_ALERT | ERR_FATAL;
3308 goto out;
3309 }
3310 curproxy->cookie_maxlife = maxlife;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003311 cur_arg++;
3312 }
Olivier Houcharda5938f72017-03-15 15:12:06 +01003313 else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */
Olivier Houchard4e694042017-03-14 20:01:29 +01003314
3315 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL))
3316 err_code |= ERR_WARN;
3317 curproxy->ck_opts |= PR_CK_DYNAMIC;
3318 }
3319
Willy Tarreaubaaee002006-06-26 02:48:02 +02003320 else {
Olivier Houchard4e694042017-03-14 20:01:29 +01003321 Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n",
Willy Tarreaubaaee002006-06-26 02:48:02 +02003322 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003323 err_code |= ERR_ALERT | ERR_FATAL;
3324 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003325 }
3326 cur_arg++;
3327 }
Willy Tarreau67402132012-05-31 20:40:20 +02003328 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02003329 Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
3330 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003331 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003332 }
3333
Willy Tarreau67402132012-05-31 20:40:20 +02003334 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02003335 Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
3336 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003337 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003338 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003339
Willy Tarreau67402132012-05-31 20:40:20 +02003340 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003341 Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
3342 file, linenum);
3343 err_code |= ERR_ALERT | ERR_FATAL;
3344 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003345 }/* end else if (!strcmp(args[0], "cookie")) */
Simon Horman9dc49962015-01-30 11:22:59 +09003346 else if (!strcmp(args[0], "email-alert")) {
3347 if (*(args[1]) == 0) {
3348 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3349 file, linenum, args[0]);
3350 err_code |= ERR_ALERT | ERR_FATAL;
3351 goto out;
3352 }
3353
3354 if (!strcmp(args[1], "from")) {
3355 if (*(args[1]) == 0) {
3356 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3357 file, linenum, args[1]);
3358 err_code |= ERR_ALERT | ERR_FATAL;
3359 goto out;
3360 }
3361 free(curproxy->email_alert.from);
3362 curproxy->email_alert.from = strdup(args[2]);
3363 }
3364 else if (!strcmp(args[1], "mailers")) {
3365 if (*(args[1]) == 0) {
3366 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3367 file, linenum, args[1]);
3368 err_code |= ERR_ALERT | ERR_FATAL;
3369 goto out;
3370 }
3371 free(curproxy->email_alert.mailers.name);
3372 curproxy->email_alert.mailers.name = strdup(args[2]);
3373 }
3374 else if (!strcmp(args[1], "myhostname")) {
3375 if (*(args[1]) == 0) {
3376 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3377 file, linenum, args[1]);
3378 err_code |= ERR_ALERT | ERR_FATAL;
3379 goto out;
3380 }
3381 free(curproxy->email_alert.myhostname);
3382 curproxy->email_alert.myhostname = strdup(args[2]);
3383 }
Simon Horman64e34162015-02-06 11:11:57 +09003384 else if (!strcmp(args[1], "level")) {
3385 curproxy->email_alert.level = get_log_level(args[2]);
3386 if (curproxy->email_alert.level < 0) {
3387 Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
3388 file, linenum, args[1], args[2]);
3389 err_code |= ERR_ALERT | ERR_FATAL;
3390 goto out;
3391 }
3392 }
Simon Horman9dc49962015-01-30 11:22:59 +09003393 else if (!strcmp(args[1], "to")) {
3394 if (*(args[1]) == 0) {
3395 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3396 file, linenum, args[1]);
3397 err_code |= ERR_ALERT | ERR_FATAL;
3398 goto out;
3399 }
3400 free(curproxy->email_alert.to);
3401 curproxy->email_alert.to = strdup(args[2]);
3402 }
3403 else {
3404 Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
3405 file, linenum, args[1]);
3406 err_code |= ERR_ALERT | ERR_FATAL;
3407 goto out;
3408 }
Simon Horman64e34162015-02-06 11:11:57 +09003409 /* Indicate that the email_alert is at least partially configured */
3410 curproxy->email_alert.set = 1;
Simon Horman9dc49962015-01-30 11:22:59 +09003411 }/* end else if (!strcmp(args[0], "email-alert")) */
Simon Horman98637e52014-06-20 12:30:16 +09003412 else if (!strcmp(args[0], "external-check")) {
3413 if (*(args[1]) == 0) {
3414 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3415 file, linenum, args[0]);
3416 err_code |= ERR_ALERT | ERR_FATAL;
3417 goto out;
3418 }
3419
3420 if (!strcmp(args[1], "command")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003421 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003422 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003423 if (*(args[2]) == 0) {
Simon Horman98637e52014-06-20 12:30:16 +09003424 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3425 file, linenum, args[1]);
3426 err_code |= ERR_ALERT | ERR_FATAL;
3427 goto out;
3428 }
3429 free(curproxy->check_command);
3430 curproxy->check_command = strdup(args[2]);
3431 }
3432 else if (!strcmp(args[1], "path")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003433 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003434 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003435 if (*(args[2]) == 0) {
Simon Horman98637e52014-06-20 12:30:16 +09003436 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3437 file, linenum, args[1]);
3438 err_code |= ERR_ALERT | ERR_FATAL;
3439 goto out;
3440 }
3441 free(curproxy->check_path);
3442 curproxy->check_path = strdup(args[2]);
3443 }
3444 else {
3445 Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n",
3446 file, linenum, args[1]);
3447 err_code |= ERR_ALERT | ERR_FATAL;
3448 goto out;
3449 }
3450 }/* end else if (!strcmp(args[0], "external-check")) */
Emeric Brun647caf12009-06-30 17:57:00 +02003451 else if (!strcmp(args[0], "persist")) { /* persist */
3452 if (*(args[1]) == 0) {
3453 Alert("parsing [%s:%d] : missing persist method.\n",
3454 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003455 err_code |= ERR_ALERT | ERR_FATAL;
3456 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003457 }
3458
3459 if (!strncmp(args[1], "rdp-cookie", 10)) {
3460 curproxy->options2 |= PR_O2_RDPC_PRST;
3461
Emeric Brunb982a3d2010-01-04 15:45:53 +01003462 if (*(args[1] + 10) == '(') { /* cookie name */
Emeric Brun647caf12009-06-30 17:57:00 +02003463 const char *beg, *end;
3464
3465 beg = args[1] + 11;
3466 end = strchr(beg, ')');
3467
William Lallemanddf1425a2015-04-28 20:17:49 +02003468 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3469 goto out;
3470
Emeric Brun647caf12009-06-30 17:57:00 +02003471 if (!end || end == beg) {
3472 Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3473 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003474 err_code |= ERR_ALERT | ERR_FATAL;
3475 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003476 }
3477
3478 free(curproxy->rdp_cookie_name);
3479 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
3480 curproxy->rdp_cookie_len = end-beg;
3481 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003482 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
Emeric Brun647caf12009-06-30 17:57:00 +02003483 free(curproxy->rdp_cookie_name);
3484 curproxy->rdp_cookie_name = strdup("msts");
3485 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
3486 }
3487 else { /* syntax */
3488 Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3489 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003490 err_code |= ERR_ALERT | ERR_FATAL;
3491 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003492 }
3493 }
3494 else {
3495 Alert("parsing [%s:%d] : unknown persist method.\n",
3496 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003497 err_code |= ERR_ALERT | ERR_FATAL;
3498 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003499 }
3500 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003501 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Willy Tarreau6db62c52015-08-10 19:04:29 +02003502 Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]);
3503 err_code |= ERR_ALERT | ERR_FATAL;
3504 goto out;
3505 }
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003506 else if (!strcmp(args[0], "load-server-state-from-file")) {
3507 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3508 err_code |= ERR_WARN;
3509 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
3510 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
3511 }
3512 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
3513 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
3514 }
3515 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
3516 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3517 }
3518 else {
3519 Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
3520 file, linenum, args[0], args[1]);
3521 err_code |= ERR_ALERT | ERR_FATAL;
3522 goto out;
3523 }
3524 }
3525 else if (!strcmp(args[0], "server-state-file-name")) {
3526 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3527 err_code |= ERR_WARN;
3528 if (*(args[1]) == 0) {
3529 Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
3530 file, linenum, args[0]);
3531 err_code |= ERR_ALERT | ERR_FATAL;
3532 goto out;
3533 }
3534 else if (!strcmp(args[1], "use-backend-name"))
3535 curproxy->server_state_file_name = strdup(curproxy->id);
3536 else
3537 curproxy->server_state_file_name = strdup(args[1]);
3538 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003539 else if (!strcmp(args[0], "capture")) {
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02003540 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003541 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003542
Willy Tarreaubaaee002006-06-26 02:48:02 +02003543 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
Cyril Bonté99ed3272010-01-24 23:29:44 +01003544 if (curproxy == &defproxy) {
3545 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
3546 err_code |= ERR_ALERT | ERR_FATAL;
3547 goto out;
3548 }
3549
William Lallemand1a748ae2015-05-19 16:37:23 +02003550 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3551 goto out;
3552
Willy Tarreaubaaee002006-06-26 02:48:02 +02003553 if (*(args[4]) == 0) {
3554 Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
3555 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003556 err_code |= ERR_ALERT | ERR_FATAL;
3557 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003558 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003559 free(curproxy->capture_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003560 curproxy->capture_name = strdup(args[2]);
3561 curproxy->capture_namelen = strlen(curproxy->capture_name);
3562 curproxy->capture_len = atol(args[4]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003563 curproxy->to_log |= LW_COOKIE;
3564 }
3565 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
3566 struct cap_hdr *hdr;
3567
3568 if (curproxy == &defproxy) {
3569 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003570 err_code |= ERR_ALERT | ERR_FATAL;
3571 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003572 }
3573
William Lallemand1a748ae2015-05-19 16:37:23 +02003574 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3575 goto out;
3576
Willy Tarreaubaaee002006-06-26 02:48:02 +02003577 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
3578 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3579 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003580 err_code |= ERR_ALERT | ERR_FATAL;
3581 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003582 }
3583
Vincent Bernat02779b62016-04-03 13:48:43 +02003584 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003585 hdr->next = curproxy->req_cap;
3586 hdr->name = strdup(args[3]);
3587 hdr->namelen = strlen(args[3]);
3588 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003589 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003590 hdr->index = curproxy->nb_req_cap++;
3591 curproxy->req_cap = hdr;
3592 curproxy->to_log |= LW_REQHDR;
3593 }
3594 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
3595 struct cap_hdr *hdr;
3596
3597 if (curproxy == &defproxy) {
3598 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003599 err_code |= ERR_ALERT | ERR_FATAL;
3600 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003601 }
3602
William Lallemand1a748ae2015-05-19 16:37:23 +02003603 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3604 goto out;
3605
Willy Tarreaubaaee002006-06-26 02:48:02 +02003606 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
3607 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3608 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003609 err_code |= ERR_ALERT | ERR_FATAL;
3610 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003611 }
Vincent Bernat02779b62016-04-03 13:48:43 +02003612 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003613 hdr->next = curproxy->rsp_cap;
3614 hdr->name = strdup(args[3]);
3615 hdr->namelen = strlen(args[3]);
3616 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003617 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003618 hdr->index = curproxy->nb_rsp_cap++;
3619 curproxy->rsp_cap = hdr;
3620 curproxy->to_log |= LW_RSPHDR;
3621 }
3622 else {
3623 Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
3624 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003625 err_code |= ERR_ALERT | ERR_FATAL;
3626 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003627 }
3628 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003629 else if (!strcmp(args[0], "retries")) { /* connection retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +01003630 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003631 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003632
William Lallemanddf1425a2015-04-28 20:17:49 +02003633 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3634 goto out;
3635
Willy Tarreaubaaee002006-06-26 02:48:02 +02003636 if (*(args[1]) == 0) {
3637 Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
3638 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003639 err_code |= ERR_ALERT | ERR_FATAL;
3640 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003641 }
3642 curproxy->conn_retries = atol(args[1]);
3643 }
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003644 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003645 struct act_rule *rule;
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003646
3647 if (curproxy == &defproxy) {
3648 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3649 err_code |= ERR_ALERT | ERR_FATAL;
3650 goto out;
3651 }
3652
Willy Tarreau20b0de52012-12-24 15:45:22 +01003653 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003654 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003655 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3656 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY ||
3657 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR ||
3658 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REQ_AUTH)) {
Willy Tarreau20b0de52012-12-24 15:45:22 +01003659 Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003660 file, linenum, args[0]);
3661 err_code |= ERR_WARN;
3662 }
3663
Willy Tarreauff011f22011-01-06 17:51:27 +01003664 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003665
Willy Tarreauff011f22011-01-06 17:51:27 +01003666 if (!rule) {
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003667 err_code |= ERR_ALERT | ERR_ABORT;
3668 goto out;
3669 }
3670
Willy Tarreau5002f572014-04-23 01:32:02 +02003671 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003672 err_code |= warnif_cond_conflicts(rule->cond,
3673 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3674 file, linenum);
3675
Willy Tarreauff011f22011-01-06 17:51:27 +01003676 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003677 }
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003678 else if (!strcmp(args[0], "http-response")) { /* response access control */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003679 struct act_rule *rule;
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003680
3681 if (curproxy == &defproxy) {
3682 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3683 err_code |= ERR_ALERT | ERR_FATAL;
3684 goto out;
3685 }
3686
3687 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003688 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003689 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3690 LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_DENY)) {
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003691 Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
3692 file, linenum, args[0]);
3693 err_code |= ERR_WARN;
3694 }
3695
3696 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
3697
3698 if (!rule) {
3699 err_code |= ERR_ALERT | ERR_ABORT;
3700 goto out;
3701 }
3702
3703 err_code |= warnif_cond_conflicts(rule->cond,
3704 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
3705 file, linenum);
3706
3707 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
3708 }
Mark Lamourinec2247f02012-01-04 13:02:01 -05003709 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
3710 /* set the header name and length into the proxy structure */
3711 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3712 err_code |= ERR_WARN;
3713
3714 if (!*args[1]) {
3715 Alert("parsing [%s:%d] : '%s' requires a header string.\n",
3716 file, linenum, args[0]);
3717 err_code |= ERR_ALERT | ERR_FATAL;
3718 goto out;
3719 }
3720
3721 /* set the desired header name */
3722 free(curproxy->server_id_hdr_name);
3723 curproxy->server_id_hdr_name = strdup(args[1]);
3724 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
3725 }
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003726 else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003727 struct act_rule *rule;
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003728
Willy Tarreaub099aca2008-10-12 17:26:37 +02003729 if (curproxy == &defproxy) {
3730 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003731 err_code |= ERR_ALERT | ERR_FATAL;
3732 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003733 }
3734
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003735 /* emulate "block" using "http-request block". Since these rules are supposed to
3736 * be processed before all http-request rules, we put them into their own list
3737 * and will insert them at the end.
3738 */
3739 rule = parse_http_req_cond((const char **)args, file, linenum, curproxy);
3740 if (!rule) {
3741 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau93893792009-07-23 13:19:11 +02003742 goto out;
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003743 }
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003744 err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]);
3745 err_code |= warnif_cond_conflicts(rule->cond,
3746 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3747 file, linenum);
3748 LIST_ADDQ(&curproxy->block_rules, &rule->list);
Willy Tarreaude9d2d72014-04-28 22:28:02 +02003749
3750 if (!already_warned(WARN_BLOCK_DEPRECATED))
3751 Warning("parsing [%s:%d] : The '%s' directive is now deprecated in favor of 'http-request deny' which uses the exact same syntax. The rules are translated but support might disappear in a future version.\n", file, linenum, args[0]);
3752
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003753 }
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003754 else if (!strcmp(args[0], "redirect")) {
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003755 struct redirect_rule *rule;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003756
Cyril Bonté99ed3272010-01-24 23:29:44 +01003757 if (curproxy == &defproxy) {
3758 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3759 err_code |= ERR_ALERT | ERR_FATAL;
3760 goto out;
3761 }
3762
Willy Tarreaube4653b2015-05-28 15:26:58 +02003763 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
Willy Tarreau4baae242012-12-27 12:00:31 +01003764 Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
3765 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003766 err_code |= ERR_ALERT | ERR_FATAL;
3767 goto out;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003768 }
3769
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003770 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
Willy Tarreauee445d92014-04-23 01:39:04 +02003771 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003772 err_code |= warnif_cond_conflicts(rule->cond,
3773 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3774 file, linenum);
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003775 }
Krzysztof Piotr Oledzki7b723ef2009-01-27 21:09:41 +01003776 else if (!strcmp(args[0], "use_backend")) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02003777 struct switching_rule *rule;
3778
Willy Tarreaub099aca2008-10-12 17:26:37 +02003779 if (curproxy == &defproxy) {
3780 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003781 err_code |= ERR_ALERT | ERR_FATAL;
3782 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003783 }
3784
Willy Tarreau55ea7572007-06-17 19:56:27 +02003785 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003786 err_code |= ERR_WARN;
Willy Tarreau55ea7572007-06-17 19:56:27 +02003787
3788 if (*(args[1]) == 0) {
3789 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003790 err_code |= ERR_ALERT | ERR_FATAL;
3791 goto out;
Willy Tarreau55ea7572007-06-17 19:56:27 +02003792 }
3793
Willy Tarreauf51658d2014-04-23 01:21:56 +02003794 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
3795 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
3796 Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
3797 file, linenum, errmsg);
3798 err_code |= ERR_ALERT | ERR_FATAL;
3799 goto out;
3800 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003801
Willy Tarreauf51658d2014-04-23 01:21:56 +02003802 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
Willy Tarreau55ea7572007-06-17 19:56:27 +02003803 }
Willy Tarreau4f862642017-02-28 09:34:39 +01003804 else if (*args[2]) {
3805 Alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
3806 file, linenum, args[2]);
3807 err_code |= ERR_ALERT | ERR_FATAL;
3808 goto out;
3809 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003810
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003811 rule = calloc(1, sizeof(*rule));
Thierry FOURNIER / OZON.IO5948b012016-11-24 23:58:32 +01003812 if (!rule) {
3813 Alert("Out of memory error.\n");
3814 goto out;
3815 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003816 rule->cond = cond;
3817 rule->be.name = strdup(args[1]);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01003818 rule->line = linenum;
3819 rule->file = strdup(file);
3820 if (!rule->file) {
3821 Alert("Out of memory error.\n");
3822 goto out;
3823 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003824 LIST_INIT(&rule->list);
3825 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
3826 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003827 else if (strcmp(args[0], "use-server") == 0) {
3828 struct server_rule *rule;
3829
3830 if (curproxy == &defproxy) {
3831 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3832 err_code |= ERR_ALERT | ERR_FATAL;
3833 goto out;
3834 }
3835
3836 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3837 err_code |= ERR_WARN;
3838
3839 if (*(args[1]) == 0) {
3840 Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
3841 err_code |= ERR_ALERT | ERR_FATAL;
3842 goto out;
3843 }
3844
3845 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
3846 Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
3847 file, linenum, args[0]);
3848 err_code |= ERR_ALERT | ERR_FATAL;
3849 goto out;
3850 }
3851
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003852 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
3853 Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
3854 file, linenum, errmsg);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003855 err_code |= ERR_ALERT | ERR_FATAL;
3856 goto out;
3857 }
3858
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003859 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003860
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003861 rule = calloc(1, sizeof(*rule));
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003862 rule->cond = cond;
3863 rule->srv.name = strdup(args[1]);
3864 LIST_INIT(&rule->list);
3865 LIST_ADDQ(&curproxy->server_rules, &rule->list);
3866 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
3867 }
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003868 else if ((!strcmp(args[0], "force-persist")) ||
3869 (!strcmp(args[0], "ignore-persist"))) {
3870 struct persist_rule *rule;
Willy Tarreau4de91492010-01-22 19:10:05 +01003871
3872 if (curproxy == &defproxy) {
3873 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3874 err_code |= ERR_ALERT | ERR_FATAL;
3875 goto out;
3876 }
3877
3878 if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL))
3879 err_code |= ERR_WARN;
3880
Willy Tarreauef6494c2010-01-28 17:12:36 +01003881 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
Willy Tarreau4de91492010-01-22 19:10:05 +01003882 Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
3883 file, linenum, args[0]);
3884 err_code |= ERR_ALERT | ERR_FATAL;
3885 goto out;
3886 }
3887
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003888 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
3889 Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
3890 file, linenum, args[0], errmsg);
Willy Tarreau4de91492010-01-22 19:10:05 +01003891 err_code |= ERR_ALERT | ERR_FATAL;
3892 goto out;
3893 }
3894
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003895 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
3896 * where force-persist is applied.
3897 */
3898 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
Willy Tarreau4de91492010-01-22 19:10:05 +01003899
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003900 rule = calloc(1, sizeof(*rule));
Willy Tarreau4de91492010-01-22 19:10:05 +01003901 rule->cond = cond;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003902 if (!strcmp(args[0], "force-persist")) {
3903 rule->type = PERSIST_TYPE_FORCE;
3904 } else {
3905 rule->type = PERSIST_TYPE_IGNORE;
3906 }
Willy Tarreau4de91492010-01-22 19:10:05 +01003907 LIST_INIT(&rule->list);
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003908 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
Willy Tarreau4de91492010-01-22 19:10:05 +01003909 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003910 else if (!strcmp(args[0], "stick-table")) {
3911 int myidx = 1;
Willy Tarreaue45288c2015-05-26 10:49:46 +02003912 struct proxy *other;
3913
Willy Tarreaue2dc1fa2015-05-26 12:08:07 +02003914 other = proxy_tbl_by_name(curproxy->id);
Willy Tarreaue45288c2015-05-26 10:49:46 +02003915 if (other) {
3916 Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
3917 file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line);
3918 err_code |= ERR_ALERT | ERR_FATAL;
3919 goto out;
3920 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003921
Emeric Brun32da3c42010-09-23 18:39:19 +02003922 curproxy->table.id = curproxy->id;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003923 curproxy->table.type = (unsigned int)-1;
3924 while (*args[myidx]) {
3925 const char *err;
3926
3927 if (strcmp(args[myidx], "size") == 0) {
3928 myidx++;
3929 if (!*(args[myidx])) {
3930 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3931 file, linenum, args[myidx-1]);
3932 err_code |= ERR_ALERT | ERR_FATAL;
3933 goto out;
3934 }
3935 if ((err = parse_size_err(args[myidx], &curproxy->table.size))) {
3936 Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
3937 file, linenum, *err, args[myidx-1]);
3938 err_code |= ERR_ALERT | ERR_FATAL;
3939 goto out;
3940 }
Willy Tarreau0c559312010-01-26 18:36:26 +01003941 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003942 }
Emeric Brun32da3c42010-09-23 18:39:19 +02003943 else if (strcmp(args[myidx], "peers") == 0) {
3944 myidx++;
Godbach50523162013-12-11 19:48:57 +08003945 if (!*(args[myidx])) {
Godbachff115542014-04-21 21:52:23 +08003946 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3947 file, linenum, args[myidx-1]);
3948 err_code |= ERR_ALERT | ERR_FATAL;
3949 goto out;
Godbach50523162013-12-11 19:48:57 +08003950 }
Emeric Brun32da3c42010-09-23 18:39:19 +02003951 curproxy->table.peers.name = strdup(args[myidx++]);
3952 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003953 else if (strcmp(args[myidx], "expire") == 0) {
3954 myidx++;
3955 if (!*(args[myidx])) {
3956 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3957 file, linenum, args[myidx-1]);
3958 err_code |= ERR_ALERT | ERR_FATAL;
3959 goto out;
3960 }
3961 err = parse_time_err(args[myidx], &val, TIME_UNIT_MS);
3962 if (err) {
3963 Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
3964 file, linenum, *err, args[myidx-1]);
3965 err_code |= ERR_ALERT | ERR_FATAL;
3966 goto out;
3967 }
Ben Cabot3b90f0a2016-01-20 09:44:39 +00003968 if (val > INT_MAX) {
3969 Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n",
3970 file, linenum, val);
3971 err_code |= ERR_ALERT | ERR_FATAL;
3972 goto out;
3973 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003974 curproxy->table.expire = val;
Willy Tarreau0c559312010-01-26 18:36:26 +01003975 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003976 }
3977 else if (strcmp(args[myidx], "nopurge") == 0) {
3978 curproxy->table.nopurge = 1;
Willy Tarreau0c559312010-01-26 18:36:26 +01003979 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003980 }
3981 else if (strcmp(args[myidx], "type") == 0) {
3982 myidx++;
3983 if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) {
3984 Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n",
3985 file, linenum, args[myidx]);
3986 err_code |= ERR_ALERT | ERR_FATAL;
3987 goto out;
3988 }
Willy Tarreau0c559312010-01-26 18:36:26 +01003989 /* myidx already points to next arg */
3990 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02003991 else if (strcmp(args[myidx], "store") == 0) {
Willy Tarreauac782882010-06-20 10:41:54 +02003992 int type, err;
Willy Tarreau888617d2010-06-20 09:11:39 +02003993 char *cw, *nw, *sa;
Willy Tarreau08d5f982010-06-06 13:34:54 +02003994
3995 myidx++;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02003996 nw = args[myidx];
3997 while (*nw) {
3998 /* the "store" keyword supports a comma-separated list */
3999 cw = nw;
Willy Tarreau888617d2010-06-20 09:11:39 +02004000 sa = NULL; /* store arg */
4001 while (*nw && *nw != ',') {
4002 if (*nw == '(') {
4003 *nw = 0;
4004 sa = ++nw;
4005 while (*nw != ')') {
4006 if (!*nw) {
4007 Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n",
4008 file, linenum, args[0], cw);
4009 err_code |= ERR_ALERT | ERR_FATAL;
4010 goto out;
4011 }
4012 nw++;
4013 }
4014 *nw = '\0';
4015 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004016 nw++;
Willy Tarreau888617d2010-06-20 09:11:39 +02004017 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004018 if (*nw)
4019 *nw++ = '\0';
4020 type = stktable_get_data_type(cw);
4021 if (type < 0) {
4022 Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n",
4023 file, linenum, args[0], cw);
4024 err_code |= ERR_ALERT | ERR_FATAL;
4025 goto out;
4026 }
Willy Tarreauac782882010-06-20 10:41:54 +02004027
4028 err = stktable_alloc_data_type(&curproxy->table, type, sa);
4029 switch (err) {
4030 case PE_NONE: break;
4031 case PE_EXIST:
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004032 Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
4033 file, linenum, args[0], cw);
4034 err_code |= ERR_WARN;
Willy Tarreauac782882010-06-20 10:41:54 +02004035 break;
4036
4037 case PE_ARG_MISSING:
4038 Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
4039 file, linenum, args[0], cw);
4040 err_code |= ERR_ALERT | ERR_FATAL;
4041 goto out;
4042
4043 case PE_ARG_NOT_USED:
4044 Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
4045 file, linenum, args[0], cw);
4046 err_code |= ERR_ALERT | ERR_FATAL;
4047 goto out;
4048
4049 default:
4050 Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
4051 file, linenum, args[0], cw);
4052 err_code |= ERR_ALERT | ERR_FATAL;
4053 goto out;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004054 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02004055 }
4056 myidx++;
4057 }
Willy Tarreau0c559312010-01-26 18:36:26 +01004058 else {
4059 Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n",
4060 file, linenum, args[myidx]);
4061 err_code |= ERR_ALERT | ERR_FATAL;
4062 goto out;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004063 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004064 }
4065
4066 if (!curproxy->table.size) {
4067 Alert("parsing [%s:%d] : stick-table: missing size.\n",
4068 file, linenum);
4069 err_code |= ERR_ALERT | ERR_FATAL;
4070 goto out;
4071 }
4072
4073 if (curproxy->table.type == (unsigned int)-1) {
4074 Alert("parsing [%s:%d] : stick-table: missing type.\n",
4075 file, linenum);
4076 err_code |= ERR_ALERT | ERR_FATAL;
4077 goto out;
4078 }
4079 }
4080 else if (!strcmp(args[0], "stick")) {
Emeric Brunb982a3d2010-01-04 15:45:53 +01004081 struct sticking_rule *rule;
Willy Tarreau12785782012-04-27 21:37:17 +02004082 struct sample_expr *expr;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004083 int myidx = 0;
4084 const char *name = NULL;
4085 int flags;
4086
4087 if (curproxy == &defproxy) {
4088 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
4089 err_code |= ERR_ALERT | ERR_FATAL;
4090 goto out;
4091 }
4092
4093 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
4094 err_code |= ERR_WARN;
4095 goto out;
4096 }
4097
4098 myidx++;
4099 if ((strcmp(args[myidx], "store") == 0) ||
4100 (strcmp(args[myidx], "store-request") == 0)) {
4101 myidx++;
4102 flags = STK_IS_STORE;
4103 }
4104 else if (strcmp(args[myidx], "store-response") == 0) {
4105 myidx++;
4106 flags = STK_IS_STORE | STK_ON_RSP;
4107 }
4108 else if (strcmp(args[myidx], "match") == 0) {
4109 myidx++;
4110 flags = STK_IS_MATCH;
4111 }
4112 else if (strcmp(args[myidx], "on") == 0) {
4113 myidx++;
4114 flags = STK_IS_MATCH | STK_IS_STORE;
4115 }
4116 else {
4117 Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
4118 err_code |= ERR_ALERT | ERR_FATAL;
4119 goto out;
4120 }
4121
4122 if (*(args[myidx]) == 0) {
4123 Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
4124 err_code |= ERR_ALERT | ERR_FATAL;
4125 goto out;
4126 }
4127
Willy Tarreaua4312fa2013-04-02 16:34:32 +02004128 curproxy->conf.args.ctx = ARGC_STK;
Thierry FOURNIEReeaa9512014-02-11 14:00:19 +01004129 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004130 if (!expr) {
Willy Tarreau975c1782013-12-12 23:16:54 +01004131 Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004132 err_code |= ERR_ALERT | ERR_FATAL;
4133 goto out;
4134 }
4135
4136 if (flags & STK_ON_RSP) {
Willy Tarreau80aca902013-01-07 15:42:20 +01004137 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
4138 Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
4139 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004140 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004141 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004142 goto out;
4143 }
4144 } else {
Willy Tarreau80aca902013-01-07 15:42:20 +01004145 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
4146 Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
4147 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004148 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004149 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004150 goto out;
4151 }
4152 }
4153
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004154 /* check if we need to allocate an hdr_idx struct for HTTP parsing */
Willy Tarreau25320b22013-03-24 07:22:08 +01004155 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004156
Emeric Brunb982a3d2010-01-04 15:45:53 +01004157 if (strcmp(args[myidx], "table") == 0) {
4158 myidx++;
4159 name = args[myidx++];
4160 }
4161
Willy Tarreauef6494c2010-01-28 17:12:36 +01004162 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02004163 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
4164 Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
4165 file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004166 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004167 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004168 goto out;
4169 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004170 }
Willy Tarreauef6494c2010-01-28 17:12:36 +01004171 else if (*(args[myidx])) {
4172 Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
4173 file, linenum, args[0], args[myidx]);
4174 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004175 free(expr);
Willy Tarreauef6494c2010-01-28 17:12:36 +01004176 goto out;
4177 }
Emeric Brun97679e72010-09-23 17:56:44 +02004178 if (flags & STK_ON_RSP)
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004179 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
Emeric Brun97679e72010-09-23 17:56:44 +02004180 else
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004181 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreauf1e98b82010-01-28 17:59:39 +01004182
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004183 rule = calloc(1, sizeof(*rule));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004184 rule->cond = cond;
4185 rule->expr = expr;
4186 rule->flags = flags;
4187 rule->table.name = name ? strdup(name) : NULL;
4188 LIST_INIT(&rule->list);
4189 if (flags & STK_ON_RSP)
4190 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
4191 else
4192 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
4193 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004194 else if (!strcmp(args[0], "stats")) {
4195 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
4196 curproxy->uri_auth = NULL; /* we must detach from the default config */
4197
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004198 if (!*args[1]) {
4199 goto stats_error_parsing;
Cyril Bonté474be412010-10-12 00:14:36 +02004200 } else if (!strcmp(args[1], "admin")) {
4201 struct stats_admin_rule *rule;
4202
4203 if (curproxy == &defproxy) {
4204 Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
4205 err_code |= ERR_ALERT | ERR_FATAL;
4206 goto out;
4207 }
4208
4209 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4210 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4211 err_code |= ERR_ALERT | ERR_ABORT;
4212 goto out;
4213 }
4214
4215 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
4216 Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
4217 file, linenum, args[0], args[1]);
4218 err_code |= ERR_ALERT | ERR_FATAL;
4219 goto out;
4220 }
Willy Tarreaub7451bb2012-04-27 12:38:15 +02004221 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
4222 Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
4223 file, linenum, args[0], args[1], errmsg);
Cyril Bonté474be412010-10-12 00:14:36 +02004224 err_code |= ERR_ALERT | ERR_FATAL;
4225 goto out;
4226 }
4227
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004228 err_code |= warnif_cond_conflicts(cond,
4229 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4230 file, linenum);
Cyril Bonté474be412010-10-12 00:14:36 +02004231
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004232 rule = calloc(1, sizeof(*rule));
Cyril Bonté474be412010-10-12 00:14:36 +02004233 rule->cond = cond;
4234 LIST_INIT(&rule->list);
4235 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004236 } else if (!strcmp(args[1], "uri")) {
4237 if (*(args[2]) == 0) {
4238 Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004239 err_code |= ERR_ALERT | ERR_FATAL;
4240 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004241 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
4242 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004243 err_code |= ERR_ALERT | ERR_ABORT;
4244 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004245 }
4246 } else if (!strcmp(args[1], "realm")) {
4247 if (*(args[2]) == 0) {
4248 Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004249 err_code |= ERR_ALERT | ERR_FATAL;
4250 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004251 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
4252 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004253 err_code |= ERR_ALERT | ERR_ABORT;
4254 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004255 }
Willy Tarreaubbd42122007-07-25 07:26:38 +02004256 } else if (!strcmp(args[1], "refresh")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +01004257 unsigned interval;
4258
4259 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
4260 if (err) {
4261 Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n",
4262 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02004263 err_code |= ERR_ALERT | ERR_FATAL;
4264 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004265 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
4266 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004267 err_code |= ERR_ALERT | ERR_ABORT;
4268 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004269 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004270 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004271 struct act_rule *rule;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004272
4273 if (curproxy == &defproxy) {
4274 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
4275 err_code |= ERR_ALERT | ERR_FATAL;
4276 goto out;
4277 }
4278
4279 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4280 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4281 err_code |= ERR_ALERT | ERR_ABORT;
4282 goto out;
4283 }
4284
Willy Tarreauff011f22011-01-06 17:51:27 +01004285 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004286 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004287 Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
4288 file, linenum, args[0]);
4289 err_code |= ERR_WARN;
4290 }
4291
Willy Tarreauff011f22011-01-06 17:51:27 +01004292 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004293
Willy Tarreauff011f22011-01-06 17:51:27 +01004294 if (!rule) {
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004295 err_code |= ERR_ALERT | ERR_ABORT;
4296 goto out;
4297 }
4298
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004299 err_code |= warnif_cond_conflicts(rule->cond,
4300 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4301 file, linenum);
Willy Tarreauff011f22011-01-06 17:51:27 +01004302 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004303
Willy Tarreaubaaee002006-06-26 02:48:02 +02004304 } else if (!strcmp(args[1], "auth")) {
4305 if (*(args[2]) == 0) {
4306 Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004307 err_code |= ERR_ALERT | ERR_FATAL;
4308 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004309 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
4310 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004311 err_code |= ERR_ALERT | ERR_ABORT;
4312 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004313 }
4314 } else if (!strcmp(args[1], "scope")) {
4315 if (*(args[2]) == 0) {
4316 Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004317 err_code |= ERR_ALERT | ERR_FATAL;
4318 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004319 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
4320 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004321 err_code |= ERR_ALERT | ERR_ABORT;
4322 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004323 }
4324 } else if (!strcmp(args[1], "enable")) {
4325 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4326 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004327 err_code |= ERR_ALERT | ERR_ABORT;
4328 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004329 }
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004330 } else if (!strcmp(args[1], "hide-version")) {
4331 if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) {
4332 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004333 err_code |= ERR_ALERT | ERR_ABORT;
4334 goto out;
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004335 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004336 } else if (!strcmp(args[1], "show-legends")) {
4337 if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) {
4338 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4339 err_code |= ERR_ALERT | ERR_ABORT;
4340 goto out;
4341 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004342 } else if (!strcmp(args[1], "show-node")) {
4343
4344 if (*args[2]) {
4345 int i;
4346 char c;
4347
4348 for (i=0; args[2][i]; i++) {
4349 c = args[2][i];
Willy Tarreau88e05812010-03-03 00:16:00 +01004350 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
4351 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004352 break;
4353 }
4354
4355 if (!i || args[2][i]) {
4356 Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
4357 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
4358 file, linenum, args[0], args[1]);
4359 err_code |= ERR_ALERT | ERR_FATAL;
4360 goto out;
4361 }
4362 }
4363
4364 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
4365 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4366 err_code |= ERR_ALERT | ERR_ABORT;
4367 goto out;
4368 }
4369 } else if (!strcmp(args[1], "show-desc")) {
4370 char *desc = NULL;
4371
4372 if (*args[2]) {
4373 int i, len=0;
4374 char *d;
4375
Willy Tarreau348acfe2014-04-14 15:00:39 +02004376 for (i = 2; *args[i]; i++)
4377 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004378
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004379 desc = d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004380
Willy Tarreau348acfe2014-04-14 15:00:39 +02004381 d += snprintf(d, desc + len - d, "%s", args[2]);
4382 for (i = 3; *args[i]; i++)
4383 d += snprintf(d, desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004384 }
4385
4386 if (!*args[2] && !global.desc)
4387 Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
4388 file, linenum, args[1]);
4389 else {
4390 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
4391 free(desc);
4392 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4393 err_code |= ERR_ALERT | ERR_ABORT;
4394 goto out;
4395 }
4396 free(desc);
4397 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004398 } else {
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004399stats_error_parsing:
Cyril Bonté474be412010-10-12 00:14:36 +02004400 Alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n",
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004401 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004402 err_code |= ERR_ALERT | ERR_FATAL;
4403 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004404 }
4405 }
4406 else if (!strcmp(args[0], "option")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004407 int optnum;
4408
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004409 if (*(args[1]) == '\0') {
4410 Alert("parsing [%s:%d]: '%s' expects an option name.\n",
4411 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004412 err_code |= ERR_ALERT | ERR_FATAL;
4413 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004414 }
Willy Tarreau13943ab2006-12-31 00:24:10 +01004415
4416 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
4417 if (!strcmp(args[1], cfg_opts[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004418 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
4419 Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4420 file, linenum, cfg_opts[optnum].name);
4421 err_code |= ERR_ALERT | ERR_FATAL;
4422 goto out;
4423 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004424 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4425 goto out;
4426
Willy Tarreau93893792009-07-23 13:19:11 +02004427 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
4428 err_code |= ERR_WARN;
4429 goto out;
4430 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004431
Willy Tarreau3842f002009-06-14 11:39:52 +02004432 curproxy->no_options &= ~cfg_opts[optnum].val;
4433 curproxy->options &= ~cfg_opts[optnum].val;
4434
4435 switch (kwm) {
4436 case KWM_STD:
4437 curproxy->options |= cfg_opts[optnum].val;
4438 break;
4439 case KWM_NO:
4440 curproxy->no_options |= cfg_opts[optnum].val;
4441 break;
4442 case KWM_DEF: /* already cleared */
4443 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004444 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004445
Willy Tarreau93893792009-07-23 13:19:11 +02004446 goto out;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004447 }
4448 }
4449
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004450 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
4451 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004452 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
4453 Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4454 file, linenum, cfg_opts2[optnum].name);
4455 err_code |= ERR_ALERT | ERR_FATAL;
4456 goto out;
4457 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004458 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4459 goto out;
Willy Tarreau93893792009-07-23 13:19:11 +02004460 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
4461 err_code |= ERR_WARN;
4462 goto out;
4463 }
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004464
Willy Tarreau3842f002009-06-14 11:39:52 +02004465 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
4466 curproxy->options2 &= ~cfg_opts2[optnum].val;
4467
4468 switch (kwm) {
4469 case KWM_STD:
4470 curproxy->options2 |= cfg_opts2[optnum].val;
4471 break;
4472 case KWM_NO:
4473 curproxy->no_options2 |= cfg_opts2[optnum].val;
4474 break;
4475 case KWM_DEF: /* already cleared */
4476 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004477 }
Willy Tarreau93893792009-07-23 13:19:11 +02004478 goto out;
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004479 }
4480 }
4481
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004482 /* HTTP options override each other. They can be cancelled using
4483 * "no option xxx" which only switches to default mode if the mode
4484 * was this one (useful for cancelling options set in defaults
4485 * sections).
4486 */
4487 if (strcmp(args[1], "httpclose") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004488 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4489 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004490 if (kwm == KWM_STD) {
4491 curproxy->options &= ~PR_O_HTTP_MODE;
4492 curproxy->options |= PR_O_HTTP_PCL;
4493 goto out;
4494 }
4495 else if (kwm == KWM_NO) {
4496 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
4497 curproxy->options &= ~PR_O_HTTP_MODE;
4498 goto out;
4499 }
4500 }
4501 else if (strcmp(args[1], "forceclose") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004502 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4503 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004504 if (kwm == KWM_STD) {
4505 curproxy->options &= ~PR_O_HTTP_MODE;
4506 curproxy->options |= PR_O_HTTP_FCL;
4507 goto out;
4508 }
4509 else if (kwm == KWM_NO) {
4510 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
4511 curproxy->options &= ~PR_O_HTTP_MODE;
4512 goto out;
4513 }
4514 }
4515 else if (strcmp(args[1], "http-server-close") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004516 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4517 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004518 if (kwm == KWM_STD) {
4519 curproxy->options &= ~PR_O_HTTP_MODE;
4520 curproxy->options |= PR_O_HTTP_SCL;
4521 goto out;
4522 }
4523 else if (kwm == KWM_NO) {
4524 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
4525 curproxy->options &= ~PR_O_HTTP_MODE;
4526 goto out;
4527 }
4528 }
4529 else if (strcmp(args[1], "http-keep-alive") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004530 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4531 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004532 if (kwm == KWM_STD) {
4533 curproxy->options &= ~PR_O_HTTP_MODE;
4534 curproxy->options |= PR_O_HTTP_KAL;
4535 goto out;
4536 }
4537 else if (kwm == KWM_NO) {
4538 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
4539 curproxy->options &= ~PR_O_HTTP_MODE;
4540 goto out;
4541 }
4542 }
4543 else if (strcmp(args[1], "http-tunnel") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004544 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4545 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004546 if (kwm == KWM_STD) {
4547 curproxy->options &= ~PR_O_HTTP_MODE;
4548 curproxy->options |= PR_O_HTTP_TUN;
4549 goto out;
4550 }
4551 else if (kwm == KWM_NO) {
4552 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
4553 curproxy->options &= ~PR_O_HTTP_MODE;
4554 goto out;
4555 }
4556 }
4557
Joseph Lynch726ab712015-05-11 23:25:34 -07004558 /* Redispatch can take an integer argument that control when the
4559 * resispatch occurs. All values are relative to the retries option.
4560 * This can be cancelled using "no option xxx".
4561 */
4562 if (strcmp(args[1], "redispatch") == 0) {
4563 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
4564 err_code |= ERR_WARN;
4565 goto out;
4566 }
4567
4568 curproxy->no_options &= ~PR_O_REDISP;
4569 curproxy->options &= ~PR_O_REDISP;
4570
4571 switch (kwm) {
4572 case KWM_STD:
4573 curproxy->options |= PR_O_REDISP;
4574 curproxy->redispatch_after = -1;
4575 if(*args[2]) {
4576 curproxy->redispatch_after = atol(args[2]);
4577 }
4578 break;
4579 case KWM_NO:
4580 curproxy->no_options |= PR_O_REDISP;
4581 curproxy->redispatch_after = 0;
4582 break;
4583 case KWM_DEF: /* already cleared */
4584 break;
4585 }
4586 goto out;
4587 }
4588
Willy Tarreau3842f002009-06-14 11:39:52 +02004589 if (kwm != KWM_STD) {
4590 Alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004591 file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004592 err_code |= ERR_ALERT | ERR_FATAL;
4593 goto out;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004594 }
4595
Emeric Brun3a058f32009-06-30 18:26:00 +02004596 if (!strcmp(args[1], "httplog")) {
William Lallemand723b73a2012-02-08 16:37:49 +01004597 char *logformat;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004598 /* generate a complete HTTP log */
William Lallemand723b73a2012-02-08 16:37:49 +01004599 logformat = default_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004600 if (*(args[2]) != '\0') {
4601 if (!strcmp(args[2], "clf")) {
4602 curproxy->options2 |= PR_O2_CLFLOG;
William Lallemand723b73a2012-02-08 16:37:49 +01004603 logformat = clf_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004604 } else {
William Lallemand77063bc2015-05-28 18:02:48 +02004605 Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004606 err_code |= ERR_ALERT | ERR_FATAL;
4607 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004608 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004609 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
4610 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004611 }
Willy Tarreau62a61232013-04-12 18:13:46 +02004612 if (curproxy->conf.logformat_string != default_http_log_format &&
4613 curproxy->conf.logformat_string != default_tcp_log_format &&
4614 curproxy->conf.logformat_string != clf_http_log_format)
4615 free(curproxy->conf.logformat_string);
4616 curproxy->conf.logformat_string = logformat;
4617
4618 free(curproxy->conf.lfs_file);
4619 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4620 curproxy->conf.lfs_line = curproxy->conf.args.line;
Emeric Brun3a058f32009-06-30 18:26:00 +02004621 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004622 else if (!strcmp(args[1], "tcplog")) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02004623 /* generate a detailed TCP log */
Willy Tarreau62a61232013-04-12 18:13:46 +02004624 if (curproxy->conf.logformat_string != default_http_log_format &&
4625 curproxy->conf.logformat_string != default_tcp_log_format &&
4626 curproxy->conf.logformat_string != clf_http_log_format)
4627 free(curproxy->conf.logformat_string);
4628 curproxy->conf.logformat_string = default_tcp_log_format;
4629
4630 free(curproxy->conf.lfs_file);
4631 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4632 curproxy->conf.lfs_line = curproxy->conf.args.line;
William Lallemanddf1425a2015-04-28 20:17:49 +02004633
4634 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4635 goto out;
William Lallemandbddd4fd2012-02-27 11:23:10 +01004636 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004637 else if (!strcmp(args[1], "tcpka")) {
Willy Tarreau87b09662015-04-03 00:22:06 +02004638 /* enable TCP keep-alives on client and server streams */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004639 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004640 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004641
William Lallemanddf1425a2015-04-28 20:17:49 +02004642 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4643 goto out;
4644
Willy Tarreau13943ab2006-12-31 00:24:10 +01004645 if (curproxy->cap & PR_CAP_FE)
4646 curproxy->options |= PR_O_TCP_CLI_KA;
4647 if (curproxy->cap & PR_CAP_BE)
4648 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004649 }
4650 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004651 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004652 err_code |= ERR_WARN;
4653
Willy Tarreaubaaee002006-06-26 02:48:02 +02004654 /* use HTTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004655 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004656 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004657 curproxy->options2 &= ~PR_O2_CHK_ANY;
4658 curproxy->options2 |= PR_O2_HTTP_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004659 if (!*args[2]) { /* no argument */
4660 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
4661 curproxy->check_len = strlen(DEF_CHECK_REQ);
4662 } else if (!*args[3]) { /* one argument : URI */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004663 int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004664 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004665 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004666 "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
Willy Tarreaubaaee002006-06-26 02:48:02 +02004667 } else { /* more arguments : METHOD URI [HTTP_VER] */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004668 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004669 if (*args[4])
4670 reqlen += strlen(args[4]);
4671 else
4672 reqlen += strlen("HTTP/1.0");
4673
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004674 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004675 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004676 "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004677 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004678 if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
4679 goto out;
Willy Tarreauf3c69202006-07-09 16:42:34 +02004680 }
4681 else if (!strcmp(args[1], "ssl-hello-chk")) {
4682 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004683 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004684 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004685
Willy Tarreaua534fea2008-08-03 12:19:50 +02004686 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004687 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004688 curproxy->options2 &= ~PR_O2_CHK_ANY;
Willy Tarreau07a54902010-03-29 18:33:29 +02004689 curproxy->options2 |= PR_O2_SSL3_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004690
4691 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4692 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004693 }
Willy Tarreau23677902007-05-08 23:50:35 +02004694 else if (!strcmp(args[1], "smtpchk")) {
4695 /* use SMTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004696 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004697 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004698 curproxy->options2 &= ~PR_O2_CHK_ANY;
4699 curproxy->options2 |= PR_O2_SMTP_CHK;
Willy Tarreau23677902007-05-08 23:50:35 +02004700
4701 if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */
4702 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4703 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4704 } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */
4705 if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) {
4706 int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004707 curproxy->check_req = malloc(reqlen);
Willy Tarreau23677902007-05-08 23:50:35 +02004708 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
4709 "%s %s\r\n", args[2], args[3]); /* HELO hostname */
4710 } else {
4711 /* this just hits the default for now, but you could potentially expand it to allow for other stuff
4712 though, it's unlikely you'd want to send anything other than an EHLO or HELO */
4713 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4714 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4715 }
4716 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004717 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4718 goto out;
Willy Tarreau23677902007-05-08 23:50:35 +02004719 }
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004720 else if (!strcmp(args[1], "pgsql-check")) {
4721 /* use PostgreSQL request to check servers' health */
4722 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4723 err_code |= ERR_WARN;
4724
4725 free(curproxy->check_req);
4726 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004727 curproxy->options2 &= ~PR_O2_CHK_ANY;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004728 curproxy->options2 |= PR_O2_PGSQL_CHK;
4729
4730 if (*(args[2])) {
4731 int cur_arg = 2;
4732
4733 while (*(args[cur_arg])) {
4734 if (strcmp(args[cur_arg], "user") == 0) {
4735 char * packet;
4736 uint32_t packet_len;
4737 uint32_t pv;
4738
4739 /* suboption header - needs additional argument for it */
4740 if (*(args[cur_arg+1]) == 0) {
4741 Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
4742 file, linenum, args[0], args[1], args[cur_arg]);
4743 err_code |= ERR_ALERT | ERR_FATAL;
4744 goto out;
4745 }
4746
4747 /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */
4748 packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1;
4749 pv = htonl(0x30000); /* protocol version 3.0 */
4750
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004751 packet = calloc(1, packet_len);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004752
4753 memcpy(packet + 4, &pv, 4);
4754
4755 /* copy "user" */
4756 memcpy(packet + 8, "user", 4);
4757
4758 /* copy username */
4759 memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1]));
4760
4761 free(curproxy->check_req);
4762 curproxy->check_req = packet;
4763 curproxy->check_len = packet_len;
4764
4765 packet_len = htonl(packet_len);
4766 memcpy(packet, &packet_len, 4);
4767 cur_arg += 2;
4768 } else {
4769 /* unknown suboption - catchall */
4770 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
4771 file, linenum, args[0], args[1]);
4772 err_code |= ERR_ALERT | ERR_FATAL;
4773 goto out;
4774 }
4775 } /* end while loop */
4776 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004777 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4778 goto out;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004779 }
4780
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004781 else if (!strcmp(args[1], "redis-check")) {
4782 /* use REDIS PING request to check servers' health */
4783 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4784 err_code |= ERR_WARN;
4785
4786 free(curproxy->check_req);
4787 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004788 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004789 curproxy->options2 |= PR_O2_REDIS_CHK;
4790
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004791 curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1);
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004792 memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1);
4793 curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02004794
4795 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4796 goto out;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004797 }
4798
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004799 else if (!strcmp(args[1], "mysql-check")) {
4800 /* use MYSQL request to check servers' health */
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004801 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4802 err_code |= ERR_WARN;
4803
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004804 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004805 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004806 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004807 curproxy->options2 |= PR_O2_MYSQL_CHK;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004808
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004809 /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte.
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004810 * const char mysql40_client_auth_pkt[] = {
4811 * "\x0e\x00\x00" // packet length
4812 * "\x01" // packet number
4813 * "\x00\x00" // client capabilities
4814 * "\x00\x00\x01" // max packet
4815 * "haproxy\x00" // username (null terminated string)
4816 * "\x00" // filler (always 0x00)
4817 * "\x01\x00\x00" // packet length
4818 * "\x00" // packet number
4819 * "\x01" // COM_QUIT command
4820 * };
4821 */
4822
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004823 /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic.
4824 * const char mysql41_client_auth_pkt[] = {
4825 * "\x0e\x00\x00\" // packet length
4826 * "\x01" // packet number
4827 * "\x00\x00\x00\x00" // client capabilities
4828 * "\x00\x00\x00\x01" // max packet
4829 * "\x21" // character set (UTF-8)
4830 * char[23] // All zeroes
4831 * "haproxy\x00" // username (null terminated string)
4832 * "\x00" // filler (always 0x00)
4833 * "\x01\x00\x00" // packet length
4834 * "\x00" // packet number
4835 * "\x01" // COM_QUIT command
4836 * };
4837 */
4838
4839
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004840 if (*(args[2])) {
4841 int cur_arg = 2;
4842
4843 while (*(args[cur_arg])) {
4844 if (strcmp(args[cur_arg], "user") == 0) {
4845 char *mysqluser;
4846 int packetlen, reqlen, userlen;
4847
4848 /* suboption header - needs additional argument for it */
4849 if (*(args[cur_arg+1]) == 0) {
4850 Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
4851 file, linenum, args[0], args[1], args[cur_arg]);
4852 err_code |= ERR_ALERT | ERR_FATAL;
4853 goto out;
4854 }
4855 mysqluser = args[cur_arg + 1];
4856 userlen = strlen(mysqluser);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004857
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004858 if (*(args[cur_arg+2])) {
4859 if (!strcmp(args[cur_arg+2], "post-41")) {
4860 packetlen = userlen + 7 + 27;
4861 reqlen = packetlen + 9;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004862
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004863 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004864 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004865 curproxy->check_len = reqlen;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004866
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004867 snprintf(curproxy->check_req, 4, "%c%c%c",
4868 ((unsigned char) packetlen & 0xff),
4869 ((unsigned char) (packetlen >> 8) & 0xff),
4870 ((unsigned char) (packetlen >> 16) & 0xff));
4871
4872 curproxy->check_req[3] = 1;
4873 curproxy->check_req[5] = 130;
4874 curproxy->check_req[11] = 1;
4875 curproxy->check_req[12] = 33;
4876 memcpy(&curproxy->check_req[36], mysqluser, userlen);
4877 curproxy->check_req[36 + userlen + 1 + 1] = 1;
4878 curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1;
4879 cur_arg += 3;
4880 } else {
4881 Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]);
4882 err_code |= ERR_ALERT | ERR_FATAL;
4883 goto out;
4884 }
4885 } else {
4886 packetlen = userlen + 7;
4887 reqlen = packetlen + 9;
4888
4889 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004890 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004891 curproxy->check_len = reqlen;
4892
4893 snprintf(curproxy->check_req, 4, "%c%c%c",
4894 ((unsigned char) packetlen & 0xff),
4895 ((unsigned char) (packetlen >> 8) & 0xff),
4896 ((unsigned char) (packetlen >> 16) & 0xff));
4897
4898 curproxy->check_req[3] = 1;
4899 curproxy->check_req[5] = 128;
4900 curproxy->check_req[8] = 1;
4901 memcpy(&curproxy->check_req[9], mysqluser, userlen);
4902 curproxy->check_req[9 + userlen + 1 + 1] = 1;
4903 curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1;
4904 cur_arg += 2;
4905 }
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004906 } else {
4907 /* unknown suboption - catchall */
4908 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
4909 file, linenum, args[0], args[1]);
4910 err_code |= ERR_ALERT | ERR_FATAL;
4911 goto out;
4912 }
4913 } /* end while loop */
4914 }
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004915 }
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004916 else if (!strcmp(args[1], "ldap-check")) {
4917 /* use LDAP request to check servers' health */
4918 free(curproxy->check_req);
4919 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004920 curproxy->options2 &= ~PR_O2_CHK_ANY;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004921 curproxy->options2 |= PR_O2_LDAP_CHK;
4922
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004923 curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1);
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004924 memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1);
4925 curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02004926 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4927 goto out;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004928 }
Christopher Fauletba7bc162016-11-07 21:07:38 +01004929 else if (!strcmp(args[1], "spop-check")) {
4930 if (curproxy == &defproxy) {
4931 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n",
4932 file, linenum, args[0], args[1]);
4933 err_code |= ERR_ALERT | ERR_FATAL;
4934 goto out;
4935 }
4936 if (curproxy->cap & PR_CAP_FE) {
4937 Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n",
4938 file, linenum, args[0], args[1]);
4939 err_code |= ERR_ALERT | ERR_FATAL;
4940 goto out;
4941 }
4942
4943 /* use SPOE request to check servers' health */
4944 free(curproxy->check_req);
4945 curproxy->check_req = NULL;
4946 curproxy->options2 &= ~PR_O2_CHK_ANY;
4947 curproxy->options2 |= PR_O2_SPOP_CHK;
4948
Christopher Faulet8ef75252017-02-20 22:56:03 +01004949 if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) {
Christopher Fauletba7bc162016-11-07 21:07:38 +01004950 Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum);
4951 err_code |= ERR_ALERT | ERR_FATAL;
4952 goto out;
4953 }
4954 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4955 goto out;
4956 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004957 else if (!strcmp(args[1], "tcp-check")) {
4958 /* use raw TCPCHK send/expect to check servers' health */
4959 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4960 err_code |= ERR_WARN;
4961
4962 free(curproxy->check_req);
4963 curproxy->check_req = NULL;
4964 curproxy->options2 &= ~PR_O2_CHK_ANY;
4965 curproxy->options2 |= PR_O2_TCPCHK_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004966 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4967 goto out;
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004968 }
Simon Horman98637e52014-06-20 12:30:16 +09004969 else if (!strcmp(args[1], "external-check")) {
4970 /* excute an external command to check servers' health */
4971 free(curproxy->check_req);
4972 curproxy->check_req = NULL;
4973 curproxy->options2 &= ~PR_O2_CHK_ANY;
4974 curproxy->options2 |= PR_O2_EXT_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004975 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4976 goto out;
Simon Horman98637e52014-06-20 12:30:16 +09004977 }
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004978 else if (!strcmp(args[1], "forwardfor")) {
Ross Westaf72a1d2008-08-03 10:51:45 +02004979 int cur_arg;
4980
4981 /* insert x-forwarded-for field, but not for the IP address listed as an except.
4982 * set default options (ie: bitfield, header name, etc)
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004983 */
Ross Westaf72a1d2008-08-03 10:51:45 +02004984
Willy Tarreau87cf5142011-08-19 22:57:24 +02004985 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
Ross Westaf72a1d2008-08-03 10:51:45 +02004986
4987 free(curproxy->fwdfor_hdr_name);
4988 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
4989 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
4990
4991 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
4992 cur_arg = 2;
4993 while (*(args[cur_arg])) {
4994 if (!strcmp(args[cur_arg], "except")) {
4995 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01004996 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
Ross Westaf72a1d2008-08-03 10:51:45 +02004997 Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
4998 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02004999 err_code |= ERR_ALERT | ERR_FATAL;
5000 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005001 }
5002 /* flush useless bits */
5003 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
Ross Westaf72a1d2008-08-03 10:51:45 +02005004 cur_arg += 2;
5005 } else if (!strcmp(args[cur_arg], "header")) {
5006 /* suboption header - needs additional argument for it */
5007 if (*(args[cur_arg+1]) == 0) {
5008 Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5009 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005010 err_code |= ERR_ALERT | ERR_FATAL;
5011 goto out;
Ross Westaf72a1d2008-08-03 10:51:45 +02005012 }
5013 free(curproxy->fwdfor_hdr_name);
5014 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
5015 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
5016 cur_arg += 2;
Willy Tarreau87cf5142011-08-19 22:57:24 +02005017 } else if (!strcmp(args[cur_arg], "if-none")) {
5018 curproxy->options &= ~PR_O_FF_ALWAYS;
5019 cur_arg += 1;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005020 } else {
Ross Westaf72a1d2008-08-03 10:51:45 +02005021 /* unknown suboption - catchall */
Willy Tarreau87cf5142011-08-19 22:57:24 +02005022 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
Ross Westaf72a1d2008-08-03 10:51:45 +02005023 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005024 err_code |= ERR_ALERT | ERR_FATAL;
5025 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005026 }
Ross Westaf72a1d2008-08-03 10:51:45 +02005027 } /* end while loop */
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005028 }
Maik Broemme2850cb42009-04-17 18:53:21 +02005029 else if (!strcmp(args[1], "originalto")) {
5030 int cur_arg;
5031
5032 /* insert x-original-to field, but not for the IP address listed as an except.
5033 * set default options (ie: bitfield, header name, etc)
5034 */
5035
5036 curproxy->options |= PR_O_ORGTO;
5037
5038 free(curproxy->orgto_hdr_name);
5039 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
5040 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
5041
Willy Tarreau87cf5142011-08-19 22:57:24 +02005042 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
Maik Broemme2850cb42009-04-17 18:53:21 +02005043 cur_arg = 2;
5044 while (*(args[cur_arg])) {
5045 if (!strcmp(args[cur_arg], "except")) {
5046 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005047 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) {
Maik Broemme2850cb42009-04-17 18:53:21 +02005048 Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5049 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005050 err_code |= ERR_ALERT | ERR_FATAL;
5051 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005052 }
5053 /* flush useless bits */
5054 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
5055 cur_arg += 2;
5056 } else if (!strcmp(args[cur_arg], "header")) {
5057 /* suboption header - needs additional argument for it */
5058 if (*(args[cur_arg+1]) == 0) {
5059 Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5060 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005061 err_code |= ERR_ALERT | ERR_FATAL;
5062 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005063 }
5064 free(curproxy->orgto_hdr_name);
5065 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
5066 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
5067 cur_arg += 2;
5068 } else {
5069 /* unknown suboption - catchall */
5070 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
5071 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005072 err_code |= ERR_ALERT | ERR_FATAL;
5073 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005074 }
5075 } /* end while loop */
5076 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005077 else {
5078 Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005079 err_code |= ERR_ALERT | ERR_FATAL;
5080 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005081 }
Willy Tarreau93893792009-07-23 13:19:11 +02005082 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005083 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005084 else if (!strcmp(args[0], "default_backend")) {
5085 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005086 err_code |= ERR_WARN;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005087
5088 if (*(args[1]) == 0) {
5089 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005090 err_code |= ERR_ALERT | ERR_FATAL;
5091 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005092 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02005093 free(curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005094 curproxy->defbe.name = strdup(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005095
5096 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5097 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005098 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005099 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01005100 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005101 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005102
Willy Tarreaua3c504c2014-04-28 22:37:32 +02005103 if (!already_warned(WARN_REDISPATCH_DEPRECATED))
5104 Warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n",
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01005105 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005106 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005107 /* enable reconnections to dispatch */
5108 curproxy->options |= PR_O_REDISP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005109
5110 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5111 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005112 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005113 else if (!strcmp(args[0], "http-reuse")) {
5114 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5115 err_code |= ERR_WARN;
5116
5117 if (strcmp(args[1], "never") == 0) {
5118 /* enable a graceful server shutdown on an HTTP 404 response */
5119 curproxy->options &= ~PR_O_REUSE_MASK;
5120 curproxy->options |= PR_O_REUSE_NEVR;
5121 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5122 goto out;
5123 }
Willy Tarreau161d45f2015-08-05 16:02:46 +02005124 else if (strcmp(args[1], "safe") == 0) {
5125 /* enable a graceful server shutdown on an HTTP 404 response */
5126 curproxy->options &= ~PR_O_REUSE_MASK;
5127 curproxy->options |= PR_O_REUSE_SAFE;
5128 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5129 goto out;
5130 }
Willy Tarreau449d74a2015-08-05 17:16:33 +02005131 else if (strcmp(args[1], "aggressive") == 0) {
5132 curproxy->options &= ~PR_O_REUSE_MASK;
5133 curproxy->options |= PR_O_REUSE_AGGR;
5134 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5135 goto out;
5136 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005137 else if (strcmp(args[1], "always") == 0) {
5138 /* enable a graceful server shutdown on an HTTP 404 response */
5139 curproxy->options &= ~PR_O_REUSE_MASK;
5140 curproxy->options |= PR_O_REUSE_ALWS;
5141 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5142 goto out;
5143 }
5144 else {
Willy Tarreau449d74a2015-08-05 17:16:33 +02005145 Alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005146 err_code |= ERR_ALERT | ERR_FATAL;
5147 goto out;
5148 }
5149 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005150 else if (!strcmp(args[0], "http-check")) {
5151 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005152 err_code |= ERR_WARN;
Willy Tarreau48494c02007-11-30 10:41:39 +01005153
5154 if (strcmp(args[1], "disable-on-404") == 0) {
5155 /* enable a graceful server shutdown on an HTTP 404 response */
5156 curproxy->options |= PR_O_DISABLE404;
William Lallemanddf1425a2015-04-28 20:17:49 +02005157 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5158 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005159 }
Willy Tarreauef781042010-01-27 11:53:01 +01005160 else if (strcmp(args[1], "send-state") == 0) {
5161 /* enable emission of the apparent state of a server in HTTP checks */
5162 curproxy->options2 |= PR_O2_CHK_SNDST;
William Lallemanddf1425a2015-04-28 20:17:49 +02005163 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5164 goto out;
Willy Tarreauef781042010-01-27 11:53:01 +01005165 }
Willy Tarreaubd741542010-03-16 18:46:54 +01005166 else if (strcmp(args[1], "expect") == 0) {
5167 const char *ptr_arg;
5168 int cur_arg;
5169
5170 if (curproxy->options2 & PR_O2_EXP_TYPE) {
5171 Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
5172 err_code |= ERR_ALERT | ERR_FATAL;
5173 goto out;
5174 }
5175
5176 cur_arg = 2;
5177 /* consider exclamation marks, sole or at the beginning of a word */
5178 while (*(ptr_arg = args[cur_arg])) {
5179 while (*ptr_arg == '!') {
5180 curproxy->options2 ^= PR_O2_EXP_INV;
5181 ptr_arg++;
5182 }
5183 if (*ptr_arg)
5184 break;
5185 cur_arg++;
5186 }
5187 /* now ptr_arg points to the beginning of a word past any possible
5188 * exclamation mark, and cur_arg is the argument which holds this word.
5189 */
5190 if (strcmp(ptr_arg, "status") == 0) {
5191 if (!*(args[cur_arg + 1])) {
5192 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5193 file, linenum, args[0], args[1], ptr_arg);
5194 err_code |= ERR_ALERT | ERR_FATAL;
5195 goto out;
5196 }
5197 curproxy->options2 |= PR_O2_EXP_STS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005198 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005199 curproxy->expect_str = strdup(args[cur_arg + 1]);
5200 }
5201 else if (strcmp(ptr_arg, "string") == 0) {
5202 if (!*(args[cur_arg + 1])) {
5203 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5204 file, linenum, args[0], args[1], ptr_arg);
5205 err_code |= ERR_ALERT | ERR_FATAL;
5206 goto out;
5207 }
5208 curproxy->options2 |= PR_O2_EXP_STR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005209 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005210 curproxy->expect_str = strdup(args[cur_arg + 1]);
5211 }
5212 else if (strcmp(ptr_arg, "rstatus") == 0) {
5213 if (!*(args[cur_arg + 1])) {
5214 Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5215 file, linenum, args[0], args[1], ptr_arg);
5216 err_code |= ERR_ALERT | ERR_FATAL;
5217 goto out;
5218 }
5219 curproxy->options2 |= PR_O2_EXP_RSTS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005220 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005221 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005222 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005223 free(curproxy->expect_regex);
5224 curproxy->expect_regex = NULL;
5225 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005226 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005227 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5228 error = NULL;
5229 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
5230 Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5231 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
5232 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005233 err_code |= ERR_ALERT | ERR_FATAL;
5234 goto out;
5235 }
5236 }
5237 else if (strcmp(ptr_arg, "rstring") == 0) {
5238 if (!*(args[cur_arg + 1])) {
5239 Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5240 file, linenum, args[0], args[1], ptr_arg);
5241 err_code |= ERR_ALERT | ERR_FATAL;
5242 goto out;
5243 }
5244 curproxy->options2 |= PR_O2_EXP_RSTR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005245 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005246 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005247 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005248 free(curproxy->expect_regex);
5249 curproxy->expect_regex = NULL;
5250 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005251 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005252 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5253 error = NULL;
5254 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
5255 Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5256 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
5257 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005258 err_code |= ERR_ALERT | ERR_FATAL;
5259 goto out;
5260 }
5261 }
5262 else {
5263 Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n",
5264 file, linenum, args[0], args[1], ptr_arg);
5265 err_code |= ERR_ALERT | ERR_FATAL;
5266 goto out;
5267 }
5268 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005269 else {
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005270 Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005271 err_code |= ERR_ALERT | ERR_FATAL;
5272 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005273 }
5274 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005275 else if (!strcmp(args[0], "tcp-check")) {
5276 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5277 err_code |= ERR_WARN;
5278
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005279 if (strcmp(args[1], "comment") == 0) {
5280 int cur_arg;
5281 struct tcpcheck_rule *tcpcheck;
5282
5283 cur_arg = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005284 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005285 tcpcheck->action = TCPCHK_ACT_COMMENT;
5286
5287 if (!*args[cur_arg + 1]) {
5288 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5289 file, linenum, args[cur_arg]);
5290 err_code |= ERR_ALERT | ERR_FATAL;
5291 goto out;
5292 }
5293
5294 tcpcheck->comment = strdup(args[cur_arg + 1]);
5295
5296 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
William Lallemanddf1425a2015-04-28 20:17:49 +02005297 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
5298 goto out;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005299 }
5300 else if (strcmp(args[1], "connect") == 0) {
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005301 const char *ptr_arg;
5302 int cur_arg;
5303 struct tcpcheck_rule *tcpcheck;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005304
5305 /* check if first rule is also a 'connect' action */
Willy Tarreau5581c272015-05-13 12:24:53 +02005306 tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list);
5307 while (&tcpcheck->list != &curproxy->tcpcheck_rules &&
5308 tcpcheck->action == TCPCHK_ACT_COMMENT) {
5309 tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list);
5310 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005311
Willy Tarreau5581c272015-05-13 12:24:53 +02005312 if (&tcpcheck->list != &curproxy->tcpcheck_rules
5313 && tcpcheck->action != TCPCHK_ACT_CONNECT) {
5314 Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
5315 file, linenum);
5316 err_code |= ERR_ALERT | ERR_FATAL;
5317 goto out;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005318 }
5319
5320 cur_arg = 2;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005321 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005322 tcpcheck->action = TCPCHK_ACT_CONNECT;
5323
5324 /* parsing each parameters to fill up the rule */
5325 while (*(ptr_arg = args[cur_arg])) {
5326 /* tcp port */
5327 if (strcmp(args[cur_arg], "port") == 0) {
5328 if ( (atol(args[cur_arg + 1]) > 65535) ||
5329 (atol(args[cur_arg + 1]) < 1) ){
5330 Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n",
5331 file, linenum, args[0], args[1], "port", args[cur_arg + 1]);
5332 err_code |= ERR_ALERT | ERR_FATAL;
5333 goto out;
5334 }
5335 tcpcheck->port = atol(args[cur_arg + 1]);
5336 cur_arg += 2;
5337 }
5338 /* send proxy protocol */
5339 else if (strcmp(args[cur_arg], "send-proxy") == 0) {
5340 tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY;
5341 cur_arg++;
5342 }
5343#ifdef USE_OPENSSL
5344 else if (strcmp(args[cur_arg], "ssl") == 0) {
5345 curproxy->options |= PR_O_TCPCHK_SSL;
5346 tcpcheck->conn_opts |= TCPCHK_OPT_SSL;
5347 cur_arg++;
5348 }
5349#endif /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005350 /* comment for this tcpcheck line */
5351 else if (strcmp(args[cur_arg], "comment") == 0) {
5352 if (!*args[cur_arg + 1]) {
5353 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5354 file, linenum, args[cur_arg]);
5355 err_code |= ERR_ALERT | ERR_FATAL;
5356 goto out;
5357 }
5358 tcpcheck->comment = strdup(args[cur_arg + 1]);
5359 cur_arg += 2;
5360 }
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005361 else {
5362#ifdef USE_OPENSSL
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005363 Alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n",
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005364#else /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005365 Alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or but got '%s' as argument.\n",
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005366#endif /* USE_OPENSSL */
5367 file, linenum, args[0], args[1], args[cur_arg]);
5368 err_code |= ERR_ALERT | ERR_FATAL;
5369 goto out;
5370 }
5371
5372 }
5373
5374 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5375 }
5376 else if (strcmp(args[1], "send") == 0) {
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005377 if (! *(args[2]) ) {
5378 /* SEND string expected */
5379 Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n",
5380 file, linenum, args[0], args[1], args[2]);
5381 err_code |= ERR_ALERT | ERR_FATAL;
5382 goto out;
5383 } else {
5384 struct tcpcheck_rule *tcpcheck;
5385
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005386 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005387
5388 tcpcheck->action = TCPCHK_ACT_SEND;
5389 tcpcheck->string_len = strlen(args[2]);
5390 tcpcheck->string = strdup(args[2]);
5391 tcpcheck->expect_regex = NULL;
5392
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005393 /* comment for this tcpcheck line */
5394 if (strcmp(args[3], "comment") == 0) {
5395 if (!*args[4]) {
5396 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5397 file, linenum, args[3]);
5398 err_code |= ERR_ALERT | ERR_FATAL;
5399 goto out;
5400 }
5401 tcpcheck->comment = strdup(args[4]);
5402 }
5403
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005404 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5405 }
5406 }
5407 else if (strcmp(args[1], "send-binary") == 0) {
5408 if (! *(args[2]) ) {
5409 /* SEND binary string expected */
5410 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n",
5411 file, linenum, args[0], args[1], args[2]);
5412 err_code |= ERR_ALERT | ERR_FATAL;
5413 goto out;
5414 } else {
5415 struct tcpcheck_rule *tcpcheck;
5416 char *err = NULL;
5417
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005418 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005419
5420 tcpcheck->action = TCPCHK_ACT_SEND;
5421 if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
5422 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5423 file, linenum, args[0], args[1], args[2], err);
5424 err_code |= ERR_ALERT | ERR_FATAL;
5425 goto out;
5426 }
5427 tcpcheck->expect_regex = NULL;
5428
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005429 /* comment for this tcpcheck line */
5430 if (strcmp(args[3], "comment") == 0) {
5431 if (!*args[4]) {
5432 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5433 file, linenum, args[3]);
5434 err_code |= ERR_ALERT | ERR_FATAL;
5435 goto out;
5436 }
5437 tcpcheck->comment = strdup(args[4]);
5438 }
5439
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005440 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5441 }
5442 }
5443 else if (strcmp(args[1], "expect") == 0) {
5444 const char *ptr_arg;
5445 int cur_arg;
5446 int inverse = 0;
5447
5448 if (curproxy->options2 & PR_O2_EXP_TYPE) {
5449 Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
5450 err_code |= ERR_ALERT | ERR_FATAL;
5451 goto out;
5452 }
5453
5454 cur_arg = 2;
5455 /* consider exclamation marks, sole or at the beginning of a word */
5456 while (*(ptr_arg = args[cur_arg])) {
5457 while (*ptr_arg == '!') {
5458 inverse = !inverse;
5459 ptr_arg++;
5460 }
5461 if (*ptr_arg)
5462 break;
5463 cur_arg++;
5464 }
5465 /* now ptr_arg points to the beginning of a word past any possible
5466 * exclamation mark, and cur_arg is the argument which holds this word.
5467 */
5468 if (strcmp(ptr_arg, "binary") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005469 struct tcpcheck_rule *tcpcheck;
5470 char *err = NULL;
5471
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005472 if (!*(args[cur_arg + 1])) {
5473 Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n",
5474 file, linenum, args[0], args[1], ptr_arg);
5475 err_code |= ERR_ALERT | ERR_FATAL;
5476 goto out;
5477 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005478
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005479 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005480
5481 tcpcheck->action = TCPCHK_ACT_EXPECT;
5482 if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
5483 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5484 file, linenum, args[0], args[1], args[2], err);
5485 err_code |= ERR_ALERT | ERR_FATAL;
5486 goto out;
5487 }
5488 tcpcheck->expect_regex = NULL;
5489 tcpcheck->inverse = inverse;
5490
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005491 /* tcpcheck comment */
5492 cur_arg += 2;
5493 if (strcmp(args[cur_arg], "comment") == 0) {
5494 if (!*args[cur_arg + 1]) {
5495 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5496 file, linenum, args[cur_arg + 1]);
5497 err_code |= ERR_ALERT | ERR_FATAL;
5498 goto out;
5499 }
5500 tcpcheck->comment = strdup(args[cur_arg + 1]);
5501 }
5502
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005503 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5504 }
5505 else if (strcmp(ptr_arg, "string") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005506 struct tcpcheck_rule *tcpcheck;
5507
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005508 if (!*(args[cur_arg + 1])) {
5509 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5510 file, linenum, args[0], args[1], ptr_arg);
5511 err_code |= ERR_ALERT | ERR_FATAL;
5512 goto out;
5513 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005514
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005515 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005516
5517 tcpcheck->action = TCPCHK_ACT_EXPECT;
5518 tcpcheck->string_len = strlen(args[cur_arg + 1]);
5519 tcpcheck->string = strdup(args[cur_arg + 1]);
5520 tcpcheck->expect_regex = NULL;
5521 tcpcheck->inverse = inverse;
5522
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005523 /* tcpcheck comment */
5524 cur_arg += 2;
5525 if (strcmp(args[cur_arg], "comment") == 0) {
5526 if (!*args[cur_arg + 1]) {
5527 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5528 file, linenum, args[cur_arg + 1]);
5529 err_code |= ERR_ALERT | ERR_FATAL;
5530 goto out;
5531 }
5532 tcpcheck->comment = strdup(args[cur_arg + 1]);
5533 }
5534
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005535 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5536 }
5537 else if (strcmp(ptr_arg, "rstring") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005538 struct tcpcheck_rule *tcpcheck;
5539
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005540 if (!*(args[cur_arg + 1])) {
5541 Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5542 file, linenum, args[0], args[1], ptr_arg);
5543 err_code |= ERR_ALERT | ERR_FATAL;
5544 goto out;
5545 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005546
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005547 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005548
5549 tcpcheck->action = TCPCHK_ACT_EXPECT;
5550 tcpcheck->string_len = 0;
5551 tcpcheck->string = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005552 tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex));
5553 error = NULL;
5554 if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) {
5555 Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5556 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
5557 free(error);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005558 err_code |= ERR_ALERT | ERR_FATAL;
5559 goto out;
5560 }
5561 tcpcheck->inverse = inverse;
5562
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005563 /* tcpcheck comment */
5564 cur_arg += 2;
5565 if (strcmp(args[cur_arg], "comment") == 0) {
5566 if (!*args[cur_arg + 1]) {
5567 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5568 file, linenum, args[cur_arg + 1]);
5569 err_code |= ERR_ALERT | ERR_FATAL;
5570 goto out;
5571 }
5572 tcpcheck->comment = strdup(args[cur_arg + 1]);
5573 }
5574
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005575 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5576 }
5577 else {
5578 Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n",
5579 file, linenum, args[0], args[1], ptr_arg);
5580 err_code |= ERR_ALERT | ERR_FATAL;
5581 goto out;
5582 }
5583 }
5584 else {
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005585 Alert("parsing [%s:%d] : '%s' only supports 'comment', 'connect', 'send' or 'expect'.\n", file, linenum, args[0]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005586 err_code |= ERR_ALERT | ERR_FATAL;
5587 goto out;
5588 }
5589 }
Willy Tarreaub80c2302007-11-30 20:51:32 +01005590 else if (!strcmp(args[0], "monitor")) {
Willy Tarreaub099aca2008-10-12 17:26:37 +02005591 if (curproxy == &defproxy) {
5592 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005593 err_code |= ERR_ALERT | ERR_FATAL;
5594 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02005595 }
5596
Willy Tarreaub80c2302007-11-30 20:51:32 +01005597 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005598 err_code |= ERR_WARN;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005599
5600 if (strcmp(args[1], "fail") == 0) {
5601 /* add a condition to fail monitor requests */
Willy Tarreauef6494c2010-01-28 17:12:36 +01005602 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Willy Tarreaub80c2302007-11-30 20:51:32 +01005603 Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
5604 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005605 err_code |= ERR_ALERT | ERR_FATAL;
5606 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005607 }
5608
Willy Tarreaub7451bb2012-04-27 12:38:15 +02005609 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
5610 Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
5611 file, linenum, args[0], args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005612 err_code |= ERR_ALERT | ERR_FATAL;
5613 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005614 }
5615 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
5616 }
5617 else {
5618 Alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005619 err_code |= ERR_ALERT | ERR_FATAL;
5620 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005621 }
5622 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005623#ifdef TPROXY
5624 else if (!strcmp(args[0], "transparent")) {
5625 /* enable transparent proxy connections */
5626 curproxy->options |= PR_O_TRANSP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005627 if (alertif_too_many_args(0, file, linenum, args, &err_code))
5628 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005629 }
5630#endif
5631 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005632 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005633 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005634
Willy Tarreaubaaee002006-06-26 02:48:02 +02005635 if (*(args[1]) == 0) {
5636 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005637 err_code |= ERR_ALERT | ERR_FATAL;
5638 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005639 }
5640 curproxy->maxconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005641 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5642 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005643 }
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005644 else if (!strcmp(args[0], "backlog")) { /* backlog */
5645 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005646 err_code |= ERR_WARN;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005647
5648 if (*(args[1]) == 0) {
5649 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005650 err_code |= ERR_ALERT | ERR_FATAL;
5651 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005652 }
5653 curproxy->backlog = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005654 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5655 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005656 }
Willy Tarreau86034312006-12-29 00:10:33 +01005657 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005658 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005659 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005660
Willy Tarreau86034312006-12-29 00:10:33 +01005661 if (*(args[1]) == 0) {
5662 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005663 err_code |= ERR_ALERT | ERR_FATAL;
5664 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005665 }
5666 curproxy->fullconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005667 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5668 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005669 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005670 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
5671 if (*(args[1]) == 0) {
5672 Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005673 err_code |= ERR_ALERT | ERR_FATAL;
5674 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005675 }
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005676 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
5677 if (err) {
5678 Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
5679 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02005680 err_code |= ERR_ALERT | ERR_FATAL;
5681 goto out;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005682 }
5683 curproxy->grace = val;
William Lallemanddf1425a2015-04-28 20:17:49 +02005684 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5685 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005686 }
5687 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
David du Colombier6f5ccb12011-03-10 22:26:24 +01005688 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005689 int port1, port2;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005690 struct protocol *proto;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005691
Willy Tarreaubaaee002006-06-26 02:48:02 +02005692 if (curproxy == &defproxy) {
5693 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005694 err_code |= ERR_ALERT | ERR_FATAL;
5695 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005696 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01005697 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005698 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005699
Willy Tarreau48ef4c92017-01-06 18:32:38 +01005700 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005701 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01005702 Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005703 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005704 goto out;
5705 }
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005706
5707 proto = protocol_by_family(sk->ss_family);
5708 if (!proto || !proto->connect) {
5709 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
5710 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005711 err_code |= ERR_ALERT | ERR_FATAL;
5712 goto out;
5713 }
5714
5715 if (port1 != port2) {
5716 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
5717 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005718 err_code |= ERR_ALERT | ERR_FATAL;
5719 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005720 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005721
5722 if (!port1) {
5723 Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
5724 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01005725 err_code |= ERR_ALERT | ERR_FATAL;
5726 goto out;
5727 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005728
William Lallemanddf1425a2015-04-28 20:17:49 +02005729 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5730 goto out;
5731
Willy Tarreaud5191e72010-02-09 20:50:45 +01005732 curproxy->dispatch_addr = *sk;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005733 curproxy->options |= PR_O_DISPATCH;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005734 }
5735 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005736 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005737 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005738
Willy Tarreaua93c74b2012-05-08 18:14:39 +02005739 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
5740 Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005741 err_code |= ERR_ALERT | ERR_FATAL;
5742 goto out;
Willy Tarreau2fcb5002007-05-08 13:35:26 +02005743 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005744 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005745 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005746 /**
5747 * The syntax for hash-type config element is
5748 * hash-type {map-based|consistent} [[<algo>] avalanche]
5749 *
5750 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
5751 */
5752 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
Bhaskar98634f02013-10-29 23:30:51 -04005753
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005754 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5755 err_code |= ERR_WARN;
5756
5757 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005758 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
5759 }
5760 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005761 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
5762 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005763 else if (strcmp(args[1], "avalanche") == 0) {
5764 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]);
5765 err_code |= ERR_ALERT | ERR_FATAL;
5766 goto out;
Willy Tarreau798a39c2010-11-24 15:04:29 +01005767 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005768 else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005769 Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005770 err_code |= ERR_ALERT | ERR_FATAL;
5771 goto out;
5772 }
Bhaskar98634f02013-10-29 23:30:51 -04005773
5774 /* set the hash function to use */
5775 if (!*args[2]) {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005776 /* the default algo is sdbm */
Bhaskar98634f02013-10-29 23:30:51 -04005777 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005778
5779 /* if consistent with no argument, then avalanche modifier is also applied */
5780 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
5781 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
Bhaskar98634f02013-10-29 23:30:51 -04005782 } else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005783 /* set the hash function */
5784 if (!strcmp(args[2], "sdbm")) {
5785 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
5786 }
5787 else if (!strcmp(args[2], "djb2")) {
5788 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
Willy Tarreau324f07f2015-01-20 19:44:50 +01005789 }
5790 else if (!strcmp(args[2], "wt6")) {
Willy Tarreaua0f42712013-11-14 14:30:35 +01005791 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005792 }
Willy Tarreau324f07f2015-01-20 19:44:50 +01005793 else if (!strcmp(args[2], "crc32")) {
5794 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
5795 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005796 else {
Willy Tarreau324f07f2015-01-20 19:44:50 +01005797 Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005798 err_code |= ERR_ALERT | ERR_FATAL;
5799 goto out;
5800 }
5801
5802 /* set the hash modifier */
5803 if (!strcmp(args[3], "avalanche")) {
5804 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
5805 }
5806 else if (*args[3]) {
5807 Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
5808 err_code |= ERR_ALERT | ERR_FATAL;
5809 goto out;
5810 }
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01005811 }
William Lallemanda73203e2012-03-12 12:48:57 +01005812 }
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04005813 else if (strcmp(args[0], "hash-balance-factor") == 0) {
5814 if (*(args[1]) == 0) {
5815 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
5816 err_code |= ERR_ALERT | ERR_FATAL;
5817 goto out;
5818 }
5819 curproxy->lbprm.chash.balance_factor = atol(args[1]);
5820 if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) {
5821 Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
5822 err_code |= ERR_ALERT | ERR_FATAL;
5823 goto out;
5824 }
5825 }
William Lallemanda73203e2012-03-12 12:48:57 +01005826 else if (strcmp(args[0], "unique-id-format") == 0) {
5827 if (!*(args[1])) {
5828 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5829 err_code |= ERR_ALERT | ERR_FATAL;
5830 goto out;
5831 }
William Lallemand3203ff42012-11-11 17:30:56 +01005832 if (*(args[2])) {
5833 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5834 err_code |= ERR_ALERT | ERR_FATAL;
5835 goto out;
5836 }
Willy Tarreau62a61232013-04-12 18:13:46 +02005837 free(curproxy->conf.uniqueid_format_string);
5838 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02005839
Willy Tarreau62a61232013-04-12 18:13:46 +02005840 free(curproxy->conf.uif_file);
5841 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
5842 curproxy->conf.uif_line = curproxy->conf.args.line;
William Lallemand723b73a2012-02-08 16:37:49 +01005843 }
William Lallemanda73203e2012-03-12 12:48:57 +01005844
5845 else if (strcmp(args[0], "unique-id-header") == 0) {
5846 if (!*(args[1])) {
5847 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5848 err_code |= ERR_ALERT | ERR_FATAL;
5849 goto out;
5850 }
5851 free(curproxy->header_unique_id);
5852 curproxy->header_unique_id = strdup(args[1]);
5853 }
5854
William Lallemand723b73a2012-02-08 16:37:49 +01005855 else if (strcmp(args[0], "log-format") == 0) {
5856 if (!*(args[1])) {
5857 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5858 err_code |= ERR_ALERT | ERR_FATAL;
5859 goto out;
5860 }
William Lallemand3203ff42012-11-11 17:30:56 +01005861 if (*(args[2])) {
5862 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5863 err_code |= ERR_ALERT | ERR_FATAL;
5864 goto out;
5865 }
Willy Tarreau196729e2012-05-31 19:30:26 +02005866
Willy Tarreau62a61232013-04-12 18:13:46 +02005867 if (curproxy->conf.logformat_string != default_http_log_format &&
5868 curproxy->conf.logformat_string != default_tcp_log_format &&
5869 curproxy->conf.logformat_string != clf_http_log_format)
5870 free(curproxy->conf.logformat_string);
5871 curproxy->conf.logformat_string = strdup(args[1]);
5872
5873 free(curproxy->conf.lfs_file);
5874 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
5875 curproxy->conf.lfs_line = curproxy->conf.args.line;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02005876
5877 /* get a chance to improve log-format error reporting by
5878 * reporting the correct line-number when possible.
5879 */
5880 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
5881 Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
5882 file, linenum, curproxy->id);
5883 err_code |= ERR_WARN;
5884 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005885 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02005886 else if (!strcmp(args[0], "log-format-sd")) {
5887 if (!*(args[1])) {
5888 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5889 err_code |= ERR_ALERT | ERR_FATAL;
5890 goto out;
5891 }
5892 if (*(args[2])) {
5893 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5894 err_code |= ERR_ALERT | ERR_FATAL;
5895 goto out;
5896 }
5897
5898 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
5899 free(curproxy->conf.logformat_sd_string);
5900 curproxy->conf.logformat_sd_string = strdup(args[1]);
5901
5902 free(curproxy->conf.lfsd_file);
5903 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
5904 curproxy->conf.lfsd_line = curproxy->conf.args.line;
5905
5906 /* get a chance to improve log-format-sd error reporting by
5907 * reporting the correct line-number when possible.
5908 */
5909 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
5910 Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
5911 file, linenum, curproxy->id);
5912 err_code |= ERR_WARN;
5913 }
5914 }
Willy Tarreau094af4e2015-01-07 15:03:42 +01005915 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
5916 if (*(args[1]) == 0) {
5917 Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
5918 err_code |= ERR_ALERT | ERR_FATAL;
5919 goto out;
5920 }
Dragan Dosen43885c72015-10-01 13:18:13 +02005921 chunk_destroy(&curproxy->log_tag);
5922 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
Willy Tarreau094af4e2015-01-07 15:03:42 +01005923 }
William Lallemand0f99e342011-10-12 17:50:54 +02005924 else if (!strcmp(args[0], "log") && kwm == KWM_NO) {
5925 /* delete previous herited or defined syslog servers */
5926 struct logsrv *back;
5927
5928 if (*(args[1]) != 0) {
5929 Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]);
5930 err_code |= ERR_ALERT | ERR_FATAL;
5931 goto out;
5932 }
5933
William Lallemand723b73a2012-02-08 16:37:49 +01005934 list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) {
5935 LIST_DEL(&tmplogsrv->list);
5936 free(tmplogsrv);
William Lallemand0f99e342011-10-12 17:50:54 +02005937 }
5938 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005939 else if (!strcmp(args[0], "log")) { /* syslog server address */
William Lallemand0f99e342011-10-12 17:50:54 +02005940 struct logsrv *logsrv;
5941
Willy Tarreaubaaee002006-06-26 02:48:02 +02005942 if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
William Lallemand0f99e342011-10-12 17:50:54 +02005943 /* copy global.logrsvs linked list to the end of curproxy->logsrvs */
William Lallemand723b73a2012-02-08 16:37:49 +01005944 list_for_each_entry(tmplogsrv, &global.logsrvs, list) {
Vincent Bernat02779b62016-04-03 13:48:43 +02005945 struct logsrv *node = malloc(sizeof(*node));
William Lallemand723b73a2012-02-08 16:37:49 +01005946 memcpy(node, tmplogsrv, sizeof(struct logsrv));
William Lallemand0f99e342011-10-12 17:50:54 +02005947 LIST_INIT(&node->list);
5948 LIST_ADDQ(&curproxy->logsrvs, &node->list);
5949 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005950 }
5951 else if (*(args[1]) && *(args[2])) {
Willy Tarreau9b435bc2013-03-06 15:02:49 +01005952 struct sockaddr_storage *sk;
5953 int port1, port2;
Willy Tarreau18324f52014-06-27 18:10:07 +02005954 int arg = 0;
5955 int len = 0;
William Lallemand0f99e342011-10-12 17:50:54 +02005956
Vincent Bernat02779b62016-04-03 13:48:43 +02005957 logsrv = calloc(1, sizeof(*logsrv));
Willy Tarreaubaaee002006-06-26 02:48:02 +02005958
Willy Tarreau18324f52014-06-27 18:10:07 +02005959 /* just after the address, a length may be specified */
5960 if (strcmp(args[arg+2], "len") == 0) {
5961 len = atoi(args[arg+3]);
5962 if (len < 80 || len > 65535) {
5963 Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n",
5964 file, linenum, args[arg+3]);
5965 err_code |= ERR_ALERT | ERR_FATAL;
5966 goto out;
5967 }
5968 logsrv->maxlen = len;
5969
5970 /* skip these two args */
5971 arg += 2;
5972 }
5973 else
5974 logsrv->maxlen = MAX_SYSLOG_LEN;
5975
5976 if (logsrv->maxlen > global.max_syslog_len) {
5977 global.max_syslog_len = logsrv->maxlen;
Hubert Verstraete831962e2016-06-28 22:44:26 +02005978 logheader = my_realloc2(logheader, global.max_syslog_len + 1);
5979 logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
5980 logline = my_realloc2(logline, global.max_syslog_len + 1);
5981 logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
Willy Tarreau18324f52014-06-27 18:10:07 +02005982 }
5983
Dragan Dosen1322d092015-09-22 16:05:32 +02005984 /* after the length, a format may be specified */
5985 if (strcmp(args[arg+2], "format") == 0) {
5986 logsrv->format = get_log_format(args[arg+3]);
5987 if (logsrv->format < 0) {
5988 Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]);
5989 err_code |= ERR_ALERT | ERR_FATAL;
5990 goto out;
5991 }
5992
5993 /* skip these two args */
5994 arg += 2;
5995 }
5996
William Lallemanddf1425a2015-04-28 20:17:49 +02005997 if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code))
5998 goto out;
5999
Willy Tarreau18324f52014-06-27 18:10:07 +02006000 logsrv->facility = get_log_facility(args[arg+2]);
William Lallemand0f99e342011-10-12 17:50:54 +02006001 if (logsrv->facility < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02006002 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]);
William Lallemand0f99e342011-10-12 17:50:54 +02006003 err_code |= ERR_ALERT | ERR_FATAL;
6004 goto out;
6005
Willy Tarreaubaaee002006-06-26 02:48:02 +02006006 }
6007
William Lallemand0f99e342011-10-12 17:50:54 +02006008 logsrv->level = 7; /* max syslog level = debug */
Willy Tarreau18324f52014-06-27 18:10:07 +02006009 if (*(args[arg+3])) {
6010 logsrv->level = get_log_level(args[arg+3]);
William Lallemand0f99e342011-10-12 17:50:54 +02006011 if (logsrv->level < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02006012 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]);
William Lallemand0f99e342011-10-12 17:50:54 +02006013 err_code |= ERR_ALERT | ERR_FATAL;
6014 goto out;
6015
Willy Tarreaubaaee002006-06-26 02:48:02 +02006016 }
6017 }
6018
William Lallemand0f99e342011-10-12 17:50:54 +02006019 logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */
Willy Tarreau18324f52014-06-27 18:10:07 +02006020 if (*(args[arg+4])) {
6021 logsrv->minlvl = get_log_level(args[arg+4]);
Willy Tarreauf7f057b2013-01-24 00:31:24 +01006022 if (logsrv->minlvl < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02006023 Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]);
William Lallemand0f99e342011-10-12 17:50:54 +02006024 err_code |= ERR_ALERT | ERR_FATAL;
6025 goto out;
6026
Willy Tarreauf7edefa2009-05-10 17:20:05 +02006027 }
6028 }
6029
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006030 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006031 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01006032 Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006033 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006034 goto out;
6035 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006036
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006037 logsrv->addr = *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006038
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006039 if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006040 if (port1 != port2) {
6041 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6042 file, linenum, args[0], args[1]);
6043 err_code |= ERR_ALERT | ERR_FATAL;
6044 goto out;
6045 }
6046
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006047 if (!port1)
William Lallemand0f99e342011-10-12 17:50:54 +02006048 set_host_port(&logsrv->addr, SYSLOG_PORT);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006049 }
William Lallemand0f99e342011-10-12 17:50:54 +02006050
6051 LIST_ADDQ(&curproxy->logsrvs, &logsrv->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006052 }
6053 else {
6054 Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n",
6055 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02006056 err_code |= ERR_ALERT | ERR_FATAL;
6057 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006058 }
6059 }
6060 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006061 int cur_arg;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006062 int port1, port2;
David du Colombier6f5ccb12011-03-10 22:26:24 +01006063 struct sockaddr_storage *sk;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006064 struct protocol *proto;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006065
Willy Tarreau977b8e42006-12-29 14:19:17 +01006066 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006067 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006068
Willy Tarreaubaaee002006-06-26 02:48:02 +02006069 if (!*args[1]) {
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006070 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
6071 file, linenum, "source", "usesrc", "interface");
Willy Tarreau93893792009-07-23 13:19:11 +02006072 err_code |= ERR_ALERT | ERR_FATAL;
6073 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006074 }
Willy Tarreau368480c2009-03-01 08:27:21 +01006075
6076 /* we must first clear any optional default setting */
Willy Tarreauef9a3602012-12-08 22:29:20 +01006077 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6078 free(curproxy->conn_src.iface_name);
6079 curproxy->conn_src.iface_name = NULL;
6080 curproxy->conn_src.iface_len = 0;
Willy Tarreau368480c2009-03-01 08:27:21 +01006081
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006082 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006083 if (!sk) {
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006084 Alert("parsing [%s:%d] : '%s %s' : %s\n",
Willy Tarreau902636f2013-03-10 19:44:48 +01006085 file, linenum, args[0], args[1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006086 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006087 goto out;
6088 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006089
6090 proto = protocol_by_family(sk->ss_family);
6091 if (!proto || !proto->connect) {
6092 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006093 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006094 err_code |= ERR_ALERT | ERR_FATAL;
6095 goto out;
6096 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006097
6098 if (port1 != port2) {
6099 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6100 file, linenum, args[0], args[1]);
6101 err_code |= ERR_ALERT | ERR_FATAL;
6102 goto out;
6103 }
6104
Willy Tarreauef9a3602012-12-08 22:29:20 +01006105 curproxy->conn_src.source_addr = *sk;
6106 curproxy->conn_src.opts |= CO_SRC_BIND;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006107
6108 cur_arg = 2;
6109 while (*(args[cur_arg])) {
6110 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau29fbe512015-08-20 19:35:14 +02006111#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006112 if (!*args[cur_arg + 1]) {
6113 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
6114 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006115 err_code |= ERR_ALERT | ERR_FATAL;
6116 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006117 }
6118
6119 if (!strcmp(args[cur_arg + 1], "client")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006120 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6121 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006122 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006123 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6124 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
Willy Tarreaubce70882009-09-07 11:51:47 +02006125 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
6126 char *name, *end;
6127
6128 name = args[cur_arg+1] + 7;
6129 while (isspace(*name))
6130 name++;
6131
6132 end = name;
6133 while (*end && !isspace(*end) && *end != ',' && *end != ')')
6134 end++;
6135
Willy Tarreauef9a3602012-12-08 22:29:20 +01006136 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6137 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
6138 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
6139 curproxy->conn_src.bind_hdr_len = end - name;
6140 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
6141 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
6142 curproxy->conn_src.bind_hdr_occ = -1;
Willy Tarreaubce70882009-09-07 11:51:47 +02006143
6144 /* now look for an occurrence number */
6145 while (isspace(*end))
6146 end++;
6147 if (*end == ',') {
6148 end++;
6149 name = end;
6150 if (*end == '-')
6151 end++;
Willy Tarreau83d84cf2012-11-22 01:04:31 +01006152 while (isdigit((int)*end))
Willy Tarreaubce70882009-09-07 11:51:47 +02006153 end++;
Willy Tarreauef9a3602012-12-08 22:29:20 +01006154 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
Willy Tarreaubce70882009-09-07 11:51:47 +02006155 }
6156
Willy Tarreauef9a3602012-12-08 22:29:20 +01006157 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
Willy Tarreaubce70882009-09-07 11:51:47 +02006158 Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
6159 " occurrences values smaller than %d.\n",
6160 file, linenum, MAX_HDR_HISTORY);
6161 err_code |= ERR_ALERT | ERR_FATAL;
6162 goto out;
6163 }
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006164 } else {
Willy Tarreau902636f2013-03-10 19:44:48 +01006165 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006166
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006167 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006168 if (!sk) {
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006169 Alert("parsing [%s:%d] : '%s %s' : %s\n",
Willy Tarreau902636f2013-03-10 19:44:48 +01006170 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006171 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006172 goto out;
6173 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006174
6175 proto = protocol_by_family(sk->ss_family);
6176 if (!proto || !proto->connect) {
6177 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6178 file, linenum, args[cur_arg], args[cur_arg+1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006179 err_code |= ERR_ALERT | ERR_FATAL;
6180 goto out;
6181 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006182
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006183 if (port1 != port2) {
6184 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6185 file, linenum, args[cur_arg], args[cur_arg + 1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006186 err_code |= ERR_ALERT | ERR_FATAL;
6187 goto out;
6188 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006189 curproxy->conn_src.tproxy_addr = *sk;
6190 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006191 }
6192 global.last_checks |= LSTCHK_NETADM;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006193#else /* no TPROXY support */
6194 Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
Willy Tarreau77074d52006-11-12 23:57:19 +01006195 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006196 err_code |= ERR_ALERT | ERR_FATAL;
6197 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006198#endif
6199 cur_arg += 2;
6200 continue;
Willy Tarreau77074d52006-11-12 23:57:19 +01006201 }
6202
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006203 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
6204#ifdef SO_BINDTODEVICE
6205 if (!*args[cur_arg + 1]) {
6206 Alert("parsing [%s:%d] : '%s' : missing interface name.\n",
6207 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006208 err_code |= ERR_ALERT | ERR_FATAL;
6209 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006210 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006211 free(curproxy->conn_src.iface_name);
6212 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
6213 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006214 global.last_checks |= LSTCHK_NETADM;
6215#else
6216 Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
6217 file, linenum, args[0], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02006218 err_code |= ERR_ALERT | ERR_FATAL;
6219 goto out;
Willy Tarreau5b6995c2008-01-13 16:31:17 +01006220#endif
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006221 cur_arg += 2;
6222 continue;
6223 }
6224 Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
Willy Tarreau3631d412012-09-25 16:31:00 +02006225 file, linenum, args[0], "interface", "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006226 err_code |= ERR_ALERT | ERR_FATAL;
6227 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006228 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006229 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006230 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
6231 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
6232 file, linenum, "usesrc", "source");
Willy Tarreau93893792009-07-23 13:19:11 +02006233 err_code |= ERR_ALERT | ERR_FATAL;
6234 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006235 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006236 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006237 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006238 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6239 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006240 err_code |= ERR_ALERT | ERR_FATAL;
6241 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006242 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006243
6244 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006245 SMP_OPT_DIR_REQ, ACT_REPLACE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006246 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006247 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006248 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006249 }
6250 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006251 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006252 SMP_OPT_DIR_REQ, ACT_REMOVE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006253 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006254 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006255 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006256 }
6257 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006258 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006259 SMP_OPT_DIR_REQ, ACT_DENY, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006260 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006261 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006262 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006263 }
6264 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006265 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006266 SMP_OPT_DIR_REQ, ACT_PASS, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006267 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006268 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006269 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006270 }
6271 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006272 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006273 SMP_OPT_DIR_REQ, ACT_ALLOW, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006274 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006275 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006276 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006277 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006278 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006279 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006280 SMP_OPT_DIR_REQ, ACT_TARPIT, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006281 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006282 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006283 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006284 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006285 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006286 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006287 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6288 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006289 err_code |= ERR_ALERT | ERR_FATAL;
6290 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006291 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006292
6293 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006294 SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006295 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006296 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006297 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006298 }
6299 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006300 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006301 SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006302 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006303 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006304 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006305 }
6306 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006307 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006308 SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006309 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006310 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006311 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006312 }
6313 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006314 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006315 SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006316 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006317 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006318 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006319 }
6320 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006321 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006322 SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006323 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006324 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006325 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006326 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006327 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006328 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006329 SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006330 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006331 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006332 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006333 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006334 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006335 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006336
Willy Tarreaubaaee002006-06-26 02:48:02 +02006337 if (curproxy == &defproxy) {
6338 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006339 err_code |= ERR_ALERT | ERR_FATAL;
6340 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006341 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006342 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006343 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006344
Willy Tarreaubaaee002006-06-26 02:48:02 +02006345 if (*(args[1]) == 0) {
6346 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006347 err_code |= ERR_ALERT | ERR_FATAL;
6348 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006349 }
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006350
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006351 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02006352 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) {
6353 Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6354 file, linenum, args[0], errmsg);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006355 err_code |= ERR_ALERT | ERR_FATAL;
6356 goto out;
6357 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006358 err_code |= warnif_cond_conflicts(cond,
6359 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
6360 file, linenum);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006361 }
6362 else if (*args[2]) {
6363 Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6364 file, linenum, args[0], args[2]);
6365 err_code |= ERR_ALERT | ERR_FATAL;
6366 goto out;
6367 }
6368
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006369 wl = calloc(1, sizeof(*wl));
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006370 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006371 wl->s = strdup(args[1]);
6372 LIST_ADDQ(&curproxy->req_add, &wl->list);
Willy Tarreau61d18892009-03-31 10:49:21 +02006373 warnif_misplaced_reqadd(curproxy, file, linenum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006374 }
6375 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006376 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006377 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6378 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006379 err_code |= ERR_ALERT | ERR_FATAL;
6380 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006381 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01006382
Willy Tarreauade5ec42010-01-28 19:33:49 +01006383 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006384 SMP_OPT_DIR_RES, ACT_REPLACE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006385 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006386 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006387 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006388 }
6389 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006390 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006391 SMP_OPT_DIR_RES, ACT_REMOVE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006392 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006393 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006394 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006395 }
6396 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006397 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006398 SMP_OPT_DIR_RES, ACT_DENY, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006399 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006400 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006401 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006402 }
6403 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006404 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006405 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6406 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006407 err_code |= ERR_ALERT | ERR_FATAL;
6408 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006409 }
6410
Willy Tarreauade5ec42010-01-28 19:33:49 +01006411 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006412 SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006413 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006414 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006415 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006416 }
6417 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006418 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006419 SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006420 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006421 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006422 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006423 }
6424 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006425 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006426 SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006427 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006428 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006429 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006430 }
6431 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006432 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006433
Willy Tarreaubaaee002006-06-26 02:48:02 +02006434 if (curproxy == &defproxy) {
6435 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006436 err_code |= ERR_ALERT | ERR_FATAL;
6437 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006438 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006439 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006440 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006441
Willy Tarreaubaaee002006-06-26 02:48:02 +02006442 if (*(args[1]) == 0) {
6443 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006444 err_code |= ERR_ALERT | ERR_FATAL;
6445 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006446 }
6447
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006448 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02006449 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) {
6450 Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6451 file, linenum, args[0], errmsg);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006452 err_code |= ERR_ALERT | ERR_FATAL;
6453 goto out;
6454 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006455 err_code |= warnif_cond_conflicts(cond,
6456 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
6457 file, linenum);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006458 }
6459 else if (*args[2]) {
6460 Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6461 file, linenum, args[0], args[2]);
6462 err_code |= ERR_ALERT | ERR_FATAL;
6463 goto out;
6464 }
6465
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006466 wl = calloc(1, sizeof(*wl));
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006467 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006468 wl->s = strdup(args[1]);
6469 LIST_ADDQ(&curproxy->rsp_add, &wl->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006470 }
6471 else if (!strcmp(args[0], "errorloc") ||
6472 !strcmp(args[0], "errorloc302") ||
6473 !strcmp(args[0], "errorloc303")) { /* error location */
6474 int errnum, errlen;
6475 char *err;
6476
Willy Tarreau977b8e42006-12-29 14:19:17 +01006477 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006478 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006479
Willy Tarreaubaaee002006-06-26 02:48:02 +02006480 if (*(args[2]) == 0) {
Willy Tarreau1772ece2009-04-03 14:49:12 +02006481 Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006482 err_code |= ERR_ALERT | ERR_FATAL;
6483 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006484 }
6485
6486 errnum = atol(args[1]);
6487 if (!strcmp(args[0], "errorloc303")) {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006488 errlen = strlen(HTTP_303) + strlen(args[2]) + 5;
6489 err = malloc(errlen);
6490 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006491 } else {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006492 errlen = strlen(HTTP_302) + strlen(args[2]) + 5;
6493 err = malloc(errlen);
6494 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006495 }
6496
Willy Tarreau0f772532006-12-23 20:51:41 +01006497 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6498 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006499 chunk_destroy(&curproxy->errmsg[rc]);
6500 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau0f772532006-12-23 20:51:41 +01006501 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006502 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006503 }
Willy Tarreau0f772532006-12-23 20:51:41 +01006504
6505 if (rc >= HTTP_ERR_SIZE) {
Willy Tarreaubb3c09a2015-09-27 15:13:30 +02006506 Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n",
6507 file, linenum, errnum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006508 free(err);
6509 }
6510 }
Willy Tarreau3f49b302007-06-11 00:29:26 +02006511 else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
6512 int errnum, errlen, fd;
6513 char *err;
6514 struct stat stat;
6515
6516 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006517 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006518
6519 if (*(args[2]) == 0) {
Willy Tarreau1772ece2009-04-03 14:49:12 +02006520 Alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006521 err_code |= ERR_ALERT | ERR_FATAL;
6522 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006523 }
6524
6525 fd = open(args[2], O_RDONLY);
6526 if ((fd < 0) || (fstat(fd, &stat) < 0)) {
6527 Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n",
6528 file, linenum, args[2], args[1]);
6529 if (fd >= 0)
6530 close(fd);
Willy Tarreau93893792009-07-23 13:19:11 +02006531 err_code |= ERR_ALERT | ERR_FATAL;
6532 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006533 }
6534
Willy Tarreau27a674e2009-08-17 07:23:33 +02006535 if (stat.st_size <= global.tune.bufsize) {
Willy Tarreau3f49b302007-06-11 00:29:26 +02006536 errlen = stat.st_size;
6537 } else {
6538 Warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n",
Willy Tarreau27a674e2009-08-17 07:23:33 +02006539 file, linenum, args[2], global.tune.bufsize);
Willy Tarreau93893792009-07-23 13:19:11 +02006540 err_code |= ERR_WARN;
Willy Tarreau27a674e2009-08-17 07:23:33 +02006541 errlen = global.tune.bufsize;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006542 }
6543
6544 err = malloc(errlen); /* malloc() must succeed during parsing */
6545 errnum = read(fd, err, errlen);
6546 if (errnum != errlen) {
6547 Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n",
6548 file, linenum, args[2], args[1]);
6549 close(fd);
6550 free(err);
Willy Tarreau93893792009-07-23 13:19:11 +02006551 err_code |= ERR_ALERT | ERR_FATAL;
6552 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006553 }
6554 close(fd);
6555
6556 errnum = atol(args[1]);
6557 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6558 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006559 chunk_destroy(&curproxy->errmsg[rc]);
6560 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006561 break;
6562 }
6563 }
6564
6565 if (rc >= HTTP_ERR_SIZE) {
Willy Tarreaubb3c09a2015-09-27 15:13:30 +02006566 Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n",
6567 file, linenum, errnum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006568 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006569 free(err);
6570 }
6571 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006572 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006573 struct cfg_kw_list *kwl;
6574 int index;
6575
6576 list_for_each_entry(kwl, &cfg_keywords.list, list) {
6577 for (index = 0; kwl->kw[index].kw != NULL; index++) {
6578 if (kwl->kw[index].section != CFG_LISTEN)
6579 continue;
6580 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
6581 /* prepare error message just in case */
Willy Tarreau28a47d62012-09-18 20:02:48 +02006582 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02006583 if (rc < 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02006584 Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006585 err_code |= ERR_ALERT | ERR_FATAL;
6586 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006587 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02006588 else if (rc > 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02006589 Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006590 err_code |= ERR_WARN;
6591 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02006592 }
Willy Tarreau93893792009-07-23 13:19:11 +02006593 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006594 }
6595 }
6596 }
William Lallemand82fe75c2012-10-23 10:25:10 +02006597
Willy Tarreau6daf3432008-01-22 16:44:08 +01006598 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau93893792009-07-23 13:19:11 +02006599 err_code |= ERR_ALERT | ERR_FATAL;
6600 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006601 }
Willy Tarreau93893792009-07-23 13:19:11 +02006602 out:
Willy Tarreauf4068b62012-05-08 17:37:49 +02006603 free(errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006604 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006605}
6606
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006607int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006608cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
6609{
6610#ifdef CONFIG_HAP_NS
6611 const char *err;
6612 const char *item = args[0];
6613
6614 if (!strcmp(item, "namespace_list")) {
6615 return 0;
6616 }
6617 else if (!strcmp(item, "namespace")) {
6618 size_t idx = 1;
6619 const char *current;
6620 while (*(current = args[idx++])) {
6621 err = invalid_char(current);
6622 if (err) {
6623 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6624 file, linenum, *err, item, current);
6625 return ERR_ALERT | ERR_FATAL;
6626 }
6627
6628 if (netns_store_lookup(current, strlen(current))) {
6629 Alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
6630 file, linenum, current);
6631 return ERR_ALERT | ERR_FATAL;
6632 }
6633 if (!netns_store_insert(current)) {
6634 Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
6635 file, linenum, current);
6636 return ERR_ALERT | ERR_FATAL;
6637 }
6638 }
6639 }
6640
6641 return 0;
6642#else
6643 Alert("parsing [%s:%d]: namespace support is not compiled in.",
6644 file, linenum);
6645 return ERR_ALERT | ERR_FATAL;
6646#endif
6647}
6648
6649int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006650cfg_parse_users(const char *file, int linenum, char **args, int kwm)
6651{
6652
6653 int err_code = 0;
6654 const char *err;
6655
6656 if (!strcmp(args[0], "userlist")) { /* new userlist */
6657 struct userlist *newul;
6658
6659 if (!*args[1]) {
6660 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6661 file, linenum, args[0]);
6662 err_code |= ERR_ALERT | ERR_FATAL;
6663 goto out;
6664 }
William Lallemand6e62fb62015-04-28 16:55:23 +02006665 if (alertif_too_many_args(1, file, linenum, args, &err_code))
6666 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006667
6668 err = invalid_char(args[1]);
6669 if (err) {
6670 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6671 file, linenum, *err, args[0], args[1]);
6672 err_code |= ERR_ALERT | ERR_FATAL;
6673 goto out;
6674 }
6675
6676 for (newul = userlist; newul; newul = newul->next)
6677 if (!strcmp(newul->name, args[1])) {
6678 Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
6679 file, linenum, args[1]);
6680 err_code |= ERR_WARN;
6681 goto out;
6682 }
6683
Vincent Bernat02779b62016-04-03 13:48:43 +02006684 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006685 if (!newul) {
6686 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6687 err_code |= ERR_ALERT | ERR_ABORT;
6688 goto out;
6689 }
6690
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006691 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006692 if (!newul->name) {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006693 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6694 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01006695 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006696 goto out;
6697 }
6698
6699 newul->next = userlist;
6700 userlist = newul;
6701
6702 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006703 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006704 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006705 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006706
6707 if (!*args[1]) {
6708 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6709 file, linenum, args[0]);
6710 err_code |= ERR_ALERT | ERR_FATAL;
6711 goto out;
6712 }
6713
6714 err = invalid_char(args[1]);
6715 if (err) {
6716 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6717 file, linenum, *err, args[0], args[1]);
6718 err_code |= ERR_ALERT | ERR_FATAL;
6719 goto out;
6720 }
6721
William Lallemand4ac9f542015-05-28 18:03:51 +02006722 if (!userlist)
6723 goto out;
6724
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006725 for (ag = userlist->groups; ag; ag = ag->next)
6726 if (!strcmp(ag->name, args[1])) {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006727 Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
6728 file, linenum, args[1], userlist->name);
6729 err_code |= ERR_ALERT;
6730 goto out;
6731 }
6732
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006733 ag = calloc(1, sizeof(*ag));
6734 if (!ag) {
6735 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6736 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006737 goto out;
6738 }
6739
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006740 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01006741 if (!ag->name) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006742 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6743 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01006744 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006745 goto out;
6746 }
6747
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006748 cur_arg = 2;
6749
6750 while (*args[cur_arg]) {
6751 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006752 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006753 cur_arg += 2;
6754 continue;
6755 } else {
6756 Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
6757 file, linenum, args[0]);
6758 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01006759 free(ag->groupusers);
6760 free(ag->name);
6761 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006762 goto out;
6763 }
6764 }
6765
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006766 ag->next = userlist->groups;
6767 userlist->groups = ag;
6768
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006769 } else if (!strcmp(args[0], "user")) { /* new user */
6770 struct auth_users *newuser;
6771 int cur_arg;
6772
6773 if (!*args[1]) {
6774 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6775 file, linenum, args[0]);
6776 err_code |= ERR_ALERT | ERR_FATAL;
6777 goto out;
6778 }
William Lallemand4ac9f542015-05-28 18:03:51 +02006779 if (!userlist)
6780 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006781
6782 for (newuser = userlist->users; newuser; newuser = newuser->next)
6783 if (!strcmp(newuser->user, args[1])) {
6784 Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
6785 file, linenum, args[1], userlist->name);
6786 err_code |= ERR_ALERT;
6787 goto out;
6788 }
6789
Vincent Bernat02779b62016-04-03 13:48:43 +02006790 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006791 if (!newuser) {
6792 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6793 err_code |= ERR_ALERT | ERR_ABORT;
6794 goto out;
6795 }
6796
6797 newuser->user = strdup(args[1]);
6798
6799 newuser->next = userlist->users;
6800 userlist->users = newuser;
6801
6802 cur_arg = 2;
6803
6804 while (*args[cur_arg]) {
6805 if (!strcmp(args[cur_arg], "password")) {
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006806#ifdef CONFIG_HAP_CRYPT
6807 if (!crypt("", args[cur_arg + 1])) {
6808 Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
6809 file, linenum, newuser->user);
6810 err_code |= ERR_ALERT | ERR_FATAL;
6811 goto out;
6812 }
6813#else
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006814 Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
6815 file, linenum);
6816 err_code |= ERR_ALERT;
6817#endif
6818 newuser->pass = strdup(args[cur_arg + 1]);
6819 cur_arg += 2;
6820 continue;
6821 } else if (!strcmp(args[cur_arg], "insecure-password")) {
6822 newuser->pass = strdup(args[cur_arg + 1]);
6823 newuser->flags |= AU_O_INSECURE;
6824 cur_arg += 2;
6825 continue;
6826 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006827 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006828 cur_arg += 2;
6829 continue;
6830 } else {
6831 Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
6832 file, linenum, args[0]);
6833 err_code |= ERR_ALERT | ERR_FATAL;
6834 goto out;
6835 }
6836 }
6837 } else {
6838 Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users");
6839 err_code |= ERR_ALERT | ERR_FATAL;
6840 }
6841
6842out:
6843 return err_code;
6844}
Willy Tarreaubaaee002006-06-26 02:48:02 +02006845
Christopher Faulet79bdef32016-11-04 22:36:15 +01006846int
6847cfg_parse_scope(const char *file, int linenum, char *line)
6848{
6849 char *beg, *end, *scope = NULL;
6850 int err_code = 0;
6851 const char *err;
6852
6853 beg = line + 1;
6854 end = strchr(beg, ']');
6855
6856 /* Detect end of scope declaration */
6857 if (!end || end == beg) {
6858 Alert("parsing [%s:%d] : empty scope name is forbidden.\n",
6859 file, linenum);
6860 err_code |= ERR_ALERT | ERR_FATAL;
6861 goto out;
6862 }
6863
6864 /* Get scope name and check its validity */
6865 scope = my_strndup(beg, end-beg);
6866 err = invalid_char(scope);
6867 if (err) {
6868 Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
6869 file, linenum, *err);
6870 err_code |= ERR_ALERT | ERR_ABORT;
6871 goto out;
6872 }
6873
6874 /* Be sure to have a scope declaration alone on its line */
6875 line = end+1;
6876 while (isspace((unsigned char)*line))
6877 line++;
6878 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
6879 Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
6880 file, linenum, *line);
6881 err_code |= ERR_ALERT | ERR_ABORT;
6882 goto out;
6883 }
6884
6885 /* We have a valid scope declaration, save it */
6886 free(cfg_scope);
6887 cfg_scope = scope;
6888 scope = NULL;
6889
6890 out:
6891 free(scope);
6892 return err_code;
6893}
6894
Willy Tarreaubaaee002006-06-26 02:48:02 +02006895/*
6896 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02006897 * Returns the error code, 0 if OK, or any combination of :
6898 * - ERR_ABORT: must abort ASAP
6899 * - ERR_FATAL: we can continue parsing but not start the service
6900 * - ERR_WARN: a warning has been emitted
6901 * - ERR_ALERT: an alert has been emitted
6902 * Only the two first ones can stop processing, the two others are just
6903 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02006904 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02006905int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02006906{
William Lallemand64e84512015-05-12 14:25:37 +02006907 char *thisline;
6908 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006909 FILE *f;
6910 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02006911 int err_code = 0;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01006912 struct cfg_section *cs = NULL;
6913 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02006914 int readbytes = 0;
6915
6916 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
William Lallemandb2f07452015-05-12 14:27:13 +02006917 Alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02006918 return -1;
6919 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01006920
David Carlier97880bb2016-04-08 10:35:26 +01006921 if ((f=fopen(file,"r")) == NULL) {
6922 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006923 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01006924 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006925
William Lallemandb2f07452015-05-12 14:27:13 +02006926next_line:
William Lallemand64e84512015-05-12 14:25:37 +02006927 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02006928 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006929 char *end;
6930 char *args[MAX_LINE_ARGS + 1];
6931 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02006932 int dquote = 0; /* double quote */
6933 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006934
Willy Tarreaubaaee002006-06-26 02:48:02 +02006935 linenum++;
6936
6937 end = line + strlen(line);
6938
William Lallemand64e84512015-05-12 14:25:37 +02006939 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006940 /* Check if we reached the limit and the last char is not \n.
6941 * Watch out for the last line without the terminating '\n'!
6942 */
William Lallemand64e84512015-05-12 14:25:37 +02006943 char *newline;
6944 int newlinesize = linesize * 2;
6945
6946 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
6947 if (newline == NULL) {
6948 Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
6949 file, linenum);
6950 err_code |= ERR_ALERT | ERR_FATAL;
6951 continue;
6952 }
6953
6954 readbytes = linesize - 1;
6955 linesize = newlinesize;
6956 thisline = newline;
6957 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006958 }
6959
William Lallemand64e84512015-05-12 14:25:37 +02006960 readbytes = 0;
6961
Willy Tarreaubaaee002006-06-26 02:48:02 +02006962 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02006963 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02006964 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02006965
Christopher Faulet79bdef32016-11-04 22:36:15 +01006966
6967 if (*line == '[') {/* This is the begining if a scope */
6968 err_code |= cfg_parse_scope(file, linenum, line);
6969 goto next_line;
6970 }
6971
Willy Tarreaubaaee002006-06-26 02:48:02 +02006972 arg = 0;
6973 args[arg] = line;
6974
6975 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02006976 if (*line == '"' && !squote) { /* double quote outside single quotes */
6977 if (dquote)
6978 dquote = 0;
6979 else
6980 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02006981 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02006982 end--;
6983 }
6984 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
6985 if (squote)
6986 squote = 0;
6987 else
6988 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02006989 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02006990 end--;
6991 }
6992 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006993 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
6994 * C equivalent value. Other combinations left unchanged (eg: \1).
6995 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02006996 int skip = 0;
6997 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
6998 *line = line[1];
6999 skip = 1;
7000 }
7001 else if (line[1] == 'r') {
7002 *line = '\r';
7003 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02007004 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007005 else if (line[1] == 'n') {
7006 *line = '\n';
7007 skip = 1;
7008 }
7009 else if (line[1] == 't') {
7010 *line = '\t';
7011 skip = 1;
7012 }
7013 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01007014 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007015 unsigned char hex1, hex2;
7016 hex1 = toupper(line[2]) - '0';
7017 hex2 = toupper(line[3]) - '0';
7018 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
7019 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
7020 *line = (hex1<<4) + hex2;
7021 skip = 3;
7022 }
7023 else {
7024 Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007025 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007026 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007027 } else if (line[1] == '"') {
7028 *line = '"';
7029 skip = 1;
7030 } else if (line[1] == '\'') {
7031 *line = '\'';
7032 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02007033 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
7034 *line = '$';
7035 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007036 }
7037 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01007038 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02007039 end -= skip;
7040 }
7041 line++;
7042 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007043 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007044 /* end of string, end of loop */
7045 *line = 0;
7046 break;
7047 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007048 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007049 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007050 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007051 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007052 line++;
7053 args[++arg] = line;
7054 }
William Lallemandb2f07452015-05-12 14:27:13 +02007055 else if (dquote && *line == '$') {
7056 /* environment variables are evaluated inside double quotes */
7057 char *var_beg;
7058 char *var_end;
7059 char save_char;
7060 char *value;
7061 int val_len;
7062 int newlinesize;
7063 int braces = 0;
7064
7065 var_beg = line + 1;
7066 var_end = var_beg;
7067
7068 if (*var_beg == '{') {
7069 var_beg++;
7070 var_end++;
7071 braces = 1;
7072 }
7073
7074 if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') {
7075 Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg);
7076 err_code |= ERR_ALERT | ERR_FATAL;
7077 goto next_line; /* skip current line */
7078 }
7079
7080 while (isalnum((int)(unsigned char)*var_end) || *var_end == '_')
7081 var_end++;
7082
7083 save_char = *var_end;
7084 *var_end = '\0';
7085 value = getenv(var_beg);
7086 *var_end = save_char;
7087 val_len = value ? strlen(value) : 0;
7088
7089 if (braces) {
7090 if (*var_end == '}') {
7091 var_end++;
7092 braces = 0;
7093 } else {
7094 Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
7095 err_code |= ERR_ALERT | ERR_FATAL;
7096 goto next_line; /* skip current line */
7097 }
7098 }
7099
7100 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
7101
7102 /* if not enough space in thisline */
7103 if (newlinesize > linesize) {
7104 char *newline;
7105
7106 newline = realloc(thisline, newlinesize * sizeof(*thisline));
7107 if (newline == NULL) {
7108 Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
7109 err_code |= ERR_ALERT | ERR_FATAL;
7110 goto next_line; /* slip current line */
7111 }
7112 /* recompute pointers if realloc returns a new pointer */
7113 if (newline != thisline) {
7114 int i;
7115 int diff;
7116
7117 for (i = 0; i <= arg; i++) {
7118 diff = args[i] - thisline;
7119 args[i] = newline + diff;
7120 }
7121
7122 diff = var_end - thisline;
7123 var_end = newline + diff;
7124 diff = end - thisline;
7125 end = newline + diff;
7126 diff = line - thisline;
7127 line = newline + diff;
7128 thisline = newline;
7129 }
7130 linesize = newlinesize;
7131 }
7132
7133 /* insert value inside the line */
7134 memmove(line + val_len, var_end, end - var_end + 1);
7135 memcpy(line, value, val_len);
7136 end += val_len - (var_end - line);
7137 line += val_len;
7138 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007139 else {
7140 line++;
7141 }
7142 }
William Lallemandb2f07452015-05-12 14:27:13 +02007143
William Lallemandf9873ba2015-05-05 17:37:14 +02007144 if (dquote) {
7145 Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
7146 err_code |= ERR_ALERT | ERR_FATAL;
7147 }
7148
7149 if (squote) {
7150 Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
7151 err_code |= ERR_ALERT | ERR_FATAL;
7152 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007153
7154 /* empty line */
7155 if (!**args)
7156 continue;
7157
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007158 if (*line) {
7159 /* we had to stop due to too many args.
7160 * Let's terminate the string, print the offending part then cut the
7161 * last arg.
7162 */
7163 while (*line && *line != '#' && *line != '\n' && *line != '\r')
7164 line++;
7165 *line = '\0';
7166
Krzysztof Piotr Oledzki500b8f02009-12-15 22:34:51 +01007167 Alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
Willy Tarreau3ccf94e2009-12-17 21:12:16 +01007168 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007169 err_code |= ERR_ALERT | ERR_FATAL;
7170 args[arg] = line;
7171 }
7172
Willy Tarreau540abe42007-05-02 20:50:16 +02007173 /* zero out remaining args and ensure that at least one entry
7174 * is zeroed out.
7175 */
7176 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007177 args[arg] = line;
7178 }
7179
Willy Tarreau3842f002009-06-14 11:39:52 +02007180 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007181 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02007182 char *tmp;
7183
Willy Tarreau3842f002009-06-14 11:39:52 +02007184 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02007185 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007186 for (arg=0; *args[arg+1]; arg++)
7187 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02007188 *tmp = '\0'; // fix the next arg to \0
7189 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007190 }
Willy Tarreau3842f002009-06-14 11:39:52 +02007191 else if (!strcmp(args[0], "default")) {
7192 kwm = KWM_DEF;
7193 for (arg=0; *args[arg+1]; arg++)
7194 args[arg] = args[arg+1]; // shift args after inversion
7195 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007196
William Lallemand0f99e342011-10-12 17:50:54 +02007197 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \
7198 strcmp(args[0], "log") != 0) {
7199 Alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02007200 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007201 }
7202
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007203 /* detect section start */
7204 list_for_each_entry(ics, &sections, list) {
7205 if (strcmp(args[0], ics->section_name) == 0) {
7206 cursection = ics->section_name;
7207 cs = ics;
7208 break;
7209 }
Emeric Brun32da3c42010-09-23 18:39:19 +02007210 }
7211
Willy Tarreaubaaee002006-06-26 02:48:02 +02007212 /* else it's a section keyword */
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007213 if (cs)
7214 err_code |= cs->section_parser(file, linenum, args, kwm);
7215 else {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01007216 Alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007217 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007218 }
Willy Tarreau058e9072009-07-20 09:30:05 +02007219
7220 if (err_code & ERR_ABORT)
7221 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007222 }
Christopher Faulet79bdef32016-11-04 22:36:15 +01007223 free(cfg_scope);
7224 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01007225 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02007226 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007227 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02007228 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007229}
7230
Willy Tarreau64ab6072014-09-16 12:17:36 +02007231/* This function propagates processes from frontend <from> to backend <to> so
7232 * that it is always guaranteed that a backend pointed to by a frontend is
7233 * bound to all of its processes. After that, if the target is a "listen"
7234 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02007235 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02007236 * checked first to ensure that <to> is already bound to all processes of
7237 * <from>, there is no risk of looping and we ensure to follow the shortest
7238 * path to the destination.
7239 *
7240 * It is possible to set <to> to NULL for the first call so that the function
7241 * takes care of visiting the initial frontend in <from>.
7242 *
7243 * It is important to note that the function relies on the fact that all names
7244 * have already been resolved.
7245 */
7246void propagate_processes(struct proxy *from, struct proxy *to)
7247{
7248 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007249
7250 if (to) {
7251 /* check whether we need to go down */
7252 if (from->bind_proc &&
7253 (from->bind_proc & to->bind_proc) == from->bind_proc)
7254 return;
7255
7256 if (!from->bind_proc && !to->bind_proc)
7257 return;
7258
7259 to->bind_proc = from->bind_proc ?
7260 (to->bind_proc | from->bind_proc) : 0;
7261
7262 /* now propagate down */
7263 from = to;
7264 }
7265
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01007266 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02007267 return;
7268
Willy Tarreauf6b70012014-12-18 14:00:43 +01007269 if (from->state == PR_STSTOPPED)
7270 return;
7271
Willy Tarreau64ab6072014-09-16 12:17:36 +02007272 /* default_backend */
7273 if (from->defbe.be)
7274 propagate_processes(from, from->defbe.be);
7275
7276 /* use_backend */
7277 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02007278 if (rule->dynamic)
7279 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007280 to = rule->be.backend;
7281 propagate_processes(from, to);
7282 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02007283}
7284
Willy Tarreaubb925012009-07-23 13:36:36 +02007285/*
7286 * Returns the error code, 0 if OK, or any combination of :
7287 * - ERR_ABORT: must abort ASAP
7288 * - ERR_FATAL: we can continue parsing but not start the service
7289 * - ERR_WARN: a warning has been emitted
7290 * - ERR_ALERT: an alert has been emitted
7291 * Only the two first ones can stop processing, the two others are just
7292 * indicators.
7293 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007294int check_config_validity()
7295{
7296 int cfgerr = 0;
7297 struct proxy *curproxy = NULL;
7298 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02007299 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007300 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007301 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007302 char *err;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007303
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007304 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007305 /*
7306 * Now, check for the integrity of all that we have collected.
7307 */
7308
7309 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02007310 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007311
Willy Tarreau193b8c62012-11-22 00:17:38 +01007312 if (!global.tune.max_http_hdr)
7313 global.tune.max_http_hdr = MAX_HTTP_HDR;
7314
7315 if (!global.tune.cookie_len)
7316 global.tune.cookie_len = CAPTURE_LEN;
7317
7318 pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
7319
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01007320 /* Post initialisation of the users and groups lists. */
7321 err_code = userlist_postinit();
7322 if (err_code != ERR_NONE)
7323 goto out;
7324
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007325 /* first, we will invert the proxy list order */
7326 curproxy = NULL;
7327 while (proxy) {
7328 struct proxy *next;
7329
7330 next = proxy->next;
7331 proxy->next = curproxy;
7332 curproxy = proxy;
7333 if (!next)
7334 break;
7335 proxy = next;
7336 }
7337
Willy Tarreau419ead82014-09-16 13:41:21 +02007338 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007339 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007340 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01007341 struct sticking_rule *mrule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02007342 struct act_rule *trule;
7343 struct act_rule *hrqrule;
Dragan Dosen1322d092015-09-22 16:05:32 +02007344 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007345 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01007346 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007347
Willy Tarreau050536d2012-10-04 08:47:34 +02007348 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007349 /* proxy ID not set, use automatic numbering with first
7350 * spare entry starting with next_pxid.
7351 */
7352 next_pxid = get_next_id(&used_proxy_id, next_pxid);
7353 curproxy->conf.id.key = curproxy->uuid = next_pxid;
7354 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007355 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01007356 next_pxid++;
7357
Willy Tarreau55ea7572007-06-17 19:56:27 +02007358
Willy Tarreaubaaee002006-06-26 02:48:02 +02007359 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02007360 /* ensure we don't keep listeners uselessly bound */
7361 stop_proxy(curproxy);
Willy Tarreau02df7742015-05-01 19:59:56 +02007362 free((void *)curproxy->table.peers.name);
7363 curproxy->table.peers.p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007364 continue;
7365 }
7366
Willy Tarreau102df612014-05-07 23:56:38 +02007367 /* Check multi-process mode compatibility for the current proxy */
7368
7369 if (curproxy->bind_proc) {
7370 /* an explicit bind-process was specified, let's check how many
7371 * processes remain.
7372 */
David Carliere6c39412015-07-02 07:00:17 +00007373 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02007374
7375 curproxy->bind_proc &= nbits(global.nbproc);
7376 if (!curproxy->bind_proc && nbproc == 1) {
7377 Warning("Proxy '%s': the process specified on the 'bind-process' directive refers to a process number that is higher than global.nbproc. The proxy has been forced to run on process 1 only.\n", curproxy->id);
7378 curproxy->bind_proc = 1;
7379 }
7380 else if (!curproxy->bind_proc && nbproc > 1) {
7381 Warning("Proxy '%s': all processes specified on the 'bind-process' directive refer to numbers that are all higher than global.nbproc. The directive was ignored and the proxy will run on all processes.\n", curproxy->id);
7382 curproxy->bind_proc = 0;
7383 }
7384 }
7385
Willy Tarreau3d209582014-05-09 17:06:11 +02007386 /* check and reduce the bind-proc of each listener */
7387 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
7388 unsigned long mask;
7389
7390 if (!bind_conf->bind_proc)
7391 continue;
7392
7393 mask = nbits(global.nbproc);
7394 if (curproxy->bind_proc)
7395 mask &= curproxy->bind_proc;
7396 /* mask cannot be null here thanks to the previous checks */
7397
David Carliere6c39412015-07-02 07:00:17 +00007398 nbproc = my_popcountl(bind_conf->bind_proc);
Willy Tarreau3d209582014-05-09 17:06:11 +02007399 bind_conf->bind_proc &= mask;
7400
7401 if (!bind_conf->bind_proc && nbproc == 1) {
7402 Warning("Proxy '%s': the process number specified on the 'process' directive of 'bind %s' at [%s:%d] refers to a process not covered by the proxy. This has been fixed by forcing it to run on the proxy's first process only.\n",
7403 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
7404 bind_conf->bind_proc = mask & ~(mask - 1);
7405 }
7406 else if (!bind_conf->bind_proc && nbproc > 1) {
7407 Warning("Proxy '%s': the process range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to processes not covered by the proxy. The directive was ignored so that all of the proxy's processes are used.\n",
7408 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
7409 bind_conf->bind_proc = 0;
7410 }
7411 }
7412
Willy Tarreauff01a212009-03-15 13:46:16 +01007413 switch (curproxy->mode) {
7414 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007415 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007416 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007417 Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
7418 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007419 cfgerr++;
7420 }
7421
7422 if (curproxy->srv != NULL)
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007423 Warning("config : servers will be ignored for %s '%s'.\n",
7424 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007425 break;
7426
7427 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007428 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007429 break;
7430
7431 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01007432 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01007433 break;
7434 }
7435
Willy Tarreauf3934b82015-08-11 11:36:45 +02007436 if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
7437 Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
7438 proxy_type_str(curproxy), curproxy->id);
7439 err_code |= ERR_WARN;
7440 }
7441
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007442 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02007443 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007444 if (curproxy->options & PR_O_TRANSP) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007445 Alert("config : %s '%s' cannot use both transparent and balance mode.\n",
7446 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007447 cfgerr++;
7448 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007449#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007450 else if (curproxy->srv == NULL) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007451 Alert("config : %s '%s' needs at least 1 server in balance mode.\n",
7452 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007453 cfgerr++;
7454 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007455#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02007456 else if (curproxy->options & PR_O_DISPATCH) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007457 Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
7458 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02007459 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007460 }
7461 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02007462 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007463 /* If no LB algo is set in a backend, and we're not in
7464 * transparent mode, dispatch mode nor proxy mode, we
7465 * want to use balance roundrobin by default.
7466 */
7467 curproxy->lbprm.algo &= ~BE_LB_ALGO;
7468 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007469 }
7470 }
Willy Tarreau193cf932007-09-17 10:17:23 +02007471
Willy Tarreau1620ec32011-08-06 17:05:02 +02007472 if (curproxy->options & PR_O_DISPATCH)
7473 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
7474 else if (curproxy->options & PR_O_HTTP_PROXY)
7475 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
7476 else if (curproxy->options & PR_O_TRANSP)
7477 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01007478
Willy Tarreau1620ec32011-08-06 17:05:02 +02007479 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) {
7480 if (curproxy->options & PR_O_DISABLE404) {
7481 Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7482 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
7483 err_code |= ERR_WARN;
7484 curproxy->options &= ~PR_O_DISABLE404;
7485 }
7486 if (curproxy->options2 & PR_O2_CHK_SNDST) {
7487 Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7488 "send-state", proxy_type_str(curproxy), curproxy->id);
7489 err_code |= ERR_WARN;
7490 curproxy->options &= ~PR_O2_CHK_SNDST;
7491 }
Willy Tarreauef781042010-01-27 11:53:01 +01007492 }
7493
Simon Horman98637e52014-06-20 12:30:16 +09007494 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
7495 if (!global.external_check) {
7496 Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
7497 curproxy->id, "option external-check");
7498 cfgerr++;
7499 }
7500 if (!curproxy->check_command) {
7501 Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
7502 curproxy->id, "option external-check");
7503 cfgerr++;
7504 }
7505 }
7506
Simon Horman64e34162015-02-06 11:11:57 +09007507 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007508 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
7509 Warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
Pieter Baauw8669e972015-08-17 00:45:05 +02007510 "'email-alert from', 'email-alert level' 'email-alert mailers', "
7511 "'email-alert myhostname', or 'email-alert to' "
7512 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007513 "to be present).\n",
7514 proxy_type_str(curproxy), curproxy->id);
7515 err_code |= ERR_WARN;
7516 free_email_alert(curproxy);
7517 }
7518 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01007519 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09007520 }
7521
Simon Horman98637e52014-06-20 12:30:16 +09007522 if (curproxy->check_command) {
7523 int clear = 0;
7524 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
7525 Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7526 "external-check command", proxy_type_str(curproxy), curproxy->id);
7527 err_code |= ERR_WARN;
7528 clear = 1;
7529 }
7530 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Ben Cabot49795eb2015-09-16 12:07:51 +01007531 Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
Simon Horman98637e52014-06-20 12:30:16 +09007532 curproxy->id, "external-check command");
7533 cfgerr++;
7534 }
7535 if (clear) {
7536 free(curproxy->check_command);
7537 curproxy->check_command = NULL;
7538 }
7539 }
7540
7541 if (curproxy->check_path) {
7542 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
7543 Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7544 "external-check path", proxy_type_str(curproxy), curproxy->id);
7545 err_code |= ERR_WARN;
7546 free(curproxy->check_path);
7547 curproxy->check_path = NULL;
7548 }
7549 }
7550
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007551 /* if a default backend was specified, let's find it */
7552 if (curproxy->defbe.name) {
7553 struct proxy *target;
7554
Willy Tarreauafb39922015-05-26 12:04:09 +02007555 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007556 if (!target) {
7557 Alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
7558 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007559 cfgerr++;
7560 } else if (target == curproxy) {
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007561 Alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
7562 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02007563 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007564 } else if (target->mode != curproxy->mode &&
7565 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7566
7567 Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
7568 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7569 curproxy->conf.file, curproxy->conf.line,
7570 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7571 target->conf.file, target->conf.line);
7572 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007573 } else {
7574 free(curproxy->defbe.name);
7575 curproxy->defbe.be = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007576 /* Update tot_fe_maxconn for a further fullconn's computation */
7577 target->tot_fe_maxconn += curproxy->maxconn;
Willy Tarreauff678132012-02-13 14:32:34 +01007578 /* Emit a warning if this proxy also has some servers */
7579 if (curproxy->srv) {
7580 Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
7581 curproxy->id);
7582 err_code |= ERR_WARN;
7583 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007584 }
7585 }
7586
Emeric Brun3f783572017-01-12 11:21:28 +01007587 if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
7588 /* Case of listen without default backend
7589 * The curproxy will be its own default backend
7590 * so we update tot_fe_maxconn for a further
7591 * fullconn's computation */
7592 curproxy->tot_fe_maxconn += curproxy->maxconn;
7593 }
7594
Willy Tarreau55ea7572007-06-17 19:56:27 +02007595 /* find the target proxy for 'use_backend' rules */
7596 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007597 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007598 struct logformat_node *node;
7599 char *pxname;
7600
7601 /* Try to parse the string as a log format expression. If the result
7602 * of the parsing is only one entry containing a simple string, then
7603 * it's a standard string corresponding to a static rule, thus the
7604 * parsing is cancelled and be.name is restored to be resolved.
7605 */
7606 pxname = rule->be.name;
7607 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01007608 curproxy->conf.args.ctx = ARGC_UBK;
7609 curproxy->conf.args.file = rule->file;
7610 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007611 err = NULL;
7612 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
7613 Alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
7614 rule->file, rule->line, pxname, err);
7615 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01007616 cfgerr++;
7617 continue;
7618 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007619 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
7620
7621 if (!LIST_ISEMPTY(&rule->be.expr)) {
7622 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
7623 rule->dynamic = 1;
7624 free(pxname);
7625 continue;
7626 }
7627 /* simple string: free the expression and fall back to static rule */
7628 free(node->arg);
7629 free(node);
7630 }
7631
7632 rule->dynamic = 0;
7633 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007634
Willy Tarreauafb39922015-05-26 12:04:09 +02007635 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007636 if (!target) {
7637 Alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
7638 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007639 cfgerr++;
7640 } else if (target == curproxy) {
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007641 Alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
7642 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007643 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007644 } else if (target->mode != curproxy->mode &&
7645 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7646
7647 Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
7648 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7649 curproxy->conf.file, curproxy->conf.line,
7650 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7651 target->conf.file, target->conf.line);
7652 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007653 } else {
7654 free((void *)rule->be.name);
7655 rule->be.backend = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007656 /* For each target of switching rules, we update
7657 * their tot_fe_maxconn, except if a previous rule point
7658 * on the same backend or on the default backend */
7659 if (rule->be.backend != curproxy->defbe.be) {
7660 struct switching_rule *swrule;
7661
7662 list_for_each_entry(swrule, &curproxy->switching_rules, list) {
7663 if (rule == swrule) {
7664 target->tot_fe_maxconn += curproxy->maxconn;
7665 break;
7666 }
7667 else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) {
7668 /* there is multiple ref of this backend */
7669 break;
7670 }
7671 }
7672 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02007673 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007674 }
7675
Willy Tarreau64ab6072014-09-16 12:17:36 +02007676 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007677 list_for_each_entry(srule, &curproxy->server_rules, list) {
7678 struct server *target = findserver(curproxy, srule->srv.name);
7679
7680 if (!target) {
7681 Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
7682 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
7683 cfgerr++;
7684 continue;
7685 }
7686 free((void *)srule->srv.name);
7687 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007688 }
7689
Emeric Brunb982a3d2010-01-04 15:45:53 +01007690 /* find the target table for 'stick' rules */
7691 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
7692 struct proxy *target;
7693
Emeric Brun1d33b292010-01-04 15:47:17 +01007694 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
7695 if (mrule->flags & STK_IS_STORE)
7696 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7697
Emeric Brunb982a3d2010-01-04 15:45:53 +01007698 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007699 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007700 else
7701 target = curproxy;
7702
7703 if (!target) {
7704 Alert("Proxy '%s': unable to find stick-table '%s'.\n",
7705 curproxy->id, mrule->table.name);
7706 cfgerr++;
7707 }
7708 else if (target->table.size == 0) {
7709 Alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7710 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7711 cfgerr++;
7712 }
Willy Tarreau12785782012-04-27 21:37:17 +02007713 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
7714 Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
Emeric Brunb982a3d2010-01-04 15:45:53 +01007715 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7716 cfgerr++;
7717 }
7718 else {
7719 free((void *)mrule->table.name);
7720 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007721 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007722 }
7723 }
7724
7725 /* find the target table for 'store response' rules */
7726 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
7727 struct proxy *target;
7728
Emeric Brun1d33b292010-01-04 15:47:17 +01007729 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7730
Emeric Brunb982a3d2010-01-04 15:45:53 +01007731 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007732 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007733 else
7734 target = curproxy;
7735
7736 if (!target) {
7737 Alert("Proxy '%s': unable to find store table '%s'.\n",
7738 curproxy->id, mrule->table.name);
7739 cfgerr++;
7740 }
7741 else if (target->table.size == 0) {
7742 Alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7743 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7744 cfgerr++;
7745 }
Willy Tarreau12785782012-04-27 21:37:17 +02007746 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
7747 Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
Emeric Brunb982a3d2010-01-04 15:45:53 +01007748 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7749 cfgerr++;
7750 }
7751 else {
7752 free((void *)mrule->table.name);
7753 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007754 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007755 }
7756 }
7757
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007758 /* find the target table for 'tcp-request' layer 4 rules */
7759 list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) {
7760 struct proxy *target;
7761
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007762 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007763 continue;
7764
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007765 if (trule->arg.trk_ctr.table.n)
7766 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007767 else
7768 target = curproxy;
7769
7770 if (!target) {
Willy Tarreau56123282010-08-06 19:06:56 +02007771 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007772 curproxy->id, trule->arg.trk_ctr.table.n,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007773 tcp_trk_idx(trule->action));
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007774 cfgerr++;
7775 }
7776 else if (target->table.size == 0) {
7777 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007778 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007779 cfgerr++;
7780 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007781 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau5f53de72012-12-12 00:25:44 +01007782 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007783 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007784 tcp_trk_idx(trule->action));
Willy Tarreau5f53de72012-12-12 00:25:44 +01007785 cfgerr++;
7786 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007787 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007788 free(trule->arg.trk_ctr.table.n);
7789 trule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau56123282010-08-06 19:06:56 +02007790 /* Note: if we decide to enhance the track-sc syntax, we may be able
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007791 * to pass a list of counters to track and allocate them right here using
7792 * stktable_alloc_data_type().
7793 */
7794 }
7795 }
7796
Willy Tarreau620408f2016-10-21 16:37:51 +02007797 /* find the target table for 'tcp-request' layer 5 rules */
7798 list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) {
7799 struct proxy *target;
7800
7801 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
7802 continue;
7803
7804 if (trule->arg.trk_ctr.table.n)
7805 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
7806 else
7807 target = curproxy;
7808
7809 if (!target) {
7810 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
7811 curproxy->id, trule->arg.trk_ctr.table.n,
7812 tcp_trk_idx(trule->action));
7813 cfgerr++;
7814 }
7815 else if (target->table.size == 0) {
7816 Alert("Proxy '%s': table '%s' used but not configured.\n",
7817 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
7818 cfgerr++;
7819 }
7820 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
7821 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
7822 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
7823 tcp_trk_idx(trule->action));
7824 cfgerr++;
7825 }
7826 else {
7827 free(trule->arg.trk_ctr.table.n);
7828 trule->arg.trk_ctr.table.t = &target->table;
7829 /* Note: if we decide to enhance the track-sc syntax, we may be able
7830 * to pass a list of counters to track and allocate them right here using
7831 * stktable_alloc_data_type().
7832 */
7833 }
7834 }
7835
Willy Tarreaud1f96522010-08-03 19:34:32 +02007836 /* find the target table for 'tcp-request' layer 6 rules */
7837 list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
7838 struct proxy *target;
7839
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007840 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreaud1f96522010-08-03 19:34:32 +02007841 continue;
7842
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007843 if (trule->arg.trk_ctr.table.n)
7844 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
Willy Tarreaud1f96522010-08-03 19:34:32 +02007845 else
7846 target = curproxy;
7847
7848 if (!target) {
Willy Tarreau56123282010-08-06 19:06:56 +02007849 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007850 curproxy->id, trule->arg.trk_ctr.table.n,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007851 tcp_trk_idx(trule->action));
Willy Tarreaud1f96522010-08-03 19:34:32 +02007852 cfgerr++;
7853 }
7854 else if (target->table.size == 0) {
7855 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007856 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreaud1f96522010-08-03 19:34:32 +02007857 cfgerr++;
7858 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007859 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau5f53de72012-12-12 00:25:44 +01007860 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007861 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007862 tcp_trk_idx(trule->action));
Willy Tarreau5f53de72012-12-12 00:25:44 +01007863 cfgerr++;
7864 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02007865 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007866 free(trule->arg.trk_ctr.table.n);
7867 trule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau56123282010-08-06 19:06:56 +02007868 /* Note: if we decide to enhance the track-sc syntax, we may be able
Willy Tarreaud1f96522010-08-03 19:34:32 +02007869 * to pass a list of counters to track and allocate them right here using
7870 * stktable_alloc_data_type().
7871 */
7872 }
7873 }
7874
Baptiste Assmanne9544932015-11-03 23:31:35 +01007875 /* parse http-request capture rules to ensure id really exists */
7876 list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) {
7877 if (hrqrule->action != ACT_CUSTOM ||
7878 hrqrule->action_ptr != http_action_req_capture_by_id)
7879 continue;
7880
7881 if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) {
7882 Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n",
7883 curproxy->id, hrqrule->arg.capid.idx);
7884 cfgerr++;
7885 }
7886 }
7887
7888 /* parse http-response capture rules to ensure id really exists */
7889 list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) {
7890 if (hrqrule->action != ACT_CUSTOM ||
7891 hrqrule->action_ptr != http_action_res_capture_by_id)
7892 continue;
7893
7894 if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) {
7895 Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n",
7896 curproxy->id, hrqrule->arg.capid.idx);
7897 cfgerr++;
7898 }
7899 }
7900
Willy Tarreau09448f72014-06-25 18:12:15 +02007901 /* find the target table for 'http-request' layer 7 rules */
7902 list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) {
7903 struct proxy *target;
7904
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007905 if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreau09448f72014-06-25 18:12:15 +02007906 continue;
7907
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007908 if (hrqrule->arg.trk_ctr.table.n)
7909 target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n);
Willy Tarreau09448f72014-06-25 18:12:15 +02007910 else
7911 target = curproxy;
7912
7913 if (!target) {
7914 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007915 curproxy->id, hrqrule->arg.trk_ctr.table.n,
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08007916 http_trk_idx(hrqrule->action));
Willy Tarreau09448f72014-06-25 18:12:15 +02007917 cfgerr++;
7918 }
7919 else if (target->table.size == 0) {
7920 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007921 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreau09448f72014-06-25 18:12:15 +02007922 cfgerr++;
7923 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007924 else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau09448f72014-06-25 18:12:15 +02007925 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007926 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id,
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08007927 http_trk_idx(hrqrule->action));
7928 cfgerr++;
7929 }
7930 else {
7931 free(hrqrule->arg.trk_ctr.table.n);
7932 hrqrule->arg.trk_ctr.table.t = &target->table;
7933 /* Note: if we decide to enhance the track-sc syntax, we may be able
7934 * to pass a list of counters to track and allocate them right here using
7935 * stktable_alloc_data_type().
7936 */
7937 }
7938 }
7939
7940 /* find the target table for 'http-response' layer 7 rules */
7941 list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) {
7942 struct proxy *target;
7943
7944 if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX)
7945 continue;
7946
7947 if (hrqrule->arg.trk_ctr.table.n)
7948 target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n);
7949 else
7950 target = curproxy;
7951
7952 if (!target) {
7953 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
7954 curproxy->id, hrqrule->arg.trk_ctr.table.n,
7955 http_trk_idx(hrqrule->action));
7956 cfgerr++;
7957 }
7958 else if (target->table.size == 0) {
7959 Alert("Proxy '%s': table '%s' used but not configured.\n",
7960 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id);
7961 cfgerr++;
7962 }
7963 else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) {
7964 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
7965 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id,
7966 http_trk_idx(hrqrule->action));
Willy Tarreau09448f72014-06-25 18:12:15 +02007967 cfgerr++;
7968 }
7969 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007970 free(hrqrule->arg.trk_ctr.table.n);
7971 hrqrule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau09448f72014-06-25 18:12:15 +02007972 /* Note: if we decide to enhance the track-sc syntax, we may be able
7973 * to pass a list of counters to track and allocate them right here using
7974 * stktable_alloc_data_type().
7975 */
7976 }
7977 }
7978
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02007979 /* move any "block" rules at the beginning of the http-request rules */
7980 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
7981 /* insert block_rules into http_req_rules at the beginning */
7982 curproxy->block_rules.p->n = curproxy->http_req_rules.n;
7983 curproxy->http_req_rules.n->p = curproxy->block_rules.p;
7984 curproxy->block_rules.n->p = &curproxy->http_req_rules;
7985 curproxy->http_req_rules.n = curproxy->block_rules.n;
7986 LIST_INIT(&curproxy->block_rules);
7987 }
7988
Emeric Brun32da3c42010-09-23 18:39:19 +02007989 if (curproxy->table.peers.name) {
7990 struct peers *curpeers = peers;
7991
7992 for (curpeers = peers; curpeers; curpeers = curpeers->next) {
7993 if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
7994 free((void *)curproxy->table.peers.name);
Willy Tarreau973ca492013-01-17 21:34:52 +01007995 curproxy->table.peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02007996 break;
7997 }
7998 }
7999
8000 if (!curpeers) {
8001 Alert("Proxy '%s': unable to find sync peers '%s'.\n",
8002 curproxy->id, curproxy->table.peers.name);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008003 free((void *)curproxy->table.peers.name);
8004 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008005 cfgerr++;
8006 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008007 else if (curpeers->state == PR_STSTOPPED) {
8008 /* silently disable this peers section */
8009 curproxy->table.peers.p = NULL;
8010 }
Emeric Brun32da3c42010-09-23 18:39:19 +02008011 else if (!curpeers->peers_fe) {
Willy Tarreau122541c2011-09-07 21:24:49 +02008012 Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
8013 curproxy->id, localpeer, curpeers->id);
Willy Tarreaud66bf962011-10-28 14:16:49 +02008014 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02008015 cfgerr++;
8016 }
8017 }
8018
Simon Horman9dc49962015-01-30 11:22:59 +09008019
8020 if (curproxy->email_alert.mailers.name) {
8021 struct mailers *curmailers = mailers;
8022
8023 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
8024 if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) {
8025 free(curproxy->email_alert.mailers.name);
8026 curproxy->email_alert.mailers.m = curmailers;
8027 curmailers->users++;
8028 break;
8029 }
8030 }
8031
8032 if (!curmailers) {
8033 Alert("Proxy '%s': unable to find mailers '%s'.\n",
8034 curproxy->id, curproxy->email_alert.mailers.name);
8035 free_email_alert(curproxy);
8036 cfgerr++;
8037 }
8038 }
8039
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008040 if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) &&
Willy Tarreauff011f22011-01-06 17:51:27 +01008041 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008042 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
8043 Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
8044 "proxy", curproxy->id);
8045 cfgerr++;
8046 goto out_uri_auth_compat;
8047 }
8048
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008049 if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008050 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02008051 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01008052 int i = 0;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008053
Willy Tarreau95fa4692010-02-01 13:05:50 +01008054 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
8055 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008056
8057 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008058 uri_auth_compat_req[i++] = "realm";
8059 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
8060 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008061
Willy Tarreau95fa4692010-02-01 13:05:50 +01008062 uri_auth_compat_req[i++] = "unless";
8063 uri_auth_compat_req[i++] = "{";
8064 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
8065 uri_auth_compat_req[i++] = "}";
8066 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008067
Willy Tarreauff011f22011-01-06 17:51:27 +01008068 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
8069 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008070 cfgerr++;
8071 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008072 }
8073
Willy Tarreauff011f22011-01-06 17:51:27 +01008074 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01008075
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008076 if (curproxy->uri_auth->auth_realm) {
8077 free(curproxy->uri_auth->auth_realm);
8078 curproxy->uri_auth->auth_realm = NULL;
8079 }
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008080
8081 curproxy->uri_auth->flags |= ST_CONVDONE;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008082 }
8083out_uri_auth_compat:
8084
Dragan Dosen43885c72015-10-01 13:18:13 +02008085 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02008086 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02008087 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
8088 if (!curproxy->conf.logformat_sd_string) {
8089 /* set the default logformat_sd_string */
8090 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
8091 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008092 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02008093 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008094 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02008095
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008096 /* compile the log format */
8097 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02008098 if (curproxy->conf.logformat_string != default_http_log_format &&
8099 curproxy->conf.logformat_string != default_tcp_log_format &&
8100 curproxy->conf.logformat_string != clf_http_log_format)
8101 free(curproxy->conf.logformat_string);
8102 curproxy->conf.logformat_string = NULL;
8103 free(curproxy->conf.lfs_file);
8104 curproxy->conf.lfs_file = NULL;
8105 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008106
8107 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
8108 free(curproxy->conf.logformat_sd_string);
8109 curproxy->conf.logformat_sd_string = NULL;
8110 free(curproxy->conf.lfsd_file);
8111 curproxy->conf.lfsd_file = NULL;
8112 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008113 }
8114
Willy Tarreau62a61232013-04-12 18:13:46 +02008115 if (curproxy->conf.logformat_string) {
8116 curproxy->conf.args.ctx = ARGC_LOG;
8117 curproxy->conf.args.file = curproxy->conf.lfs_file;
8118 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008119 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008120 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008121 SMP_VAL_FE_LOG_END, &err)) {
8122 Alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
8123 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8124 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008125 cfgerr++;
8126 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008127 curproxy->conf.args.file = NULL;
8128 curproxy->conf.args.line = 0;
8129 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008130
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008131 if (curproxy->conf.logformat_sd_string) {
8132 curproxy->conf.args.ctx = ARGC_LOGSD;
8133 curproxy->conf.args.file = curproxy->conf.lfsd_file;
8134 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008135 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008136 if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008137 SMP_VAL_FE_LOG_END, &err)) {
8138 Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8139 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8140 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008141 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008142 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
8143 Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8144 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8145 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008146 cfgerr++;
8147 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008148 curproxy->conf.args.file = NULL;
8149 curproxy->conf.args.line = 0;
8150 }
8151
Willy Tarreau62a61232013-04-12 18:13:46 +02008152 if (curproxy->conf.uniqueid_format_string) {
8153 curproxy->conf.args.ctx = ARGC_UIF;
8154 curproxy->conf.args.file = curproxy->conf.uif_file;
8155 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008156 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008157 if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008158 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
8159 Alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
8160 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
8161 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008162 cfgerr++;
8163 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008164 curproxy->conf.args.file = NULL;
8165 curproxy->conf.args.line = 0;
8166 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008167
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01008168 /* only now we can check if some args remain unresolved.
8169 * This must be done after the users and groups resolution.
8170 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008171 cfgerr += smp_resolve_args(curproxy);
8172 if (!cfgerr)
8173 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01008174
Willy Tarreau2738a142006-07-08 17:28:09 +02008175 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008176 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02008177 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02008178 (!curproxy->timeout.connect ||
8179 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008180 Warning("config : missing timeouts for %s '%s'.\n"
Willy Tarreau2738a142006-07-08 17:28:09 +02008181 " | While not properly invalid, you will certainly encounter various problems\n"
8182 " | with such a configuration. To fix this, please ensure that all following\n"
Willy Tarreau0f68eac2008-01-20 23:25:06 +01008183 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008184 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008185 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02008186 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02008187
Willy Tarreau1fa31262007-12-03 00:36:16 +01008188 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
8189 * We must still support older configurations, so let's find out whether those
8190 * parameters have been set or must be copied from contimeouts.
8191 */
8192 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008193 if (!curproxy->timeout.tarpit ||
8194 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008195 /* tarpit timeout not set. We search in the following order:
8196 * default.tarpit, curr.connect, default.connect.
8197 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008198 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008199 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008200 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008201 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008202 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008203 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008204 }
8205 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008206 (!curproxy->timeout.queue ||
8207 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008208 /* queue timeout not set. We search in the following order:
8209 * default.queue, curr.connect, default.connect.
8210 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008211 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008212 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008213 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008214 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008215 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008216 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008217 }
8218 }
8219
Willy Tarreau1620ec32011-08-06 17:05:02 +02008220 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) {
Willy Tarreau137325d2010-02-01 16:38:17 +01008221 curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02008222 curproxy->check_req = malloc(curproxy->check_len);
Willy Tarreau137325d2010-02-01 16:38:17 +01008223 memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len);
Willy Tarreauf3c69202006-07-09 16:42:34 +02008224 }
8225
Willy Tarreau215663d2014-06-13 18:30:23 +02008226 if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) &&
8227 (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) {
8228 Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
8229 proxy_type_str(curproxy), curproxy->id);
8230 err_code |= ERR_WARN;
8231 }
8232
Willy Tarreau193b8c62012-11-22 00:17:38 +01008233 /* ensure that cookie capture length is not too large */
8234 if (curproxy->capture_len >= global.tune.cookie_len) {
8235 Warning("config : truncating capture length to %d bytes for %s '%s'.\n",
8236 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
8237 err_code |= ERR_WARN;
8238 curproxy->capture_len = global.tune.cookie_len - 1;
8239 }
8240
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008241 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01008242 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008243 curproxy->req_cap_pool = create_pool("ptrcap",
8244 curproxy->nb_req_cap * sizeof(char *),
8245 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008246 }
8247
8248 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008249 curproxy->rsp_cap_pool = create_pool("ptrcap",
8250 curproxy->nb_rsp_cap * sizeof(char *),
8251 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008252 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008253
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008254 switch (curproxy->load_server_state_from_file) {
8255 case PR_SRV_STATE_FILE_UNSPEC:
8256 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
8257 break;
8258 case PR_SRV_STATE_FILE_GLOBAL:
8259 if (!global.server_state_file) {
8260 Warning("config : backend '%s' configured to load server state file from global section 'server-state-file' directive. Unfortunately, 'server-state-file' is not set!\n",
8261 curproxy->id);
8262 err_code |= ERR_WARN;
8263 }
8264 break;
8265 }
8266
Willy Tarreaubaaee002006-06-26 02:48:02 +02008267 /* first, we will invert the servers list order */
8268 newsrv = NULL;
8269 while (curproxy->srv) {
8270 struct server *next;
8271
8272 next = curproxy->srv->next;
8273 curproxy->srv->next = newsrv;
8274 newsrv = curproxy->srv;
8275 if (!next)
8276 break;
8277 curproxy->srv = next;
8278 }
8279
Willy Tarreau17edc812014-01-03 12:14:34 +01008280 /* Check that no server name conflicts. This causes trouble in the stats.
8281 * We only emit a warning for the first conflict affecting each server,
8282 * in order to avoid combinatory explosion if all servers have the same
8283 * name. We do that only for servers which do not have an explicit ID,
8284 * because these IDs were made also for distinguishing them and we don't
8285 * want to annoy people who correctly manage them.
8286 */
8287 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8288 struct server *other_srv;
8289
8290 if (newsrv->puid)
8291 continue;
8292
8293 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
8294 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
8295 Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n",
8296 newsrv->conf.file, newsrv->conf.line,
8297 proxy_type_str(curproxy), curproxy->id,
8298 newsrv->id, other_srv->conf.line);
8299 break;
8300 }
8301 }
8302 }
8303
Willy Tarreaudd701652010-05-25 23:03:02 +02008304 /* assign automatic UIDs to servers which don't have one yet */
8305 next_id = 1;
8306 newsrv = curproxy->srv;
8307 while (newsrv != NULL) {
8308 if (!newsrv->puid) {
8309 /* server ID not set, use automatic numbering with first
8310 * spare entry starting with next_svid.
8311 */
8312 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
8313 newsrv->conf.id.key = newsrv->puid = next_id;
8314 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
8315 }
8316 next_id++;
8317 newsrv = newsrv->next;
8318 }
8319
Willy Tarreau20697042007-11-15 23:26:18 +01008320 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01008321 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02008322
Willy Tarreau62c3be22012-01-20 13:12:32 +01008323 /*
8324 * If this server supports a maxconn parameter, it needs a dedicated
8325 * tasks to fill the emptied slots when a connection leaves.
8326 * Also, resolve deferred tracking dependency if needed.
8327 */
8328 newsrv = curproxy->srv;
8329 while (newsrv != NULL) {
8330 if (newsrv->minconn > newsrv->maxconn) {
8331 /* Only 'minconn' was specified, or it was higher than or equal
8332 * to 'maxconn'. Let's turn this into maxconn and clean it, as
8333 * this will avoid further useless expensive computations.
8334 */
8335 newsrv->maxconn = newsrv->minconn;
8336 } else if (newsrv->maxconn && !newsrv->minconn) {
8337 /* minconn was not specified, so we set it to maxconn */
8338 newsrv->minconn = newsrv->maxconn;
8339 }
8340
Willy Tarreau17d45382016-12-22 21:16:08 +01008341 /* this will also properly set the transport layer for prod and checks */
8342 if (newsrv->use_ssl || newsrv->check.use_ssl) {
8343 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
8344 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
8345 }
Emeric Brun94324a42012-10-11 14:00:19 +02008346
Willy Tarreau2f075e92013-12-03 11:11:34 +01008347 /* set the check type on the server */
8348 newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
8349
Willy Tarreau62c3be22012-01-20 13:12:32 +01008350 if (newsrv->trackit) {
8351 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02008352 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008353 char *pname, *sname;
8354
8355 pname = newsrv->trackit;
8356 sname = strrchr(pname, '/');
8357
8358 if (sname)
8359 *sname++ = '\0';
8360 else {
8361 sname = pname;
8362 pname = NULL;
8363 }
8364
8365 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02008366 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008367 if (!px) {
8368 Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
8369 proxy_type_str(curproxy), curproxy->id,
8370 newsrv->id, pname);
8371 cfgerr++;
8372 goto next_srv;
8373 }
8374 } else
8375 px = curproxy;
8376
8377 srv = findserver(px, sname);
8378 if (!srv) {
8379 Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
8380 proxy_type_str(curproxy), curproxy->id,
8381 newsrv->id, sname);
8382 cfgerr++;
8383 goto next_srv;
8384 }
8385
Willy Tarreau32091232014-05-16 13:52:00 +02008386 if (!(srv->check.state & CHK_ST_CONFIGURED) &&
8387 !(srv->agent.state & CHK_ST_CONFIGURED) &&
8388 !srv->track && !srv->trackit) {
Willy Tarreau62c3be22012-01-20 13:12:32 +01008389 Alert("config : %s '%s', server '%s': unable to use %s/%s for "
Willy Tarreau32091232014-05-16 13:52:00 +02008390 "tracking as it does not have any check nor agent enabled.\n",
8391 proxy_type_str(curproxy), curproxy->id,
8392 newsrv->id, px->id, srv->id);
8393 cfgerr++;
8394 goto next_srv;
8395 }
8396
8397 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
8398
8399 if (loop) {
8400 Alert("config : %s '%s', server '%s': unable to track %s/%s as it "
8401 "belongs to a tracking chain looping back to %s/%s.\n",
8402 proxy_type_str(curproxy), curproxy->id,
8403 newsrv->id, px->id, srv->id, px->id, loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008404 cfgerr++;
8405 goto next_srv;
8406 }
8407
8408 if (curproxy != px &&
8409 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
8410 Alert("config : %s '%s', server '%s': unable to use %s/%s for"
8411 "tracking: disable-on-404 option inconsistency.\n",
8412 proxy_type_str(curproxy), curproxy->id,
8413 newsrv->id, px->id, srv->id);
8414 cfgerr++;
8415 goto next_srv;
8416 }
8417
Willy Tarreau62c3be22012-01-20 13:12:32 +01008418 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01008419 newsrv->tracknext = srv->trackers;
8420 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008421
8422 free(newsrv->trackit);
8423 newsrv->trackit = NULL;
8424 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02008425
8426 /*
8427 * resolve server's resolvers name and update the resolvers pointer
8428 * accordingly
8429 */
8430 if (newsrv->resolvers_id) {
8431 struct dns_resolvers *curr_resolvers;
8432 int found;
8433
8434 found = 0;
8435 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
8436 if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) {
8437 found = 1;
8438 break;
8439 }
8440 }
8441
8442 if (!found) {
8443 Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n",
8444 proxy_type_str(curproxy), curproxy->id,
8445 newsrv->id, newsrv->resolvers_id);
8446 cfgerr++;
8447 } else {
8448 free(newsrv->resolvers_id);
8449 newsrv->resolvers_id = NULL;
8450 if (newsrv->resolution)
8451 newsrv->resolution->resolvers = curr_resolvers;
8452 }
8453 }
8454 else {
8455 /* if no resolvers section associated to this server
8456 * we can clean up the associated resolution structure
8457 */
8458 if (newsrv->resolution) {
8459 free(newsrv->resolution->hostname_dn);
8460 newsrv->resolution->hostname_dn = NULL;
8461 free(newsrv->resolution);
8462 newsrv->resolution = NULL;
8463 }
8464 }
8465
Willy Tarreau62c3be22012-01-20 13:12:32 +01008466 next_srv:
8467 newsrv = newsrv->next;
8468 }
8469
Olivier Houchard4e694042017-03-14 20:01:29 +01008470 /*
8471 * Try to generate dynamic cookies for servers now.
8472 * It couldn't be done earlier, since at the time we parsed
8473 * the server line, we may not have known yet that we
8474 * should use dynamic cookies, or the secret key may not
8475 * have been provided yet.
8476 */
8477 if (curproxy->ck_opts & PR_CK_DYNAMIC) {
8478 newsrv = curproxy->srv;
8479 while (newsrv != NULL) {
8480 srv_set_dyncookie(newsrv);
8481 newsrv = newsrv->next;
8482 }
8483
8484 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008485 /* We have to initialize the server lookup mechanism depending
8486 * on what LB algorithm was choosen.
8487 */
8488
8489 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
8490 switch (curproxy->lbprm.algo & BE_LB_KIND) {
8491 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02008492 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
8493 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8494 init_server_map(curproxy);
8495 } else {
8496 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
8497 fwrr_init_server_groups(curproxy);
8498 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008499 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008500
Willy Tarreau3ebb1162012-02-13 16:57:44 +01008501 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01008502 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
8503 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
8504 fwlc_init_server_tree(curproxy);
8505 } else {
8506 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
8507 fas_init_server_tree(curproxy);
8508 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008509 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008510
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008511 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008512 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
8513 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8514 chash_init_server_tree(curproxy);
8515 } else {
8516 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8517 init_server_map(curproxy);
8518 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008519 break;
8520 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02008521
8522 if (curproxy->options & PR_O_LOGASAP)
8523 curproxy->to_log &= ~LW_BYTES;
8524
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008525 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008526 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
8527 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008528 Warning("config : log format ignored for %s '%s' since it has no log address.\n",
8529 proxy_type_str(curproxy), curproxy->id);
8530 err_code |= ERR_WARN;
8531 }
8532
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008533 if (curproxy->mode != PR_MODE_HTTP) {
8534 int optnum;
8535
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008536 if (curproxy->uri_auth) {
8537 Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
8538 proxy_type_str(curproxy), curproxy->id);
8539 err_code |= ERR_WARN;
8540 curproxy->uri_auth = NULL;
8541 }
8542
Willy Tarreaude7dc882017-03-10 11:49:21 +01008543 if (curproxy->capture_name) {
8544 Warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n",
8545 proxy_type_str(curproxy), curproxy->id);
8546 err_code |= ERR_WARN;
8547 }
8548
8549 if (!LIST_ISEMPTY(&curproxy->http_req_rules)) {
8550 Warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n",
8551 proxy_type_str(curproxy), curproxy->id);
8552 err_code |= ERR_WARN;
8553 }
8554
8555 if (!LIST_ISEMPTY(&curproxy->http_res_rules)) {
8556 Warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n",
8557 proxy_type_str(curproxy), curproxy->id);
8558 err_code |= ERR_WARN;
8559 }
8560
8561 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
8562 Warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n",
8563 proxy_type_str(curproxy), curproxy->id);
8564 err_code |= ERR_WARN;
8565 }
8566
8567 if (!LIST_ISEMPTY(&curproxy->redirect_rules)) {
8568 Warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n",
8569 proxy_type_str(curproxy), curproxy->id);
8570 err_code |= ERR_WARN;
8571 }
8572
Willy Tarreau87cf5142011-08-19 22:57:24 +02008573 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008574 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8575 "forwardfor", proxy_type_str(curproxy), curproxy->id);
8576 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02008577 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008578 }
8579
8580 if (curproxy->options & PR_O_ORGTO) {
8581 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8582 "originalto", proxy_type_str(curproxy), curproxy->id);
8583 err_code |= ERR_WARN;
8584 curproxy->options &= ~PR_O_ORGTO;
8585 }
8586
8587 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
8588 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
8589 (curproxy->cap & cfg_opts[optnum].cap) &&
8590 (curproxy->options & cfg_opts[optnum].val)) {
8591 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8592 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
8593 err_code |= ERR_WARN;
8594 curproxy->options &= ~cfg_opts[optnum].val;
8595 }
8596 }
8597
8598 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
8599 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
8600 (curproxy->cap & cfg_opts2[optnum].cap) &&
8601 (curproxy->options2 & cfg_opts2[optnum].val)) {
8602 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8603 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
8604 err_code |= ERR_WARN;
8605 curproxy->options2 &= ~cfg_opts2[optnum].val;
8606 }
8607 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008608
Willy Tarreau29fbe512015-08-20 19:35:14 +02008609#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008610 if (curproxy->conn_src.bind_hdr_occ) {
8611 curproxy->conn_src.bind_hdr_occ = 0;
Willy Tarreaubce70882009-09-07 11:51:47 +02008612 Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
Willy Tarreauef9a3602012-12-08 22:29:20 +01008613 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008614 err_code |= ERR_WARN;
8615 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008616#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008617 }
8618
Willy Tarreaubaaee002006-06-26 02:48:02 +02008619 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01008620 * ensure that we're not cross-dressing a TCP server into HTTP.
8621 */
8622 newsrv = curproxy->srv;
8623 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01008624 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008625 Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
8626 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008627 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01008628 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008629
Willy Tarreau0cec3312011-10-31 13:49:26 +01008630 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
8631 Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
8632 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8633 err_code |= ERR_WARN;
8634 }
8635
Willy Tarreauc93cd162014-05-13 15:54:22 +02008636 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Willy Tarreau82ffa392013-08-13 17:19:08 +02008637 Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
8638 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8639 err_code |= ERR_WARN;
8640 }
8641
Willy Tarreau29fbe512015-08-20 19:35:14 +02008642#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008643 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
8644 newsrv->conn_src.bind_hdr_occ = 0;
Willy Tarreaubce70882009-09-07 11:51:47 +02008645 Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n",
Willy Tarreauef9a3602012-12-08 22:29:20 +01008646 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008647 err_code |= ERR_WARN;
8648 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008649#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01008650
8651 if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) {
8652 if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8653 (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP ||
8654 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8655 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) {
8656 Warning("config : %s '%s' : connections to server '%s' use the client's IP address as the source while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'usesrc' and to use the 'forwardfor' option instead.\n",
8657 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8658 err_code |= ERR_WARN;
8659 }
8660
8661
8662 if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) {
8663 Warning("config : %s '%s' : connections to server '%s' will have a PROXY protocol header announcing the first client's IP address while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'send-proxy' and to use the 'forwardfor' option instead.\n",
8664 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8665 err_code |= ERR_WARN;
8666 }
8667 }
8668
Willy Tarreau21d2af32008-02-14 20:25:24 +01008669 newsrv = newsrv->next;
8670 }
8671
Willy Tarreaue42bd962014-09-16 16:21:19 +02008672 /* check if we have a frontend with "tcp-request content" looking at L7
8673 * with no inspect-delay
8674 */
8675 if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) {
8676 list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02008677 if (trule->action == ACT_TCP_CAPTURE &&
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +02008678 !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008679 break;
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02008680 if ((trule->action >= ACT_ACTION_TRK_SC0 && trule->action <= ACT_ACTION_TRK_SCMAX) &&
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02008681 !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008682 break;
8683 }
8684
8685 if (&trule->list != &curproxy->tcp_req.inspect_rules) {
8686 Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request"
8687 " contents were found in a frontend without any 'tcp-request inspect-delay' setting."
8688 " This means that these rules will randomly find their contents. This can be fixed by"
8689 " setting the tcp-request inspect-delay.\n",
8690 proxy_type_str(curproxy), curproxy->id);
8691 err_code |= ERR_WARN;
8692 }
8693 }
8694
Christopher Fauletd7c91962015-04-30 11:48:27 +02008695 /* Check filter configuration, if any */
8696 cfgerr += flt_check(curproxy);
8697
Willy Tarreauc1a21672009-08-16 22:37:44 +02008698 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02008699 if (!curproxy->accept)
8700 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02008701
Willy Tarreauc1a21672009-08-16 22:37:44 +02008702 if (curproxy->tcp_req.inspect_delay ||
8703 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02008704 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008705
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008706 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008707 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008708 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008709 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008710
8711 /* both TCP and HTTP must check switching rules */
8712 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008713
8714 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008715 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008716 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8717 curproxy->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END;
Christopher Faulet309c6412015-12-02 09:57:32 +01008718 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008719 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8720 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008721 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008722 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008723 }
8724
8725 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02008726 if (curproxy->tcp_req.inspect_delay ||
8727 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
8728 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
8729
Emeric Brun97679e72010-09-23 17:56:44 +02008730 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
8731 curproxy->be_rsp_ana |= AN_RES_INSPECT;
8732
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008733 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008734 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008735 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008736 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008737
8738 /* If the backend does requires RDP cookie persistence, we have to
8739 * enable the corresponding analyser.
8740 */
8741 if (curproxy->options2 & PR_O2_RDPC_PRST)
8742 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008743
8744 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008745 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008746 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8747 curproxy->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END;
Christopher Faulet309c6412015-12-02 09:57:32 +01008748 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008749 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8750 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008751 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008752 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008753 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008754 }
8755
8756 /***********************************************************/
8757 /* At this point, target names have already been resolved. */
8758 /***********************************************************/
8759
8760 /* Check multi-process mode compatibility */
8761
8762 if (global.nbproc > 1 && global.stats_fe) {
8763 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8764 unsigned long mask;
8765
8766 mask = nbits(global.nbproc);
8767 if (global.stats_fe->bind_proc)
8768 mask &= global.stats_fe->bind_proc;
8769
8770 if (bind_conf->bind_proc)
8771 mask &= bind_conf->bind_proc;
8772
8773 /* stop here if more than one process is used */
David Carliere6c39412015-07-02 07:00:17 +00008774 if (my_popcountl(mask) > 1)
Willy Tarreau419ead82014-09-16 13:41:21 +02008775 break;
8776 }
8777 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
8778 Warning("stats socket will not work as expected in multi-process mode (nbproc > 1), you should force process binding globally using 'stats bind-process' or per socket using the 'process' attribute.\n");
8779 }
8780 }
8781
8782 /* Make each frontend inherit bind-process from its listeners when not specified. */
8783 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8784 if (curproxy->bind_proc)
8785 continue;
8786
8787 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8788 unsigned long mask;
8789
Willy Tarreaue428b082015-05-04 21:57:58 +02008790 mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008791 curproxy->bind_proc |= mask;
8792 }
8793
8794 if (!curproxy->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008795 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008796 }
8797
8798 if (global.stats_fe) {
8799 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8800 unsigned long mask;
8801
Cyril Bonté06181952016-02-24 00:14:54 +01008802 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02008803 global.stats_fe->bind_proc |= mask;
8804 }
8805 if (!global.stats_fe->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008806 global.stats_fe->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008807 }
8808
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008809 /* propagate bindings from frontends to backends. Don't do it if there
8810 * are any fatal errors as we must not call it with unresolved proxies.
8811 */
8812 if (!cfgerr) {
8813 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8814 if (curproxy->cap & PR_CAP_FE)
8815 propagate_processes(curproxy, NULL);
8816 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008817 }
8818
8819 /* Bind each unbound backend to all processes when not specified. */
8820 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8821 if (curproxy->bind_proc)
8822 continue;
Willy Tarreaue428b082015-05-04 21:57:58 +02008823 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008824 }
8825
8826 /*******************************************************/
8827 /* At this step, all proxies have a non-null bind_proc */
8828 /*******************************************************/
8829
8830 /* perform the final checks before creating tasks */
8831
8832 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8833 struct listener *listener;
8834 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008835
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008836 /* Configure SSL for each bind line.
8837 * Note: if configuration fails at some point, the ->ctx member
8838 * remains NULL so that listeners can later detach.
8839 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008840 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01008841 if (bind_conf->xprt->prepare_bind_conf &&
8842 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008843 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008844 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008845
Willy Tarreaue6b98942007-10-29 01:09:36 +01008846 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008847 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02008848 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008849 int nbproc;
8850
8851 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02008852 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008853 nbits(global.nbproc));
8854
8855 if (!nbproc) /* no intersection between listener and frontend */
8856 nbproc = 1;
8857
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008858 if (!listener->luid) {
8859 /* listener ID not set, use automatic numbering with first
8860 * spare entry starting with next_luid.
8861 */
8862 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
8863 listener->conf.id.key = listener->luid = next_id;
8864 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008865 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01008866 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008867
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008868 /* enable separate counters */
8869 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01008870 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01008871 if (!listener->name)
8872 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008873 }
Willy Tarreau81796be2012-09-22 19:11:47 +02008874
Willy Tarreaue6b98942007-10-29 01:09:36 +01008875 if (curproxy->options & PR_O_TCP_NOLING)
8876 listener->options |= LI_O_NOLINGER;
Willy Tarreau32368ce2012-09-06 11:10:55 +02008877 if (!listener->maxconn)
8878 listener->maxconn = curproxy->maxconn;
8879 if (!listener->backlog)
8880 listener->backlog = curproxy->backlog;
Willy Tarreau16a21472012-11-19 12:39:59 +01008881 if (!listener->maxaccept)
8882 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
8883
8884 /* we want to have an optimal behaviour on single process mode to
8885 * maximize the work at once, but in multi-process we want to keep
8886 * some fairness between processes, so we target half of the max
8887 * number of events to be balanced over all the processes the proxy
8888 * is bound to. Rememeber that maxaccept = -1 must be kept as it is
8889 * used to disable the limit.
8890 */
8891 if (listener->maxaccept > 0) {
8892 if (nbproc > 1)
8893 listener->maxaccept = (listener->maxaccept + 1) / 2;
8894 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
8895 }
8896
Willy Tarreau9903f0e2015-04-04 18:50:31 +02008897 listener->accept = session_accept_fd;
Willy Tarreau87b09662015-04-03 00:22:06 +02008898 listener->handler = process_stream;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008899 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01008900 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01008901
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008902 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02008903 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008904
Willy Tarreau620408f2016-10-21 16:37:51 +02008905 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
8906 listener->options |= LI_O_TCP_L5_RULES;
8907
Willy Tarreaude3041d2010-05-31 10:56:17 +02008908 if (curproxy->mon_mask.s_addr)
8909 listener->options |= LI_O_CHK_MONNET;
8910
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008911 /* smart accept mode is automatic in HTTP mode */
8912 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008913 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008914 !(curproxy->no_options2 & PR_O2_SMARTACC)))
8915 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01008916 }
8917
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008918 /* Release unused SSL configs */
8919 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01008920 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
8921 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008922 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008923
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008924 if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) {
Willy Tarreau102df612014-05-07 23:56:38 +02008925 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02008926 int count, maxproc = 0;
8927
8928 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00008929 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02008930 if (count > maxproc)
8931 maxproc = count;
8932 }
8933 /* backends have 0, frontends have 1 or more */
8934 if (maxproc != 1)
8935 Warning("Proxy '%s': in multi-process mode, stats will be"
8936 " limited to process assigned to the current request.\n",
8937 curproxy->id);
8938
Willy Tarreau102df612014-05-07 23:56:38 +02008939 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
8940 Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
8941 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008942 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008943 }
Willy Tarreau102df612014-05-07 23:56:38 +02008944 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
8945 Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
8946 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008947 }
8948 }
Willy Tarreau918ff602011-07-25 16:33:49 +02008949
8950 /* create the task associated with the proxy */
8951 curproxy->task = task_new();
8952 if (curproxy->task) {
8953 curproxy->task->context = curproxy;
8954 curproxy->task->process = manage_proxy;
8955 /* no need to queue, it will be done automatically if some
8956 * listener gets limited.
8957 */
8958 curproxy->task->expire = TICK_ETERNITY;
8959 } else {
8960 Alert("Proxy '%s': no more memory when trying to allocate the management task\n",
8961 curproxy->id);
8962 cfgerr++;
8963 }
Willy Tarreaub369a042014-09-16 13:21:03 +02008964 }
8965
Willy Tarreaufbb78422011-06-05 15:38:35 +02008966 /* automatically compute fullconn if not set. We must not do it in the
8967 * loop above because cross-references are not yet fully resolved.
8968 */
8969 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8970 /* If <fullconn> is not set, let's set it to 10% of the sum of
8971 * the possible incoming frontend's maxconns.
8972 */
8973 if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02008974 /* we have the sum of the maxconns in <total>. We only
8975 * keep 10% of that sum to set the default fullconn, with
8976 * a hard minimum of 1 (to avoid a divide by zero).
8977 */
Emeric Brun3f783572017-01-12 11:21:28 +01008978 curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10;
Willy Tarreaufbb78422011-06-05 15:38:35 +02008979 if (!curproxy->fullconn)
8980 curproxy->fullconn = 1;
8981 }
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01008982 }
8983
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008984 /*
8985 * Recount currently required checks.
8986 */
8987
8988 for (curproxy=proxy; curproxy; curproxy=curproxy->next) {
8989 int optnum;
8990
Willy Tarreau66aa61f2009-01-18 21:44:07 +01008991 for (optnum = 0; cfg_opts[optnum].name; optnum++)
8992 if (curproxy->options & cfg_opts[optnum].val)
8993 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008994
Willy Tarreau66aa61f2009-01-18 21:44:07 +01008995 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
8996 if (curproxy->options2 & cfg_opts2[optnum].val)
8997 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008998 }
8999
Willy Tarreau0fca4832015-05-01 19:12:05 +02009000 /* compute the required process bindings for the peers */
9001 for (curproxy = proxy; curproxy; curproxy = curproxy->next)
9002 if (curproxy->table.peers.p)
9003 curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
9004
Willy Tarreau122541c2011-09-07 21:24:49 +02009005 if (peers) {
9006 struct peers *curpeers = peers, **last;
9007 struct peer *p, *pb;
9008
Willy Tarreau1e273012015-05-01 19:15:17 +02009009 /* Remove all peers sections which don't have a valid listener,
9010 * which are not used by any table, or which are bound to more
9011 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02009012 */
9013 last = &peers;
9014 while (*last) {
9015 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009016
9017 if (curpeers->state == PR_STSTOPPED) {
9018 /* the "disabled" keyword was present */
9019 if (curpeers->peers_fe)
9020 stop_proxy(curpeers->peers_fe);
9021 curpeers->peers_fe = NULL;
9022 }
9023 else if (!curpeers->peers_fe) {
9024 Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
9025 curpeers->id, localpeer);
9026 }
David Carliere6c39412015-07-02 07:00:17 +00009027 else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) {
Willy Tarreau1e273012015-05-01 19:15:17 +02009028 /* either it's totally stopped or too much used */
9029 if (curpeers->peers_fe->bind_proc) {
9030 Alert("Peers section '%s': peers referenced by sections "
Willy Tarreau64c57222015-05-04 21:48:51 +02009031 "running in different processes (%d different ones). "
9032 "Check global.nbproc and all tables' bind-process "
David Carliere6c39412015-07-02 07:00:17 +00009033 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02009034 cfgerr++;
9035 }
9036 stop_proxy(curpeers->peers_fe);
9037 curpeers->peers_fe = NULL;
9038 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009039 else {
Emeric Brunb3971ab2015-05-12 18:49:09 +02009040 peers_init_sync(curpeers);
Willy Tarreau122541c2011-09-07 21:24:49 +02009041 last = &curpeers->next;
9042 continue;
9043 }
9044
Willy Tarreau77e4bd12015-05-01 20:02:17 +02009045 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02009046 p = curpeers->remote;
9047 while (p) {
9048 pb = p->next;
9049 free(p->id);
9050 free(p);
9051 p = pb;
9052 }
9053
9054 /* Destroy and unlink this curpeers section.
9055 * Note: curpeers is backed up into *last.
9056 */
9057 free(curpeers->id);
9058 curpeers = curpeers->next;
9059 free(*last);
9060 *last = curpeers;
9061 }
9062 }
9063
Willy Tarreau6866f3f2015-05-01 19:09:08 +02009064 /* initialize stick-tables on backend capable proxies. This must not
9065 * be done earlier because the data size may be discovered while parsing
9066 * other proxies.
9067 */
9068 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
9069 if (curproxy->state == PR_STSTOPPED)
9070 continue;
9071
9072 if (!stktable_init(&curproxy->table)) {
9073 Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
9074 cfgerr++;
9075 }
9076 }
9077
Simon Horman0d16a402015-01-30 11:22:58 +09009078 if (mailers) {
9079 struct mailers *curmailers = mailers, **last;
9080 struct mailer *m, *mb;
9081
9082 /* Remove all mailers sections which don't have a valid listener.
9083 * This can happen when a mailers section is never referenced.
9084 */
9085 last = &mailers;
9086 while (*last) {
9087 curmailers = *last;
9088 if (curmailers->users) {
9089 last = &curmailers->next;
9090 continue;
9091 }
9092
9093 Warning("Removing incomplete section 'mailers %s'.\n",
9094 curmailers->id);
9095
9096 m = curmailers->mailer_list;
9097 while (m) {
9098 mb = m->next;
9099 free(m->id);
9100 free(m);
9101 m = mb;
9102 }
9103
9104 /* Destroy and unlink this curmailers section.
9105 * Note: curmailers is backed up into *last.
9106 */
9107 free(curmailers->id);
9108 curmailers = curmailers->next;
9109 free(*last);
9110 *last = curmailers;
9111 }
9112 }
9113
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009114 /* Update server_state_file_name to backend name if backend is supposed to use
9115 * a server-state file locally defined and none has been provided */
9116 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
9117 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
9118 curproxy->server_state_file_name == NULL)
9119 curproxy->server_state_file_name = strdup(curproxy->id);
9120 }
9121
Willy Tarreau34eb6712011-10-24 18:15:04 +02009122 pool2_hdr_idx = create_pool("hdr_idx",
Willy Tarreauac1932d2011-10-24 19:14:41 +02009123 global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
Willy Tarreau34eb6712011-10-24 18:15:04 +02009124 MEM_F_SHARED);
9125
Willy Tarreaubb925012009-07-23 13:36:36 +02009126 if (cfgerr > 0)
9127 err_code |= ERR_ALERT | ERR_FATAL;
9128 out:
9129 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02009130}
9131
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009132/*
9133 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
9134 * parsing sessions.
9135 */
9136void cfg_register_keywords(struct cfg_kw_list *kwl)
9137{
9138 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
9139}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009140
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009141/*
9142 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
9143 */
9144void cfg_unregister_keywords(struct cfg_kw_list *kwl)
9145{
9146 LIST_DEL(&kwl->list);
9147 LIST_INIT(&kwl->list);
9148}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009149
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009150/* this function register new section in the haproxy configuration file.
9151 * <section_name> is the name of this new section and <section_parser>
9152 * is the called parser. If two section declaration have the same name,
9153 * only the first declared is used.
9154 */
9155int cfg_register_section(char *section_name,
9156 int (*section_parser)(const char *, int, char **, int))
9157{
9158 struct cfg_section *cs;
9159
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009160 list_for_each_entry(cs, &sections, list) {
9161 if (strcmp(cs->section_name, section_name) == 0) {
9162 Alert("register section '%s': already registered.\n", section_name);
9163 return 0;
9164 }
9165 }
9166
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009167 cs = calloc(1, sizeof(*cs));
9168 if (!cs) {
9169 Alert("register section '%s': out of memory.\n", section_name);
9170 return 0;
9171 }
9172
9173 cs->section_name = section_name;
9174 cs->section_parser = section_parser;
9175
9176 LIST_ADDQ(&sections, &cs->list);
9177
9178 return 1;
9179}
9180
Willy Tarreaubaaee002006-06-26 02:48:02 +02009181/*
David Carlier845efb52015-09-25 11:49:18 +01009182 * free all config section entries
9183 */
9184void cfg_unregister_sections(void)
9185{
9186 struct cfg_section *cs, *ics;
9187
9188 list_for_each_entry_safe(cs, ics, &sections, list) {
9189 LIST_DEL(&cs->list);
9190 free(cs);
9191 }
9192}
9193
Christopher Faulet7110b402016-10-26 11:09:44 +02009194void cfg_backup_sections(struct list *backup_sections)
9195{
9196 struct cfg_section *cs, *ics;
9197
9198 list_for_each_entry_safe(cs, ics, &sections, list) {
9199 LIST_DEL(&cs->list);
9200 LIST_ADDQ(backup_sections, &cs->list);
9201 }
9202}
9203
9204void cfg_restore_sections(struct list *backup_sections)
9205{
9206 struct cfg_section *cs, *ics;
9207
9208 list_for_each_entry_safe(cs, ics, backup_sections, list) {
9209 LIST_DEL(&cs->list);
9210 LIST_ADDQ(&sections, &cs->list);
9211 }
9212}
9213
Willy Tarreau659fbf02016-05-26 17:55:28 +02009214__attribute__((constructor))
9215static void cfgparse_init(void)
9216{
9217 /* Register internal sections */
9218 cfg_register_section("listen", cfg_parse_listen);
9219 cfg_register_section("frontend", cfg_parse_listen);
9220 cfg_register_section("backend", cfg_parse_listen);
9221 cfg_register_section("defaults", cfg_parse_listen);
9222 cfg_register_section("global", cfg_parse_global);
9223 cfg_register_section("userlist", cfg_parse_users);
9224 cfg_register_section("peers", cfg_parse_peers);
9225 cfg_register_section("mailers", cfg_parse_mailers);
9226 cfg_register_section("namespace_list", cfg_parse_netns);
9227 cfg_register_section("resolvers", cfg_parse_resolvers);
9228}
9229
David Carlier845efb52015-09-25 11:49:18 +01009230/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02009231 * Local variables:
9232 * c-indent-level: 8
9233 * c-basic-offset: 8
9234 * End:
9235 */