blob: 54869608da034fad8bab65e1715a6875039b9ba6 [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;
Willy Tarreau4d187ac2009-12-03 23:13:06 +01002635 if (defproxy.cookie_domain)
2636 curproxy->cookie_domain = strdup(defproxy.cookie_domain);
Willy Tarreau01732802007-11-01 22:48:15 +01002637
Willy Tarreau31936852010-10-06 16:59:56 +02002638 if (defproxy.cookie_maxidle)
2639 curproxy->cookie_maxidle = defproxy.cookie_maxidle;
2640
2641 if (defproxy.cookie_maxlife)
2642 curproxy->cookie_maxlife = defproxy.cookie_maxlife;
2643
Emeric Brun647caf12009-06-30 17:57:00 +02002644 if (defproxy.rdp_cookie_name)
2645 curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name);
2646 curproxy->rdp_cookie_len = defproxy.rdp_cookie_len;
2647
Willy Tarreau01732802007-11-01 22:48:15 +01002648 if (defproxy.url_param_name)
2649 curproxy->url_param_name = strdup(defproxy.url_param_name);
2650 curproxy->url_param_len = defproxy.url_param_len;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01002651
Benoitaffb4812009-03-25 13:02:10 +01002652 if (defproxy.hh_name)
2653 curproxy->hh_name = strdup(defproxy.hh_name);
2654 curproxy->hh_len = defproxy.hh_len;
2655 curproxy->hh_match_domain = defproxy.hh_match_domain;
2656
Willy Tarreauef9a3602012-12-08 22:29:20 +01002657 if (defproxy.conn_src.iface_name)
2658 curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name);
2659 curproxy->conn_src.iface_len = defproxy.conn_src.iface_len;
Godbach9f048532013-04-23 15:27:57 +08002660 curproxy->conn_src.opts = defproxy.conn_src.opts;
Willy Tarreau29fbe512015-08-20 19:35:14 +02002661#if defined(CONFIG_HAP_TRANSPARENT)
Godbach9f048532013-04-23 15:27:57 +08002662 curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr;
Willy Tarreauc621d362013-04-25 17:35:22 +02002663#endif
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02002664 curproxy->load_server_state_from_file = defproxy.load_server_state_from_file;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002665 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002666
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02002667 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002668 if (defproxy.capture_name)
2669 curproxy->capture_name = strdup(defproxy.capture_name);
2670 curproxy->capture_namelen = defproxy.capture_namelen;
2671 curproxy->capture_len = defproxy.capture_len;
Willy Tarreau0f772532006-12-23 20:51:41 +01002672 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002673
Willy Tarreau977b8e42006-12-29 14:19:17 +01002674 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002675 curproxy->timeout.client = defproxy.timeout.client;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002676 curproxy->timeout.clientfin = defproxy.timeout.clientfin;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002677 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau036fae02008-01-06 13:24:40 +01002678 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002679 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002680 curproxy->mon_net = defproxy.mon_net;
2681 curproxy->mon_mask = defproxy.mon_mask;
2682 if (defproxy.monitor_uri)
2683 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
2684 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002685 if (defproxy.defbe.name)
2686 curproxy->defbe.name = strdup(defproxy.defbe.name);
Willy Tarreau99a7ca22012-05-31 19:39:23 +02002687
2688 /* get either a pointer to the logformat string or a copy of it */
Willy Tarreau62a61232013-04-12 18:13:46 +02002689 curproxy->conf.logformat_string = defproxy.conf.logformat_string;
2690 if (curproxy->conf.logformat_string &&
2691 curproxy->conf.logformat_string != default_http_log_format &&
2692 curproxy->conf.logformat_string != default_tcp_log_format &&
2693 curproxy->conf.logformat_string != clf_http_log_format)
2694 curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string);
2695
2696 if (defproxy.conf.lfs_file) {
2697 curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file);
2698 curproxy->conf.lfs_line = defproxy.conf.lfs_line;
2699 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002700
2701 /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */
2702 curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string;
2703 if (curproxy->conf.logformat_sd_string &&
2704 curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
2705 curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string);
2706
2707 if (defproxy.conf.lfsd_file) {
2708 curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file);
2709 curproxy->conf.lfsd_line = defproxy.conf.lfsd_line;
2710 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002711 }
2712
2713 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaud7c30f92007-12-03 01:38:36 +01002714 curproxy->timeout.connect = defproxy.timeout.connect;
2715 curproxy->timeout.server = defproxy.timeout.server;
Simone Gotti1b48cc92014-06-11 12:25:28 +02002716 curproxy->timeout.serverfin = defproxy.timeout.serverfin;
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01002717 curproxy->timeout.check = defproxy.timeout.check;
Willy Tarreau1fa31262007-12-03 00:36:16 +01002718 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau51c9bde2008-01-06 13:40:03 +01002719 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreaucd7afc02009-07-12 10:03:17 +02002720 curproxy->timeout.httpreq = defproxy.timeout.httpreq;
Willy Tarreaub16a5742010-01-10 14:46:16 +01002721 curproxy->timeout.httpka = defproxy.timeout.httpka;
Willy Tarreauce887fd2012-05-12 12:50:00 +02002722 curproxy->timeout.tunnel = defproxy.timeout.tunnel;
Willy Tarreauef9a3602012-12-08 22:29:20 +01002723 curproxy->conn_src.source_addr = defproxy.conn_src.source_addr;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002724 }
2725
Willy Tarreaubaaee002006-06-26 02:48:02 +02002726 curproxy->mode = defproxy.mode;
Willy Tarreaued2119c2014-04-24 22:10:39 +02002727 curproxy->uri_auth = defproxy.uri_auth; /* for stats */
William Lallemand0f99e342011-10-12 17:50:54 +02002728
2729 /* copy default logsrvs to curproxy */
William Lallemand723b73a2012-02-08 16:37:49 +01002730 list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
Vincent Bernat02779b62016-04-03 13:48:43 +02002731 struct logsrv *node = malloc(sizeof(*node));
William Lallemand723b73a2012-02-08 16:37:49 +01002732 memcpy(node, tmplogsrv, sizeof(struct logsrv));
William Lallemand0f99e342011-10-12 17:50:54 +02002733 LIST_INIT(&node->list);
2734 LIST_ADDQ(&curproxy->logsrvs, &node->list);
2735 }
2736
Willy Tarreau62a61232013-04-12 18:13:46 +02002737 curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string;
2738 if (curproxy->conf.uniqueid_format_string)
2739 curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string);
2740
Dragan Dosen43885c72015-10-01 13:18:13 +02002741 chunk_dup(&curproxy->log_tag, &defproxy.log_tag);
Willy Tarreau094af4e2015-01-07 15:03:42 +01002742
Willy Tarreau62a61232013-04-12 18:13:46 +02002743 if (defproxy.conf.uif_file) {
2744 curproxy->conf.uif_file = strdup(defproxy.conf.uif_file);
2745 curproxy->conf.uif_line = defproxy.conf.uif_line;
2746 }
William Lallemanda73203e2012-03-12 12:48:57 +01002747
2748 /* copy default header unique id */
2749 if (defproxy.header_unique_id)
2750 curproxy->header_unique_id = strdup(defproxy.header_unique_id);
2751
William Lallemand82fe75c2012-10-23 10:25:10 +02002752 /* default compression options */
2753 if (defproxy.comp != NULL) {
2754 curproxy->comp = calloc(1, sizeof(struct comp));
2755 curproxy->comp->algos = defproxy.comp->algos;
2756 curproxy->comp->types = defproxy.comp->types;
2757 }
2758
Willy Tarreaubaaee002006-06-26 02:48:02 +02002759 curproxy->grace = defproxy.grace;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02002760 curproxy->conf.used_listener_id = EB_ROOT;
2761 curproxy->conf.used_server_id = EB_ROOT;
Willy Tarreau1c47f852006-07-09 08:22:27 +02002762
Simon Horman98637e52014-06-20 12:30:16 +09002763 if (defproxy.check_path)
2764 curproxy->check_path = strdup(defproxy.check_path);
2765 if (defproxy.check_command)
2766 curproxy->check_command = strdup(defproxy.check_command);
2767
Simon Horman9dc49962015-01-30 11:22:59 +09002768 if (defproxy.email_alert.mailers.name)
2769 curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name);
2770 if (defproxy.email_alert.from)
2771 curproxy->email_alert.from = strdup(defproxy.email_alert.from);
2772 if (defproxy.email_alert.to)
2773 curproxy->email_alert.to = strdup(defproxy.email_alert.to);
2774 if (defproxy.email_alert.myhostname)
2775 curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname);
Simon Horman64e34162015-02-06 11:11:57 +09002776 curproxy->email_alert.level = defproxy.email_alert.level;
Cyril Bonté7e084702015-12-04 03:07:06 +01002777 curproxy->email_alert.set = defproxy.email_alert.set;
Simon Horman9dc49962015-01-30 11:22:59 +09002778
Willy Tarreau93893792009-07-23 13:19:11 +02002779 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002780 }
2781 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
2782 /* some variables may have already been initialized earlier */
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002783 /* FIXME-20070101: we should do this too at the end of the
2784 * config parsing to free all default values.
2785 */
William Lallemand6e62fb62015-04-28 16:55:23 +02002786 if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
2787 err_code |= ERR_ABORT;
2788 goto out;
2789 }
2790
Willy Tarreaua534fea2008-08-03 12:19:50 +02002791 free(defproxy.check_req);
Simon Horman98637e52014-06-20 12:30:16 +09002792 free(defproxy.check_command);
2793 free(defproxy.check_path);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002794 free(defproxy.cookie_name);
Emeric Brun647caf12009-06-30 17:57:00 +02002795 free(defproxy.rdp_cookie_name);
Willy Tarreau4d187ac2009-12-03 23:13:06 +01002796 free(defproxy.cookie_domain);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002797 free(defproxy.url_param_name);
Benoitaffb4812009-03-25 13:02:10 +01002798 free(defproxy.hh_name);
Willy Tarreaua534fea2008-08-03 12:19:50 +02002799 free(defproxy.capture_name);
2800 free(defproxy.monitor_uri);
2801 free(defproxy.defbe.name);
Willy Tarreauef9a3602012-12-08 22:29:20 +01002802 free(defproxy.conn_src.iface_name);
Willy Tarreau79f5fe82008-08-23 08:18:21 +02002803 free(defproxy.fwdfor_hdr_name);
2804 defproxy.fwdfor_hdr_len = 0;
Willy Tarreaub86db342009-11-30 11:50:16 +01002805 free(defproxy.orgto_hdr_name);
2806 defproxy.orgto_hdr_len = 0;
Mark Lamourinec2247f02012-01-04 13:02:01 -05002807 free(defproxy.server_id_hdr_name);
2808 defproxy.server_id_hdr_len = 0;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02002809 free(defproxy.expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02002810 if (defproxy.expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02002811 regex_free(defproxy.expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02002812 free(defproxy.expect_regex);
2813 defproxy.expect_regex = NULL;
2814 }
Willy Tarreau0f772532006-12-23 20:51:41 +01002815
Willy Tarreau62a61232013-04-12 18:13:46 +02002816 if (defproxy.conf.logformat_string != default_http_log_format &&
2817 defproxy.conf.logformat_string != default_tcp_log_format &&
2818 defproxy.conf.logformat_string != clf_http_log_format)
2819 free(defproxy.conf.logformat_string);
Willy Tarreau196729e2012-05-31 19:30:26 +02002820
Willy Tarreau62a61232013-04-12 18:13:46 +02002821 free(defproxy.conf.uniqueid_format_string);
2822 free(defproxy.conf.lfs_file);
2823 free(defproxy.conf.uif_file);
Dragan Dosen43885c72015-10-01 13:18:13 +02002824 chunk_destroy(&defproxy.log_tag);
Simon Horman9dc49962015-01-30 11:22:59 +09002825 free_email_alert(&defproxy);
Willy Tarreau196729e2012-05-31 19:30:26 +02002826
Dragan Dosen0b85ece2015-09-25 19:17:44 +02002827 if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format)
2828 free(defproxy.conf.logformat_sd_string);
2829 free(defproxy.conf.lfsd_file);
2830
Willy Tarreaua534fea2008-08-03 12:19:50 +02002831 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002832 chunk_destroy(&defproxy.errmsg[rc]);
Willy Tarreau0f772532006-12-23 20:51:41 +01002833
Willy Tarreaubaaee002006-06-26 02:48:02 +02002834 /* we cannot free uri_auth because it might already be used */
2835 init_default_instance();
2836 curproxy = &defproxy;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002837 curproxy->conf.args.file = curproxy->conf.file = strdup(file);
2838 curproxy->conf.args.line = curproxy->conf.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002839 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
Willy Tarreau93893792009-07-23 13:19:11 +02002840 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002841 }
2842 else if (curproxy == NULL) {
2843 Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02002844 err_code |= ERR_ALERT | ERR_FATAL;
2845 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002846 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02002847
2848 /* update the current file and line being parsed */
2849 curproxy->conf.args.file = curproxy->conf.file;
2850 curproxy->conf.args.line = linenum;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002851
2852 /* Now let's parse the proxy-specific keywords */
Willy Tarreau272adea2014-03-31 10:39:59 +02002853 if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) {
2854 err_code |= parse_server(file, linenum, args, curproxy, &defproxy);
2855 if (err_code & ERR_FATAL)
2856 goto out;
2857 }
2858 else if (!strcmp(args[0], "bind")) { /* new listen addresses */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002859 struct listener *l;
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002860 int cur_arg;
2861
Willy Tarreaubaaee002006-06-26 02:48:02 +02002862 if (curproxy == &defproxy) {
2863 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002864 err_code |= ERR_ALERT | ERR_FATAL;
2865 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002866 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002867 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002868 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002869
Willy Tarreau24709282013-03-10 21:32:12 +01002870 if (!*(args[1])) {
Willy Tarreaud55c3fe2010-11-09 09:50:37 +01002871 Alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n",
Willy Tarreaubaaee002006-06-26 02:48:02 +02002872 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002873 err_code |= ERR_ALERT | ERR_FATAL;
2874 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002875 }
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002876
Willy Tarreaua261e9b2016-12-22 20:44:00 +01002877 bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
Willy Tarreau8dc21fa2013-01-24 15:17:20 +01002878
2879 /* use default settings for unix sockets */
2880 bind_conf->ux.uid = global.unix_bind.ux.uid;
2881 bind_conf->ux.gid = global.unix_bind.ux.gid;
2882 bind_conf->ux.mode = global.unix_bind.ux.mode;
Willy Tarreau8a956912010-10-15 14:27:08 +02002883
2884 /* NOTE: the following line might create several listeners if there
2885 * are comma-separated IPs or port ranges. So all further processing
2886 * will have to be applied to all listeners created after last_listen.
2887 */
Willy Tarreau902636f2013-03-10 19:44:48 +01002888 if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) {
2889 if (errmsg && *errmsg) {
2890 indent_msg(&errmsg, 2);
2891 Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreau4fbb2282012-09-20 20:01:39 +02002892 }
2893 else
2894 Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n",
2895 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02002896 err_code |= ERR_ALERT | ERR_FATAL;
2897 goto out;
2898 }
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002899
Willy Tarreau4348fad2012-09-20 16:48:07 +02002900 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
2901 /* Set default global rights and owner for unix bind */
Willy Tarreauc8b11092011-02-16 11:08:57 +01002902 global.maxsock++;
Willy Tarreau90a570f2009-10-04 20:54:54 +02002903 }
2904
Willy Tarreau5e6e2042009-02-04 17:19:29 +01002905 cur_arg = 2;
2906 while (*(args[cur_arg])) {
Willy Tarreau8638f482012-09-18 18:01:17 +02002907 static int bind_dumped;
Willy Tarreau26982662012-09-12 23:17:10 +02002908 struct bind_kw *kw;
Willy Tarreau8638f482012-09-18 18:01:17 +02002909 char *err;
2910
Willy Tarreau26982662012-09-12 23:17:10 +02002911 kw = bind_find_kw(args[cur_arg]);
2912 if (kw) {
2913 char *err = NULL;
2914 int code;
2915
2916 if (!kw->parse) {
Willy Tarreaudda322d2012-09-18 16:34:09 +02002917 Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n",
2918 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02002919 cur_arg += 1 + kw->skip ;
2920 err_code |= ERR_ALERT | ERR_FATAL;
2921 goto out;
2922 }
2923
Willy Tarreau4348fad2012-09-20 16:48:07 +02002924 code = kw->parse(args, cur_arg, curproxy, bind_conf, &err);
Willy Tarreau26982662012-09-12 23:17:10 +02002925 err_code |= code;
2926
2927 if (code) {
2928 if (err && *err) {
2929 indent_msg(&err, 2);
Willy Tarreaudda322d2012-09-18 16:34:09 +02002930 Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err);
Willy Tarreau26982662012-09-12 23:17:10 +02002931 }
2932 else
Willy Tarreaudda322d2012-09-18 16:34:09 +02002933 Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n",
2934 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau26982662012-09-12 23:17:10 +02002935 if (code & ERR_FATAL) {
2936 free(err);
2937 cur_arg += 1 + kw->skip;
2938 goto out;
2939 }
2940 }
2941 free(err);
2942 cur_arg += 1 + kw->skip;
2943 continue;
2944 }
2945
Willy Tarreau8638f482012-09-18 18:01:17 +02002946 err = NULL;
2947 if (!bind_dumped) {
2948 bind_dump_kws(&err);
2949 indent_msg(&err, 4);
2950 bind_dumped = 1;
2951 }
2952
2953 Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n",
2954 file, linenum, args[0], args[1], args[cur_arg],
2955 err ? " Registered keywords :" : "", err ? err : "");
2956 free(err);
2957
Willy Tarreau93893792009-07-23 13:19:11 +02002958 err_code |= ERR_ALERT | ERR_FATAL;
2959 goto out;
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002960 }
Willy Tarreau93893792009-07-23 13:19:11 +02002961 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002962 }
2963 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01002964 if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002965 Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
2966 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002967 err_code |= ERR_ALERT | ERR_FATAL;
2968 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002969 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002970 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002971 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002972
Willy Tarreaubaaee002006-06-26 02:48:02 +02002973 /* flush useless bits */
2974 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
Willy Tarreau93893792009-07-23 13:19:11 +02002975 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002976 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02002977 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
Willy Tarreau977b8e42006-12-29 14:19:17 +01002978 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02002979 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002980
William Lallemanddf1425a2015-04-28 20:17:49 +02002981 if (alertif_too_many_args(1, file, linenum, args, &err_code))
2982 goto out;
2983
Willy Tarreau1c47f852006-07-09 08:22:27 +02002984 if (!*args[1]) {
2985 Alert("parsing [%s:%d] : '%s' expects an URI.\n",
2986 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02002987 err_code |= ERR_ALERT | ERR_FATAL;
2988 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02002989 }
2990
Willy Tarreaua534fea2008-08-03 12:19:50 +02002991 free(curproxy->monitor_uri);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01002992 curproxy->monitor_uri_len = strlen(args[1]);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02002993 curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +01002994 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
Willy Tarreau1c47f852006-07-09 08:22:27 +02002995 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
2996
Willy Tarreau93893792009-07-23 13:19:11 +02002997 goto out;
Willy Tarreau1c47f852006-07-09 08:22:27 +02002998 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002999 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
William Lallemanddf1425a2015-04-28 20:17:49 +02003000 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3001 goto out;
3002
Willy Tarreaubaaee002006-06-26 02:48:02 +02003003 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
3004 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
3005 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
3006 else {
3007 Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003008 err_code |= ERR_ALERT | ERR_FATAL;
3009 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003010 }
3011 }
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003012 else if (!strcmp(args[0], "id")) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003013 struct eb32_node *node;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003014
3015 if (curproxy == &defproxy) {
3016 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
3017 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003018 err_code |= ERR_ALERT | ERR_FATAL;
3019 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003020 }
3021
William Lallemanddf1425a2015-04-28 20:17:49 +02003022 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3023 goto out;
3024
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003025 if (!*args[1]) {
3026 Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
3027 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003028 err_code |= ERR_ALERT | ERR_FATAL;
3029 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003030 }
3031
3032 curproxy->uuid = atol(args[1]);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003033 curproxy->conf.id.key = curproxy->uuid;
Willy Tarreau0d1fdf72015-05-27 16:44:02 +02003034 curproxy->options |= PR_O_FORCED_ID;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003035
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003036 if (curproxy->uuid <= 0) {
3037 Alert("parsing [%s:%d]: custom id has to be > 0.\n",
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003038 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003039 err_code |= ERR_ALERT | ERR_FATAL;
3040 goto out;
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003041 }
3042
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02003043 node = eb32_lookup(&used_proxy_id, curproxy->uuid);
3044 if (node) {
3045 struct proxy *target = container_of(node, struct proxy, conf.id);
3046 Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n",
3047 file, linenum, proxy_type_str(curproxy), curproxy->id,
3048 proxy_type_str(target), target->id, target->conf.file, target->conf.line);
3049 err_code |= ERR_ALERT | ERR_FATAL;
3050 goto out;
3051 }
3052 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01003053 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003054 else if (!strcmp(args[0], "description")) {
3055 int i, len=0;
3056 char *d;
3057
Cyril Bonté99ed3272010-01-24 23:29:44 +01003058 if (curproxy == &defproxy) {
3059 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n",
3060 file, linenum, args[0]);
3061 err_code |= ERR_ALERT | ERR_FATAL;
3062 goto out;
3063 }
3064
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003065 if (!*args[1]) {
3066 Alert("parsing [%s:%d]: '%s' expects a string argument.\n",
3067 file, linenum, args[0]);
3068 return -1;
3069 }
3070
Willy Tarreau348acfe2014-04-14 15:00:39 +02003071 for (i = 1; *args[i]; i++)
3072 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003073
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003074 d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003075 curproxy->desc = d;
3076
Willy Tarreau348acfe2014-04-14 15:00:39 +02003077 d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
3078 for (i = 2; *args[i]; i++)
3079 d += snprintf(d, curproxy->desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02003080
3081 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003082 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
William Lallemanddf1425a2015-04-28 20:17:49 +02003083 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3084 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003085 curproxy->state = PR_STSTOPPED;
3086 }
3087 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
William Lallemanddf1425a2015-04-28 20:17:49 +02003088 if (alertif_too_many_args(0, file, linenum, args, &err_code))
3089 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003090 curproxy->state = PR_STNEW;
3091 }
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003092 else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */
3093 int cur_arg = 1;
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003094 unsigned long set = 0;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003095
3096 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +01003097 unsigned int low, high;
3098
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003099 if (strcmp(args[cur_arg], "all") == 0) {
3100 set = 0;
3101 break;
3102 }
3103 else if (strcmp(args[cur_arg], "odd") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003104 set |= ~0UL/3UL; /* 0x555....555 */
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003105 }
3106 else if (strcmp(args[cur_arg], "even") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003107 set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003108 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +01003109 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +01003110 char *dash = strchr(args[cur_arg], '-');
3111
3112 low = high = str2uic(args[cur_arg]);
3113 if (dash)
3114 high = str2uic(dash + 1);
3115
3116 if (high < low) {
3117 unsigned int swap = low;
3118 low = high;
3119 high = swap;
3120 }
3121
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003122 if (low < 1 || high > LONGBITS) {
3123 Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n",
3124 file, linenum, args[0], LONGBITS);
Willy Tarreau93893792009-07-23 13:19:11 +02003125 err_code |= ERR_ALERT | ERR_FATAL;
3126 goto out;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003127 }
Willy Tarreau110ecc12012-11-15 17:50:01 +01003128 while (low <= high)
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003129 set |= 1UL << (low++ - 1);
Willy Tarreau110ecc12012-11-15 17:50:01 +01003130 }
3131 else {
Willy Tarreaua9db57e2013-01-18 11:29:29 +01003132 Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n",
3133 file, linenum, args[0], LONGBITS);
Willy Tarreau110ecc12012-11-15 17:50:01 +01003134 err_code |= ERR_ALERT | ERR_FATAL;
3135 goto out;
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01003136 }
3137 cur_arg++;
3138 }
3139 curproxy->bind_proc = set;
3140 }
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003141 else if (!strcmp(args[0], "acl")) { /* add an ACL */
Willy Tarreaub099aca2008-10-12 17:26:37 +02003142 if (curproxy == &defproxy) {
3143 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003144 err_code |= ERR_ALERT | ERR_FATAL;
3145 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003146 }
3147
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003148 err = invalid_char(args[1]);
3149 if (err) {
3150 Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n",
3151 file, linenum, *err, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003152 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01003153 }
3154
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01003155 if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003156 Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n",
3157 file, linenum, args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003158 err_code |= ERR_ALERT | ERR_FATAL;
3159 goto out;
Willy Tarreaueb0c6142007-05-07 00:53:22 +02003160 }
3161 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003162 else if (!strcmp(args[0], "cookie")) { /* cookie name */
3163 int cur_arg;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003164
Willy Tarreau977b8e42006-12-29 14:19:17 +01003165 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003166 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003167
Willy Tarreaubaaee002006-06-26 02:48:02 +02003168 if (*(args[1]) == 0) {
3169 Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
3170 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003171 err_code |= ERR_ALERT | ERR_FATAL;
3172 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003173 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003174
Willy Tarreau67402132012-05-31 20:40:20 +02003175 curproxy->ck_opts = 0;
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003176 curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
Willy Tarreau4d187ac2009-12-03 23:13:06 +01003177 free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
Willy Tarreaua534fea2008-08-03 12:19:50 +02003178 free(curproxy->cookie_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003179 curproxy->cookie_name = strdup(args[1]);
3180 curproxy->cookie_len = strlen(curproxy->cookie_name);
Willy Tarreauc63d4bb2010-10-23 11:37:27 +02003181
Willy Tarreaubaaee002006-06-26 02:48:02 +02003182 cur_arg = 2;
3183 while (*(args[cur_arg])) {
3184 if (!strcmp(args[cur_arg], "rewrite")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003185 curproxy->ck_opts |= PR_CK_RW;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003186 }
3187 else if (!strcmp(args[cur_arg], "indirect")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003188 curproxy->ck_opts |= PR_CK_IND;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003189 }
3190 else if (!strcmp(args[cur_arg], "insert")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003191 curproxy->ck_opts |= PR_CK_INS;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003192 }
3193 else if (!strcmp(args[cur_arg], "nocache")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003194 curproxy->ck_opts |= PR_CK_NOC;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003195 }
3196 else if (!strcmp(args[cur_arg], "postonly")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003197 curproxy->ck_opts |= PR_CK_POST;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003198 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003199 else if (!strcmp(args[cur_arg], "preserve")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003200 curproxy->ck_opts |= PR_CK_PSV;
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003201 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003202 else if (!strcmp(args[cur_arg], "prefix")) {
Willy Tarreau67402132012-05-31 20:40:20 +02003203 curproxy->ck_opts |= PR_CK_PFX;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003204 }
Willy Tarreau4992dd22012-05-31 21:02:17 +02003205 else if (!strcmp(args[cur_arg], "httponly")) {
3206 curproxy->ck_opts |= PR_CK_HTTPONLY;
3207 }
3208 else if (!strcmp(args[cur_arg], "secure")) {
3209 curproxy->ck_opts |= PR_CK_SECURE;
3210 }
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003211 else if (!strcmp(args[cur_arg], "domain")) {
3212 if (!*args[cur_arg + 1]) {
3213 Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n",
3214 file, linenum, args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02003215 err_code |= ERR_ALERT | ERR_FATAL;
3216 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003217 }
3218
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003219 if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) {
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003220 /* rfc2109, 4.3.2 Rejecting Cookies */
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003221 Warning("parsing [%s:%d]: domain '%s' contains no embedded"
3222 " dots nor does not start with a dot."
3223 " RFC forbids it, this configuration may not work properly.\n",
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003224 file, linenum, args[cur_arg + 1]);
Krzysztof Piotr Oledzki1a8bea92009-12-15 23:40:47 +01003225 err_code |= ERR_WARN;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003226 }
3227
3228 err = invalid_domainchar(args[cur_arg + 1]);
3229 if (err) {
3230 Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n",
3231 file, linenum, *err, args[cur_arg + 1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003232 err_code |= ERR_ALERT | ERR_FATAL;
3233 goto out;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003234 }
3235
Willy Tarreau68a897b2009-12-03 23:28:34 +01003236 if (!curproxy->cookie_domain) {
3237 curproxy->cookie_domain = strdup(args[cur_arg + 1]);
3238 } else {
3239 /* one domain was already specified, add another one by
3240 * building the string which will be returned along with
3241 * the cookie.
3242 */
3243 char *new_ptr;
3244 int new_len = strlen(curproxy->cookie_domain) +
3245 strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
3246 new_ptr = malloc(new_len);
3247 snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
3248 free(curproxy->cookie_domain);
3249 curproxy->cookie_domain = new_ptr;
3250 }
Willy Tarreau31936852010-10-06 16:59:56 +02003251 cur_arg++;
3252 }
3253 else if (!strcmp(args[cur_arg], "maxidle")) {
3254 unsigned int maxidle;
3255 const char *res;
3256
3257 if (!*args[cur_arg + 1]) {
3258 Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n",
3259 file, linenum, args[cur_arg]);
3260 err_code |= ERR_ALERT | ERR_FATAL;
3261 goto out;
3262 }
3263
3264 res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S);
3265 if (res) {
3266 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3267 file, linenum, *res, args[cur_arg]);
3268 err_code |= ERR_ALERT | ERR_FATAL;
3269 goto out;
3270 }
3271 curproxy->cookie_maxidle = maxidle;
3272 cur_arg++;
3273 }
3274 else if (!strcmp(args[cur_arg], "maxlife")) {
3275 unsigned int maxlife;
3276 const char *res;
3277
3278 if (!*args[cur_arg + 1]) {
3279 Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n",
3280 file, linenum, args[cur_arg]);
3281 err_code |= ERR_ALERT | ERR_FATAL;
3282 goto out;
3283 }
3284
3285 res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S);
3286 if (res) {
3287 Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
3288 file, linenum, *res, args[cur_arg]);
3289 err_code |= ERR_ALERT | ERR_FATAL;
3290 goto out;
3291 }
3292 curproxy->cookie_maxlife = maxlife;
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02003293 cur_arg++;
3294 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003295 else {
Willy Tarreau31936852010-10-06 16:59:56 +02003296 Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n",
Willy Tarreaubaaee002006-06-26 02:48:02 +02003297 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003298 err_code |= ERR_ALERT | ERR_FATAL;
3299 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003300 }
3301 cur_arg++;
3302 }
Willy Tarreau67402132012-05-31 20:40:20 +02003303 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02003304 Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
3305 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003306 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003307 }
3308
Willy Tarreau67402132012-05-31 20:40:20 +02003309 if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02003310 Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
3311 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003312 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003313 }
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003314
Willy Tarreau67402132012-05-31 20:40:20 +02003315 if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) {
Willy Tarreauba4c5be2010-10-23 12:46:42 +02003316 Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n",
3317 file, linenum);
3318 err_code |= ERR_ALERT | ERR_FATAL;
3319 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003320 }/* end else if (!strcmp(args[0], "cookie")) */
Simon Horman9dc49962015-01-30 11:22:59 +09003321 else if (!strcmp(args[0], "email-alert")) {
3322 if (*(args[1]) == 0) {
3323 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3324 file, linenum, args[0]);
3325 err_code |= ERR_ALERT | ERR_FATAL;
3326 goto out;
3327 }
3328
3329 if (!strcmp(args[1], "from")) {
3330 if (*(args[1]) == 0) {
3331 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3332 file, linenum, args[1]);
3333 err_code |= ERR_ALERT | ERR_FATAL;
3334 goto out;
3335 }
3336 free(curproxy->email_alert.from);
3337 curproxy->email_alert.from = strdup(args[2]);
3338 }
3339 else if (!strcmp(args[1], "mailers")) {
3340 if (*(args[1]) == 0) {
3341 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3342 file, linenum, args[1]);
3343 err_code |= ERR_ALERT | ERR_FATAL;
3344 goto out;
3345 }
3346 free(curproxy->email_alert.mailers.name);
3347 curproxy->email_alert.mailers.name = strdup(args[2]);
3348 }
3349 else if (!strcmp(args[1], "myhostname")) {
3350 if (*(args[1]) == 0) {
3351 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3352 file, linenum, args[1]);
3353 err_code |= ERR_ALERT | ERR_FATAL;
3354 goto out;
3355 }
3356 free(curproxy->email_alert.myhostname);
3357 curproxy->email_alert.myhostname = strdup(args[2]);
3358 }
Simon Horman64e34162015-02-06 11:11:57 +09003359 else if (!strcmp(args[1], "level")) {
3360 curproxy->email_alert.level = get_log_level(args[2]);
3361 if (curproxy->email_alert.level < 0) {
3362 Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n",
3363 file, linenum, args[1], args[2]);
3364 err_code |= ERR_ALERT | ERR_FATAL;
3365 goto out;
3366 }
3367 }
Simon Horman9dc49962015-01-30 11:22:59 +09003368 else if (!strcmp(args[1], "to")) {
3369 if (*(args[1]) == 0) {
3370 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3371 file, linenum, args[1]);
3372 err_code |= ERR_ALERT | ERR_FATAL;
3373 goto out;
3374 }
3375 free(curproxy->email_alert.to);
3376 curproxy->email_alert.to = strdup(args[2]);
3377 }
3378 else {
3379 Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
3380 file, linenum, args[1]);
3381 err_code |= ERR_ALERT | ERR_FATAL;
3382 goto out;
3383 }
Simon Horman64e34162015-02-06 11:11:57 +09003384 /* Indicate that the email_alert is at least partially configured */
3385 curproxy->email_alert.set = 1;
Simon Horman9dc49962015-01-30 11:22:59 +09003386 }/* end else if (!strcmp(args[0], "email-alert")) */
Simon Horman98637e52014-06-20 12:30:16 +09003387 else if (!strcmp(args[0], "external-check")) {
3388 if (*(args[1]) == 0) {
3389 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3390 file, linenum, args[0]);
3391 err_code |= ERR_ALERT | ERR_FATAL;
3392 goto out;
3393 }
3394
3395 if (!strcmp(args[1], "command")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003396 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003397 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003398 if (*(args[2]) == 0) {
Simon Horman98637e52014-06-20 12:30:16 +09003399 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3400 file, linenum, args[1]);
3401 err_code |= ERR_ALERT | ERR_FATAL;
3402 goto out;
3403 }
3404 free(curproxy->check_command);
3405 curproxy->check_command = strdup(args[2]);
3406 }
3407 else if (!strcmp(args[1], "path")) {
Ben Cabot49795eb2015-09-16 12:07:51 +01003408 if (alertif_too_many_args(2, file, linenum, args, &err_code))
William Lallemanddf1425a2015-04-28 20:17:49 +02003409 goto out;
Ben Cabot49795eb2015-09-16 12:07:51 +01003410 if (*(args[2]) == 0) {
Simon Horman98637e52014-06-20 12:30:16 +09003411 Alert("parsing [%s:%d] : missing argument after '%s'.\n",
3412 file, linenum, args[1]);
3413 err_code |= ERR_ALERT | ERR_FATAL;
3414 goto out;
3415 }
3416 free(curproxy->check_path);
3417 curproxy->check_path = strdup(args[2]);
3418 }
3419 else {
3420 Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n",
3421 file, linenum, args[1]);
3422 err_code |= ERR_ALERT | ERR_FATAL;
3423 goto out;
3424 }
3425 }/* end else if (!strcmp(args[0], "external-check")) */
Emeric Brun647caf12009-06-30 17:57:00 +02003426 else if (!strcmp(args[0], "persist")) { /* persist */
3427 if (*(args[1]) == 0) {
3428 Alert("parsing [%s:%d] : missing persist method.\n",
3429 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003430 err_code |= ERR_ALERT | ERR_FATAL;
3431 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003432 }
3433
3434 if (!strncmp(args[1], "rdp-cookie", 10)) {
3435 curproxy->options2 |= PR_O2_RDPC_PRST;
3436
Emeric Brunb982a3d2010-01-04 15:45:53 +01003437 if (*(args[1] + 10) == '(') { /* cookie name */
Emeric Brun647caf12009-06-30 17:57:00 +02003438 const char *beg, *end;
3439
3440 beg = args[1] + 11;
3441 end = strchr(beg, ')');
3442
William Lallemanddf1425a2015-04-28 20:17:49 +02003443 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3444 goto out;
3445
Emeric Brun647caf12009-06-30 17:57:00 +02003446 if (!end || end == beg) {
3447 Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3448 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003449 err_code |= ERR_ALERT | ERR_FATAL;
3450 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003451 }
3452
3453 free(curproxy->rdp_cookie_name);
3454 curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
3455 curproxy->rdp_cookie_len = end-beg;
3456 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003457 else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
Emeric Brun647caf12009-06-30 17:57:00 +02003458 free(curproxy->rdp_cookie_name);
3459 curproxy->rdp_cookie_name = strdup("msts");
3460 curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
3461 }
3462 else { /* syntax */
3463 Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n",
3464 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003465 err_code |= ERR_ALERT | ERR_FATAL;
3466 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003467 }
3468 }
3469 else {
3470 Alert("parsing [%s:%d] : unknown persist method.\n",
3471 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02003472 err_code |= ERR_ALERT | ERR_FATAL;
3473 goto out;
Emeric Brun647caf12009-06-30 17:57:00 +02003474 }
3475 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003476 else if (!strcmp(args[0], "appsession")) { /* cookie name */
Willy Tarreau6db62c52015-08-10 19:04:29 +02003477 Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]);
3478 err_code |= ERR_ALERT | ERR_FATAL;
3479 goto out;
3480 }
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02003481 else if (!strcmp(args[0], "load-server-state-from-file")) {
3482 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3483 err_code |= ERR_WARN;
3484 if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */
3485 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL;
3486 }
3487 else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */
3488 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL;
3489 }
3490 else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */
3491 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
3492 }
3493 else {
3494 Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n",
3495 file, linenum, args[0], args[1]);
3496 err_code |= ERR_ALERT | ERR_FATAL;
3497 goto out;
3498 }
3499 }
3500 else if (!strcmp(args[0], "server-state-file-name")) {
3501 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3502 err_code |= ERR_WARN;
3503 if (*(args[1]) == 0) {
3504 Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
3505 file, linenum, args[0]);
3506 err_code |= ERR_ALERT | ERR_FATAL;
3507 goto out;
3508 }
3509 else if (!strcmp(args[1], "use-backend-name"))
3510 curproxy->server_state_file_name = strdup(curproxy->id);
3511 else
3512 curproxy->server_state_file_name = strdup(args[1]);
3513 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003514 else if (!strcmp(args[0], "capture")) {
Willy Tarreau3b6b1a92009-07-23 13:24:23 +02003515 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003516 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003517
Willy Tarreaubaaee002006-06-26 02:48:02 +02003518 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
Cyril Bonté99ed3272010-01-24 23:29:44 +01003519 if (curproxy == &defproxy) {
3520 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
3521 err_code |= ERR_ALERT | ERR_FATAL;
3522 goto out;
3523 }
3524
William Lallemand1a748ae2015-05-19 16:37:23 +02003525 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3526 goto out;
3527
Willy Tarreaubaaee002006-06-26 02:48:02 +02003528 if (*(args[4]) == 0) {
3529 Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
3530 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003531 err_code |= ERR_ALERT | ERR_FATAL;
3532 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003533 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02003534 free(curproxy->capture_name);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003535 curproxy->capture_name = strdup(args[2]);
3536 curproxy->capture_namelen = strlen(curproxy->capture_name);
3537 curproxy->capture_len = atol(args[4]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003538 curproxy->to_log |= LW_COOKIE;
3539 }
3540 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
3541 struct cap_hdr *hdr;
3542
3543 if (curproxy == &defproxy) {
3544 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 +02003545 err_code |= ERR_ALERT | ERR_FATAL;
3546 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003547 }
3548
William Lallemand1a748ae2015-05-19 16:37:23 +02003549 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3550 goto out;
3551
Willy Tarreaubaaee002006-06-26 02:48:02 +02003552 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
3553 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3554 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003555 err_code |= ERR_ALERT | ERR_FATAL;
3556 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003557 }
3558
Vincent Bernat02779b62016-04-03 13:48:43 +02003559 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003560 hdr->next = curproxy->req_cap;
3561 hdr->name = strdup(args[3]);
3562 hdr->namelen = strlen(args[3]);
3563 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003564 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003565 hdr->index = curproxy->nb_req_cap++;
3566 curproxy->req_cap = hdr;
3567 curproxy->to_log |= LW_REQHDR;
3568 }
3569 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
3570 struct cap_hdr *hdr;
3571
3572 if (curproxy == &defproxy) {
3573 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 +02003574 err_code |= ERR_ALERT | ERR_FATAL;
3575 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003576 }
3577
William Lallemand1a748ae2015-05-19 16:37:23 +02003578 if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code))
3579 goto out;
3580
Willy Tarreaubaaee002006-06-26 02:48:02 +02003581 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
3582 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
3583 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02003584 err_code |= ERR_ALERT | ERR_FATAL;
3585 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003586 }
Vincent Bernat02779b62016-04-03 13:48:43 +02003587 hdr = calloc(1, sizeof(*hdr));
Willy Tarreaubaaee002006-06-26 02:48:02 +02003588 hdr->next = curproxy->rsp_cap;
3589 hdr->name = strdup(args[3]);
3590 hdr->namelen = strlen(args[3]);
3591 hdr->len = atol(args[5]);
Willy Tarreaucf7f3202007-05-13 22:46:04 +02003592 hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED);
Willy Tarreaubaaee002006-06-26 02:48:02 +02003593 hdr->index = curproxy->nb_rsp_cap++;
3594 curproxy->rsp_cap = hdr;
3595 curproxy->to_log |= LW_RSPHDR;
3596 }
3597 else {
3598 Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
3599 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003600 err_code |= ERR_ALERT | ERR_FATAL;
3601 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003602 }
3603 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02003604 else if (!strcmp(args[0], "retries")) { /* connection retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +01003605 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003606 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01003607
William Lallemanddf1425a2015-04-28 20:17:49 +02003608 if (alertif_too_many_args(1, file, linenum, args, &err_code))
3609 goto out;
3610
Willy Tarreaubaaee002006-06-26 02:48:02 +02003611 if (*(args[1]) == 0) {
3612 Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
3613 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003614 err_code |= ERR_ALERT | ERR_FATAL;
3615 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02003616 }
3617 curproxy->conn_retries = atol(args[1]);
3618 }
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003619 else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003620 struct act_rule *rule;
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003621
3622 if (curproxy == &defproxy) {
3623 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3624 err_code |= ERR_ALERT | ERR_FATAL;
3625 goto out;
3626 }
3627
Willy Tarreau20b0de52012-12-24 15:45:22 +01003628 if (!LIST_ISEMPTY(&curproxy->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003629 !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003630 (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3631 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY ||
3632 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR ||
3633 LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REQ_AUTH)) {
Willy Tarreau20b0de52012-12-24 15:45:22 +01003634 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 +01003635 file, linenum, args[0]);
3636 err_code |= ERR_WARN;
3637 }
3638
Willy Tarreauff011f22011-01-06 17:51:27 +01003639 rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003640
Willy Tarreauff011f22011-01-06 17:51:27 +01003641 if (!rule) {
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003642 err_code |= ERR_ALERT | ERR_ABORT;
3643 goto out;
3644 }
3645
Willy Tarreau5002f572014-04-23 01:32:02 +02003646 err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003647 err_code |= warnif_cond_conflicts(rule->cond,
3648 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3649 file, linenum);
3650
Willy Tarreauff011f22011-01-06 17:51:27 +01003651 LIST_ADDQ(&curproxy->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki59bb2182010-01-29 17:58:21 +01003652 }
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003653 else if (!strcmp(args[0], "http-response")) { /* response access control */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003654 struct act_rule *rule;
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003655
3656 if (curproxy == &defproxy) {
3657 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3658 err_code |= ERR_ALERT | ERR_FATAL;
3659 goto out;
3660 }
3661
3662 if (!LIST_ISEMPTY(&curproxy->http_res_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003663 !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond &&
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02003664 (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW ||
3665 LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_DENY)) {
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003666 Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n",
3667 file, linenum, args[0]);
3668 err_code |= ERR_WARN;
3669 }
3670
3671 rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy);
3672
3673 if (!rule) {
3674 err_code |= ERR_ALERT | ERR_ABORT;
3675 goto out;
3676 }
3677
3678 err_code |= warnif_cond_conflicts(rule->cond,
3679 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
3680 file, linenum);
3681
3682 LIST_ADDQ(&curproxy->http_res_rules, &rule->list);
3683 }
Mark Lamourinec2247f02012-01-04 13:02:01 -05003684 else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */
3685 /* set the header name and length into the proxy structure */
3686 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3687 err_code |= ERR_WARN;
3688
3689 if (!*args[1]) {
3690 Alert("parsing [%s:%d] : '%s' requires a header string.\n",
3691 file, linenum, args[0]);
3692 err_code |= ERR_ALERT | ERR_FATAL;
3693 goto out;
3694 }
3695
3696 /* set the desired header name */
3697 free(curproxy->server_id_hdr_name);
3698 curproxy->server_id_hdr_name = strdup(args[1]);
3699 curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
3700 }
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003701 else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02003702 struct act_rule *rule;
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003703
Willy Tarreaub099aca2008-10-12 17:26:37 +02003704 if (curproxy == &defproxy) {
3705 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003706 err_code |= ERR_ALERT | ERR_FATAL;
3707 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003708 }
3709
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003710 /* emulate "block" using "http-request block". Since these rules are supposed to
3711 * be processed before all http-request rules, we put them into their own list
3712 * and will insert them at the end.
3713 */
3714 rule = parse_http_req_cond((const char **)args, file, linenum, curproxy);
3715 if (!rule) {
3716 err_code |= ERR_ALERT | ERR_ABORT;
Willy Tarreau93893792009-07-23 13:19:11 +02003717 goto out;
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003718 }
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02003719 err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]);
3720 err_code |= warnif_cond_conflicts(rule->cond,
3721 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3722 file, linenum);
3723 LIST_ADDQ(&curproxy->block_rules, &rule->list);
Willy Tarreaude9d2d72014-04-28 22:28:02 +02003724
3725 if (!already_warned(WARN_BLOCK_DEPRECATED))
3726 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]);
3727
Willy Tarreau5c8e3e02007-05-07 00:58:25 +02003728 }
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003729 else if (!strcmp(args[0], "redirect")) {
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003730 struct redirect_rule *rule;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003731
Cyril Bonté99ed3272010-01-24 23:29:44 +01003732 if (curproxy == &defproxy) {
3733 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3734 err_code |= ERR_ALERT | ERR_FATAL;
3735 goto out;
3736 }
3737
Willy Tarreaube4653b2015-05-28 15:26:58 +02003738 if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) {
Willy Tarreau4baae242012-12-27 12:00:31 +01003739 Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n",
3740 file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02003741 err_code |= ERR_ALERT | ERR_FATAL;
3742 goto out;
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003743 }
3744
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003745 LIST_ADDQ(&curproxy->redirect_rules, &rule->list);
Willy Tarreauee445d92014-04-23 01:39:04 +02003746 err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]);
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003747 err_code |= warnif_cond_conflicts(rule->cond,
3748 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
3749 file, linenum);
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003750 }
Krzysztof Piotr Oledzki7b723ef2009-01-27 21:09:41 +01003751 else if (!strcmp(args[0], "use_backend")) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02003752 struct switching_rule *rule;
3753
Willy Tarreaub099aca2008-10-12 17:26:37 +02003754 if (curproxy == &defproxy) {
3755 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003756 err_code |= ERR_ALERT | ERR_FATAL;
3757 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02003758 }
3759
Willy Tarreau55ea7572007-06-17 19:56:27 +02003760 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02003761 err_code |= ERR_WARN;
Willy Tarreau55ea7572007-06-17 19:56:27 +02003762
3763 if (*(args[1]) == 0) {
3764 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02003765 err_code |= ERR_ALERT | ERR_FATAL;
3766 goto out;
Willy Tarreau55ea7572007-06-17 19:56:27 +02003767 }
3768
Willy Tarreauf51658d2014-04-23 01:21:56 +02003769 if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
3770 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
3771 Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
3772 file, linenum, errmsg);
3773 err_code |= ERR_ALERT | ERR_FATAL;
3774 goto out;
3775 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003776
Willy Tarreauf51658d2014-04-23 01:21:56 +02003777 err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
Willy Tarreau55ea7572007-06-17 19:56:27 +02003778 }
Willy Tarreau4f862642017-02-28 09:34:39 +01003779 else if (*args[2]) {
3780 Alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n",
3781 file, linenum, args[2]);
3782 err_code |= ERR_ALERT | ERR_FATAL;
3783 goto out;
3784 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003785
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003786 rule = calloc(1, sizeof(*rule));
Thierry FOURNIER / OZON.IO5948b012016-11-24 23:58:32 +01003787 if (!rule) {
3788 Alert("Out of memory error.\n");
3789 goto out;
3790 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003791 rule->cond = cond;
3792 rule->be.name = strdup(args[1]);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01003793 rule->line = linenum;
3794 rule->file = strdup(file);
3795 if (!rule->file) {
3796 Alert("Out of memory error.\n");
3797 goto out;
3798 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02003799 LIST_INIT(&rule->list);
3800 LIST_ADDQ(&curproxy->switching_rules, &rule->list);
3801 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003802 else if (strcmp(args[0], "use-server") == 0) {
3803 struct server_rule *rule;
3804
3805 if (curproxy == &defproxy) {
3806 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3807 err_code |= ERR_ALERT | ERR_FATAL;
3808 goto out;
3809 }
3810
3811 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
3812 err_code |= ERR_WARN;
3813
3814 if (*(args[1]) == 0) {
3815 Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]);
3816 err_code |= ERR_ALERT | ERR_FATAL;
3817 goto out;
3818 }
3819
3820 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
3821 Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
3822 file, linenum, args[0]);
3823 err_code |= ERR_ALERT | ERR_FATAL;
3824 goto out;
3825 }
3826
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003827 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
3828 Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
3829 file, linenum, errmsg);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003830 err_code |= ERR_ALERT | ERR_FATAL;
3831 goto out;
3832 }
3833
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003834 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003835
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003836 rule = calloc(1, sizeof(*rule));
Willy Tarreau4a5cade2012-04-05 21:09:48 +02003837 rule->cond = cond;
3838 rule->srv.name = strdup(args[1]);
3839 LIST_INIT(&rule->list);
3840 LIST_ADDQ(&curproxy->server_rules, &rule->list);
3841 curproxy->be_req_ana |= AN_REQ_SRV_RULES;
3842 }
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003843 else if ((!strcmp(args[0], "force-persist")) ||
3844 (!strcmp(args[0], "ignore-persist"))) {
3845 struct persist_rule *rule;
Willy Tarreau4de91492010-01-22 19:10:05 +01003846
3847 if (curproxy == &defproxy) {
3848 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
3849 err_code |= ERR_ALERT | ERR_FATAL;
3850 goto out;
3851 }
3852
3853 if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL))
3854 err_code |= ERR_WARN;
3855
Willy Tarreauef6494c2010-01-28 17:12:36 +01003856 if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) {
Willy Tarreau4de91492010-01-22 19:10:05 +01003857 Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
3858 file, linenum, args[0]);
3859 err_code |= ERR_ALERT | ERR_FATAL;
3860 goto out;
3861 }
3862
Willy Tarreaub7451bb2012-04-27 12:38:15 +02003863 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) {
3864 Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n",
3865 file, linenum, args[0], errmsg);
Willy Tarreau4de91492010-01-22 19:10:05 +01003866 err_code |= ERR_ALERT | ERR_FATAL;
3867 goto out;
3868 }
3869
Willy Tarreaua91d0a52013-03-25 08:12:18 +01003870 /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is
3871 * where force-persist is applied.
3872 */
3873 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum);
Willy Tarreau4de91492010-01-22 19:10:05 +01003874
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02003875 rule = calloc(1, sizeof(*rule));
Willy Tarreau4de91492010-01-22 19:10:05 +01003876 rule->cond = cond;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003877 if (!strcmp(args[0], "force-persist")) {
3878 rule->type = PERSIST_TYPE_FORCE;
3879 } else {
3880 rule->type = PERSIST_TYPE_IGNORE;
3881 }
Willy Tarreau4de91492010-01-22 19:10:05 +01003882 LIST_INIT(&rule->list);
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02003883 LIST_ADDQ(&curproxy->persist_rules, &rule->list);
Willy Tarreau4de91492010-01-22 19:10:05 +01003884 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003885 else if (!strcmp(args[0], "stick-table")) {
3886 int myidx = 1;
Willy Tarreaue45288c2015-05-26 10:49:46 +02003887 struct proxy *other;
3888
Willy Tarreaue2dc1fa2015-05-26 12:08:07 +02003889 other = proxy_tbl_by_name(curproxy->id);
Willy Tarreaue45288c2015-05-26 10:49:46 +02003890 if (other) {
3891 Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n",
3892 file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line);
3893 err_code |= ERR_ALERT | ERR_FATAL;
3894 goto out;
3895 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003896
Emeric Brun32da3c42010-09-23 18:39:19 +02003897 curproxy->table.id = curproxy->id;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003898 curproxy->table.type = (unsigned int)-1;
3899 while (*args[myidx]) {
3900 const char *err;
3901
3902 if (strcmp(args[myidx], "size") == 0) {
3903 myidx++;
3904 if (!*(args[myidx])) {
3905 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3906 file, linenum, args[myidx-1]);
3907 err_code |= ERR_ALERT | ERR_FATAL;
3908 goto out;
3909 }
3910 if ((err = parse_size_err(args[myidx], &curproxy->table.size))) {
3911 Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
3912 file, linenum, *err, args[myidx-1]);
3913 err_code |= ERR_ALERT | ERR_FATAL;
3914 goto out;
3915 }
Willy Tarreau0c559312010-01-26 18:36:26 +01003916 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003917 }
Emeric Brun32da3c42010-09-23 18:39:19 +02003918 else if (strcmp(args[myidx], "peers") == 0) {
3919 myidx++;
Godbach50523162013-12-11 19:48:57 +08003920 if (!*(args[myidx])) {
Godbachff115542014-04-21 21:52:23 +08003921 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3922 file, linenum, args[myidx-1]);
3923 err_code |= ERR_ALERT | ERR_FATAL;
3924 goto out;
Godbach50523162013-12-11 19:48:57 +08003925 }
Emeric Brun32da3c42010-09-23 18:39:19 +02003926 curproxy->table.peers.name = strdup(args[myidx++]);
3927 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003928 else if (strcmp(args[myidx], "expire") == 0) {
3929 myidx++;
3930 if (!*(args[myidx])) {
3931 Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n",
3932 file, linenum, args[myidx-1]);
3933 err_code |= ERR_ALERT | ERR_FATAL;
3934 goto out;
3935 }
3936 err = parse_time_err(args[myidx], &val, TIME_UNIT_MS);
3937 if (err) {
3938 Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n",
3939 file, linenum, *err, args[myidx-1]);
3940 err_code |= ERR_ALERT | ERR_FATAL;
3941 goto out;
3942 }
Ben Cabot3b90f0a2016-01-20 09:44:39 +00003943 if (val > INT_MAX) {
3944 Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n",
3945 file, linenum, val);
3946 err_code |= ERR_ALERT | ERR_FATAL;
3947 goto out;
3948 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01003949 curproxy->table.expire = val;
Willy Tarreau0c559312010-01-26 18:36:26 +01003950 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003951 }
3952 else if (strcmp(args[myidx], "nopurge") == 0) {
3953 curproxy->table.nopurge = 1;
Willy Tarreau0c559312010-01-26 18:36:26 +01003954 myidx++;
Emeric Brunb982a3d2010-01-04 15:45:53 +01003955 }
3956 else if (strcmp(args[myidx], "type") == 0) {
3957 myidx++;
3958 if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) {
3959 Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n",
3960 file, linenum, args[myidx]);
3961 err_code |= ERR_ALERT | ERR_FATAL;
3962 goto out;
3963 }
Willy Tarreau0c559312010-01-26 18:36:26 +01003964 /* myidx already points to next arg */
3965 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02003966 else if (strcmp(args[myidx], "store") == 0) {
Willy Tarreauac782882010-06-20 10:41:54 +02003967 int type, err;
Willy Tarreau888617d2010-06-20 09:11:39 +02003968 char *cw, *nw, *sa;
Willy Tarreau08d5f982010-06-06 13:34:54 +02003969
3970 myidx++;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02003971 nw = args[myidx];
3972 while (*nw) {
3973 /* the "store" keyword supports a comma-separated list */
3974 cw = nw;
Willy Tarreau888617d2010-06-20 09:11:39 +02003975 sa = NULL; /* store arg */
3976 while (*nw && *nw != ',') {
3977 if (*nw == '(') {
3978 *nw = 0;
3979 sa = ++nw;
3980 while (*nw != ')') {
3981 if (!*nw) {
3982 Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n",
3983 file, linenum, args[0], cw);
3984 err_code |= ERR_ALERT | ERR_FATAL;
3985 goto out;
3986 }
3987 nw++;
3988 }
3989 *nw = '\0';
3990 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02003991 nw++;
Willy Tarreau888617d2010-06-20 09:11:39 +02003992 }
Willy Tarreaub084e9c2010-06-19 07:12:36 +02003993 if (*nw)
3994 *nw++ = '\0';
3995 type = stktable_get_data_type(cw);
3996 if (type < 0) {
3997 Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n",
3998 file, linenum, args[0], cw);
3999 err_code |= ERR_ALERT | ERR_FATAL;
4000 goto out;
4001 }
Willy Tarreauac782882010-06-20 10:41:54 +02004002
4003 err = stktable_alloc_data_type(&curproxy->table, type, sa);
4004 switch (err) {
4005 case PE_NONE: break;
4006 case PE_EXIST:
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004007 Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
4008 file, linenum, args[0], cw);
4009 err_code |= ERR_WARN;
Willy Tarreauac782882010-06-20 10:41:54 +02004010 break;
4011
4012 case PE_ARG_MISSING:
4013 Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
4014 file, linenum, args[0], cw);
4015 err_code |= ERR_ALERT | ERR_FATAL;
4016 goto out;
4017
4018 case PE_ARG_NOT_USED:
4019 Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
4020 file, linenum, args[0], cw);
4021 err_code |= ERR_ALERT | ERR_FATAL;
4022 goto out;
4023
4024 default:
4025 Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
4026 file, linenum, args[0], cw);
4027 err_code |= ERR_ALERT | ERR_FATAL;
4028 goto out;
Willy Tarreaub084e9c2010-06-19 07:12:36 +02004029 }
Willy Tarreau08d5f982010-06-06 13:34:54 +02004030 }
4031 myidx++;
4032 }
Willy Tarreau0c559312010-01-26 18:36:26 +01004033 else {
4034 Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n",
4035 file, linenum, args[myidx]);
4036 err_code |= ERR_ALERT | ERR_FATAL;
4037 goto out;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004038 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004039 }
4040
4041 if (!curproxy->table.size) {
4042 Alert("parsing [%s:%d] : stick-table: missing size.\n",
4043 file, linenum);
4044 err_code |= ERR_ALERT | ERR_FATAL;
4045 goto out;
4046 }
4047
4048 if (curproxy->table.type == (unsigned int)-1) {
4049 Alert("parsing [%s:%d] : stick-table: missing type.\n",
4050 file, linenum);
4051 err_code |= ERR_ALERT | ERR_FATAL;
4052 goto out;
4053 }
4054 }
4055 else if (!strcmp(args[0], "stick")) {
Emeric Brunb982a3d2010-01-04 15:45:53 +01004056 struct sticking_rule *rule;
Willy Tarreau12785782012-04-27 21:37:17 +02004057 struct sample_expr *expr;
Emeric Brunb982a3d2010-01-04 15:45:53 +01004058 int myidx = 0;
4059 const char *name = NULL;
4060 int flags;
4061
4062 if (curproxy == &defproxy) {
4063 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
4064 err_code |= ERR_ALERT | ERR_FATAL;
4065 goto out;
4066 }
4067
4068 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) {
4069 err_code |= ERR_WARN;
4070 goto out;
4071 }
4072
4073 myidx++;
4074 if ((strcmp(args[myidx], "store") == 0) ||
4075 (strcmp(args[myidx], "store-request") == 0)) {
4076 myidx++;
4077 flags = STK_IS_STORE;
4078 }
4079 else if (strcmp(args[myidx], "store-response") == 0) {
4080 myidx++;
4081 flags = STK_IS_STORE | STK_ON_RSP;
4082 }
4083 else if (strcmp(args[myidx], "match") == 0) {
4084 myidx++;
4085 flags = STK_IS_MATCH;
4086 }
4087 else if (strcmp(args[myidx], "on") == 0) {
4088 myidx++;
4089 flags = STK_IS_MATCH | STK_IS_STORE;
4090 }
4091 else {
4092 Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]);
4093 err_code |= ERR_ALERT | ERR_FATAL;
4094 goto out;
4095 }
4096
4097 if (*(args[myidx]) == 0) {
4098 Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]);
4099 err_code |= ERR_ALERT | ERR_FATAL;
4100 goto out;
4101 }
4102
Willy Tarreaua4312fa2013-04-02 16:34:32 +02004103 curproxy->conf.args.ctx = ARGC_STK;
Thierry FOURNIEReeaa9512014-02-11 14:00:19 +01004104 expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004105 if (!expr) {
Willy Tarreau975c1782013-12-12 23:16:54 +01004106 Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004107 err_code |= ERR_ALERT | ERR_FATAL;
4108 goto out;
4109 }
4110
4111 if (flags & STK_ON_RSP) {
Willy Tarreau80aca902013-01-07 15:42:20 +01004112 if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) {
4113 Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n",
4114 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004115 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004116 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004117 goto out;
4118 }
4119 } else {
Willy Tarreau80aca902013-01-07 15:42:20 +01004120 if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) {
4121 Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n",
4122 file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004123 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004124 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004125 goto out;
4126 }
4127 }
4128
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004129 /* check if we need to allocate an hdr_idx struct for HTTP parsing */
Willy Tarreau25320b22013-03-24 07:22:08 +01004130 curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY);
Willy Tarreau1b6c00c2012-10-05 22:41:26 +02004131
Emeric Brunb982a3d2010-01-04 15:45:53 +01004132 if (strcmp(args[myidx], "table") == 0) {
4133 myidx++;
4134 name = args[myidx++];
4135 }
4136
Willy Tarreauef6494c2010-01-28 17:12:36 +01004137 if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02004138 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) {
4139 Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n",
4140 file, linenum, args[0], errmsg);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004141 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004142 free(expr);
Emeric Brunb982a3d2010-01-04 15:45:53 +01004143 goto out;
4144 }
Emeric Brunb982a3d2010-01-04 15:45:53 +01004145 }
Willy Tarreauef6494c2010-01-28 17:12:36 +01004146 else if (*(args[myidx])) {
4147 Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n",
4148 file, linenum, args[0], args[myidx]);
4149 err_code |= ERR_ALERT | ERR_FATAL;
Simon Horman5e55f5d2011-07-15 13:14:07 +09004150 free(expr);
Willy Tarreauef6494c2010-01-28 17:12:36 +01004151 goto out;
4152 }
Emeric Brun97679e72010-09-23 17:56:44 +02004153 if (flags & STK_ON_RSP)
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004154 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum);
Emeric Brun97679e72010-09-23 17:56:44 +02004155 else
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004156 err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum);
Willy Tarreauf1e98b82010-01-28 17:59:39 +01004157
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004158 rule = calloc(1, sizeof(*rule));
Emeric Brunb982a3d2010-01-04 15:45:53 +01004159 rule->cond = cond;
4160 rule->expr = expr;
4161 rule->flags = flags;
4162 rule->table.name = name ? strdup(name) : NULL;
4163 LIST_INIT(&rule->list);
4164 if (flags & STK_ON_RSP)
4165 LIST_ADDQ(&curproxy->storersp_rules, &rule->list);
4166 else
4167 LIST_ADDQ(&curproxy->sticking_rules, &rule->list);
4168 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004169 else if (!strcmp(args[0], "stats")) {
4170 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
4171 curproxy->uri_auth = NULL; /* we must detach from the default config */
4172
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004173 if (!*args[1]) {
4174 goto stats_error_parsing;
Cyril Bonté474be412010-10-12 00:14:36 +02004175 } else if (!strcmp(args[1], "admin")) {
4176 struct stats_admin_rule *rule;
4177
4178 if (curproxy == &defproxy) {
4179 Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
4180 err_code |= ERR_ALERT | ERR_FATAL;
4181 goto out;
4182 }
4183
4184 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4185 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4186 err_code |= ERR_ALERT | ERR_ABORT;
4187 goto out;
4188 }
4189
4190 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
4191 Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
4192 file, linenum, args[0], args[1]);
4193 err_code |= ERR_ALERT | ERR_FATAL;
4194 goto out;
4195 }
Willy Tarreaub7451bb2012-04-27 12:38:15 +02004196 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
4197 Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n",
4198 file, linenum, args[0], args[1], errmsg);
Cyril Bonté474be412010-10-12 00:14:36 +02004199 err_code |= ERR_ALERT | ERR_FATAL;
4200 goto out;
4201 }
4202
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004203 err_code |= warnif_cond_conflicts(cond,
4204 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4205 file, linenum);
Cyril Bonté474be412010-10-12 00:14:36 +02004206
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004207 rule = calloc(1, sizeof(*rule));
Cyril Bonté474be412010-10-12 00:14:36 +02004208 rule->cond = cond;
4209 LIST_INIT(&rule->list);
4210 LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004211 } else if (!strcmp(args[1], "uri")) {
4212 if (*(args[2]) == 0) {
4213 Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004214 err_code |= ERR_ALERT | ERR_FATAL;
4215 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004216 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
4217 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004218 err_code |= ERR_ALERT | ERR_ABORT;
4219 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004220 }
4221 } else if (!strcmp(args[1], "realm")) {
4222 if (*(args[2]) == 0) {
4223 Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004224 err_code |= ERR_ALERT | ERR_FATAL;
4225 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004226 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
4227 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004228 err_code |= ERR_ALERT | ERR_ABORT;
4229 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004230 }
Willy Tarreaubbd42122007-07-25 07:26:38 +02004231 } else if (!strcmp(args[1], "refresh")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +01004232 unsigned interval;
4233
4234 err = parse_time_err(args[2], &interval, TIME_UNIT_S);
4235 if (err) {
4236 Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n",
4237 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02004238 err_code |= ERR_ALERT | ERR_FATAL;
4239 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004240 } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
4241 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004242 err_code |= ERR_ALERT | ERR_ABORT;
4243 goto out;
Willy Tarreaubbd42122007-07-25 07:26:38 +02004244 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004245 } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004246 struct act_rule *rule;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004247
4248 if (curproxy == &defproxy) {
4249 Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
4250 err_code |= ERR_ALERT | ERR_FATAL;
4251 goto out;
4252 }
4253
4254 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4255 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4256 err_code |= ERR_ALERT | ERR_ABORT;
4257 goto out;
4258 }
4259
Willy Tarreauff011f22011-01-06 17:51:27 +01004260 if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02004261 !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004262 Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n",
4263 file, linenum, args[0]);
4264 err_code |= ERR_WARN;
4265 }
4266
Willy Tarreauff011f22011-01-06 17:51:27 +01004267 rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004268
Willy Tarreauff011f22011-01-06 17:51:27 +01004269 if (!rule) {
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004270 err_code |= ERR_ALERT | ERR_ABORT;
4271 goto out;
4272 }
4273
Willy Tarreaua91d0a52013-03-25 08:12:18 +01004274 err_code |= warnif_cond_conflicts(rule->cond,
4275 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
4276 file, linenum);
Willy Tarreauff011f22011-01-06 17:51:27 +01004277 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01004278
Willy Tarreaubaaee002006-06-26 02:48:02 +02004279 } else if (!strcmp(args[1], "auth")) {
4280 if (*(args[2]) == 0) {
4281 Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004282 err_code |= ERR_ALERT | ERR_FATAL;
4283 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004284 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
4285 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004286 err_code |= ERR_ALERT | ERR_ABORT;
4287 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004288 }
4289 } else if (!strcmp(args[1], "scope")) {
4290 if (*(args[2]) == 0) {
4291 Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004292 err_code |= ERR_ALERT | ERR_FATAL;
4293 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004294 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
4295 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004296 err_code |= ERR_ALERT | ERR_ABORT;
4297 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004298 }
4299 } else if (!strcmp(args[1], "enable")) {
4300 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
4301 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004302 err_code |= ERR_ALERT | ERR_ABORT;
4303 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004304 }
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004305 } else if (!strcmp(args[1], "hide-version")) {
4306 if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) {
4307 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02004308 err_code |= ERR_ALERT | ERR_ABORT;
4309 goto out;
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02004310 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004311 } else if (!strcmp(args[1], "show-legends")) {
4312 if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) {
4313 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4314 err_code |= ERR_ALERT | ERR_ABORT;
4315 goto out;
4316 }
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004317 } else if (!strcmp(args[1], "show-node")) {
4318
4319 if (*args[2]) {
4320 int i;
4321 char c;
4322
4323 for (i=0; args[2][i]; i++) {
4324 c = args[2][i];
Willy Tarreau88e05812010-03-03 00:16:00 +01004325 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
4326 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004327 break;
4328 }
4329
4330 if (!i || args[2][i]) {
4331 Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string"
4332 "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n",
4333 file, linenum, args[0], args[1]);
4334 err_code |= ERR_ALERT | ERR_FATAL;
4335 goto out;
4336 }
4337 }
4338
4339 if (!stats_set_node(&curproxy->uri_auth, args[2])) {
4340 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4341 err_code |= ERR_ALERT | ERR_ABORT;
4342 goto out;
4343 }
4344 } else if (!strcmp(args[1], "show-desc")) {
4345 char *desc = NULL;
4346
4347 if (*args[2]) {
4348 int i, len=0;
4349 char *d;
4350
Willy Tarreau348acfe2014-04-14 15:00:39 +02004351 for (i = 2; *args[i]; i++)
4352 len += strlen(args[i]) + 1;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004353
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004354 desc = d = calloc(1, len);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004355
Willy Tarreau348acfe2014-04-14 15:00:39 +02004356 d += snprintf(d, desc + len - d, "%s", args[2]);
4357 for (i = 3; *args[i]; i++)
4358 d += snprintf(d, desc + len - d, " %s", args[i]);
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004359 }
4360
4361 if (!*args[2] && !global.desc)
4362 Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n",
4363 file, linenum, args[1]);
4364 else {
4365 if (!stats_set_desc(&curproxy->uri_auth, desc)) {
4366 free(desc);
4367 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
4368 err_code |= ERR_ALERT | ERR_ABORT;
4369 goto out;
4370 }
4371 free(desc);
4372 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004373 } else {
Krzysztof Piotr Oledzki260a3bb2010-01-06 16:25:05 +01004374stats_error_parsing:
Cyril Bonté474be412010-10-12 00:14:36 +02004375 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 +01004376 file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004377 err_code |= ERR_ALERT | ERR_FATAL;
4378 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004379 }
4380 }
4381 else if (!strcmp(args[0], "option")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004382 int optnum;
4383
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004384 if (*(args[1]) == '\0') {
4385 Alert("parsing [%s:%d]: '%s' expects an option name.\n",
4386 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02004387 err_code |= ERR_ALERT | ERR_FATAL;
4388 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004389 }
Willy Tarreau13943ab2006-12-31 00:24:10 +01004390
4391 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
4392 if (!strcmp(args[1], cfg_opts[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004393 if (cfg_opts[optnum].cap == PR_CAP_NONE) {
4394 Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4395 file, linenum, cfg_opts[optnum].name);
4396 err_code |= ERR_ALERT | ERR_FATAL;
4397 goto out;
4398 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004399 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4400 goto out;
4401
Willy Tarreau93893792009-07-23 13:19:11 +02004402 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) {
4403 err_code |= ERR_WARN;
4404 goto out;
4405 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004406
Willy Tarreau3842f002009-06-14 11:39:52 +02004407 curproxy->no_options &= ~cfg_opts[optnum].val;
4408 curproxy->options &= ~cfg_opts[optnum].val;
4409
4410 switch (kwm) {
4411 case KWM_STD:
4412 curproxy->options |= cfg_opts[optnum].val;
4413 break;
4414 case KWM_NO:
4415 curproxy->no_options |= cfg_opts[optnum].val;
4416 break;
4417 case KWM_DEF: /* already cleared */
4418 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004419 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004420
Willy Tarreau93893792009-07-23 13:19:11 +02004421 goto out;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004422 }
4423 }
4424
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004425 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
4426 if (!strcmp(args[1], cfg_opts2[optnum].name)) {
Cyril Bonté62846b22010-11-01 19:26:00 +01004427 if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
4428 Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
4429 file, linenum, cfg_opts2[optnum].name);
4430 err_code |= ERR_ALERT | ERR_FATAL;
4431 goto out;
4432 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004433 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4434 goto out;
Willy Tarreau93893792009-07-23 13:19:11 +02004435 if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
4436 err_code |= ERR_WARN;
4437 goto out;
4438 }
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004439
Willy Tarreau3842f002009-06-14 11:39:52 +02004440 curproxy->no_options2 &= ~cfg_opts2[optnum].val;
4441 curproxy->options2 &= ~cfg_opts2[optnum].val;
4442
4443 switch (kwm) {
4444 case KWM_STD:
4445 curproxy->options2 |= cfg_opts2[optnum].val;
4446 break;
4447 case KWM_NO:
4448 curproxy->no_options2 |= cfg_opts2[optnum].val;
4449 break;
4450 case KWM_DEF: /* already cleared */
4451 break;
Willy Tarreau84b57da2009-06-14 11:10:45 +02004452 }
Willy Tarreau93893792009-07-23 13:19:11 +02004453 goto out;
Willy Tarreau66aa61f2009-01-18 21:44:07 +01004454 }
4455 }
4456
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004457 /* HTTP options override each other. They can be cancelled using
4458 * "no option xxx" which only switches to default mode if the mode
4459 * was this one (useful for cancelling options set in defaults
4460 * sections).
4461 */
4462 if (strcmp(args[1], "httpclose") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004463 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4464 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004465 if (kwm == KWM_STD) {
4466 curproxy->options &= ~PR_O_HTTP_MODE;
4467 curproxy->options |= PR_O_HTTP_PCL;
4468 goto out;
4469 }
4470 else if (kwm == KWM_NO) {
4471 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
4472 curproxy->options &= ~PR_O_HTTP_MODE;
4473 goto out;
4474 }
4475 }
4476 else if (strcmp(args[1], "forceclose") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004477 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4478 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004479 if (kwm == KWM_STD) {
4480 curproxy->options &= ~PR_O_HTTP_MODE;
4481 curproxy->options |= PR_O_HTTP_FCL;
4482 goto out;
4483 }
4484 else if (kwm == KWM_NO) {
4485 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
4486 curproxy->options &= ~PR_O_HTTP_MODE;
4487 goto out;
4488 }
4489 }
4490 else if (strcmp(args[1], "http-server-close") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004491 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4492 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004493 if (kwm == KWM_STD) {
4494 curproxy->options &= ~PR_O_HTTP_MODE;
4495 curproxy->options |= PR_O_HTTP_SCL;
4496 goto out;
4497 }
4498 else if (kwm == KWM_NO) {
4499 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL)
4500 curproxy->options &= ~PR_O_HTTP_MODE;
4501 goto out;
4502 }
4503 }
4504 else if (strcmp(args[1], "http-keep-alive") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004505 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4506 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004507 if (kwm == KWM_STD) {
4508 curproxy->options &= ~PR_O_HTTP_MODE;
4509 curproxy->options |= PR_O_HTTP_KAL;
4510 goto out;
4511 }
4512 else if (kwm == KWM_NO) {
4513 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL)
4514 curproxy->options &= ~PR_O_HTTP_MODE;
4515 goto out;
4516 }
4517 }
4518 else if (strcmp(args[1], "http-tunnel") == 0) {
William Lallemanddf1425a2015-04-28 20:17:49 +02004519 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4520 goto out;
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004521 if (kwm == KWM_STD) {
4522 curproxy->options &= ~PR_O_HTTP_MODE;
4523 curproxy->options |= PR_O_HTTP_TUN;
4524 goto out;
4525 }
4526 else if (kwm == KWM_NO) {
4527 if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
4528 curproxy->options &= ~PR_O_HTTP_MODE;
4529 goto out;
4530 }
4531 }
4532
Joseph Lynch726ab712015-05-11 23:25:34 -07004533 /* Redispatch can take an integer argument that control when the
4534 * resispatch occurs. All values are relative to the retries option.
4535 * This can be cancelled using "no option xxx".
4536 */
4537 if (strcmp(args[1], "redispatch") == 0) {
4538 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) {
4539 err_code |= ERR_WARN;
4540 goto out;
4541 }
4542
4543 curproxy->no_options &= ~PR_O_REDISP;
4544 curproxy->options &= ~PR_O_REDISP;
4545
4546 switch (kwm) {
4547 case KWM_STD:
4548 curproxy->options |= PR_O_REDISP;
4549 curproxy->redispatch_after = -1;
4550 if(*args[2]) {
4551 curproxy->redispatch_after = atol(args[2]);
4552 }
4553 break;
4554 case KWM_NO:
4555 curproxy->no_options |= PR_O_REDISP;
4556 curproxy->redispatch_after = 0;
4557 break;
4558 case KWM_DEF: /* already cleared */
4559 break;
4560 }
4561 goto out;
4562 }
4563
Willy Tarreau3842f002009-06-14 11:39:52 +02004564 if (kwm != KWM_STD) {
4565 Alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n",
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004566 file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004567 err_code |= ERR_ALERT | ERR_FATAL;
4568 goto out;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01004569 }
4570
Emeric Brun3a058f32009-06-30 18:26:00 +02004571 if (!strcmp(args[1], "httplog")) {
William Lallemand723b73a2012-02-08 16:37:49 +01004572 char *logformat;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004573 /* generate a complete HTTP log */
William Lallemand723b73a2012-02-08 16:37:49 +01004574 logformat = default_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004575 if (*(args[2]) != '\0') {
4576 if (!strcmp(args[2], "clf")) {
4577 curproxy->options2 |= PR_O2_CLFLOG;
William Lallemand723b73a2012-02-08 16:37:49 +01004578 logformat = clf_http_log_format;
Emeric Brun3a058f32009-06-30 18:26:00 +02004579 } else {
William Lallemand77063bc2015-05-28 18:02:48 +02004580 Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02004581 err_code |= ERR_ALERT | ERR_FATAL;
4582 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004583 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004584 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
4585 goto out;
Emeric Brun3a058f32009-06-30 18:26:00 +02004586 }
Willy Tarreau62a61232013-04-12 18:13:46 +02004587 if (curproxy->conf.logformat_string != default_http_log_format &&
4588 curproxy->conf.logformat_string != default_tcp_log_format &&
4589 curproxy->conf.logformat_string != clf_http_log_format)
4590 free(curproxy->conf.logformat_string);
4591 curproxy->conf.logformat_string = logformat;
4592
4593 free(curproxy->conf.lfs_file);
4594 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4595 curproxy->conf.lfs_line = curproxy->conf.args.line;
Emeric Brun3a058f32009-06-30 18:26:00 +02004596 }
William Lallemandbddd4fd2012-02-27 11:23:10 +01004597 else if (!strcmp(args[1], "tcplog")) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02004598 /* generate a detailed TCP log */
Willy Tarreau62a61232013-04-12 18:13:46 +02004599 if (curproxy->conf.logformat_string != default_http_log_format &&
4600 curproxy->conf.logformat_string != default_tcp_log_format &&
4601 curproxy->conf.logformat_string != clf_http_log_format)
4602 free(curproxy->conf.logformat_string);
4603 curproxy->conf.logformat_string = default_tcp_log_format;
4604
4605 free(curproxy->conf.lfs_file);
4606 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
4607 curproxy->conf.lfs_line = curproxy->conf.args.line;
William Lallemanddf1425a2015-04-28 20:17:49 +02004608
4609 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4610 goto out;
William Lallemandbddd4fd2012-02-27 11:23:10 +01004611 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02004612 else if (!strcmp(args[1], "tcpka")) {
Willy Tarreau87b09662015-04-03 00:22:06 +02004613 /* enable TCP keep-alives on client and server streams */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004614 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004615 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004616
William Lallemanddf1425a2015-04-28 20:17:49 +02004617 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4618 goto out;
4619
Willy Tarreau13943ab2006-12-31 00:24:10 +01004620 if (curproxy->cap & PR_CAP_FE)
4621 curproxy->options |= PR_O_TCP_CLI_KA;
4622 if (curproxy->cap & PR_CAP_BE)
4623 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004624 }
4625 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +01004626 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004627 err_code |= ERR_WARN;
4628
Willy Tarreaubaaee002006-06-26 02:48:02 +02004629 /* use HTTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004630 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004631 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004632 curproxy->options2 &= ~PR_O2_CHK_ANY;
4633 curproxy->options2 |= PR_O2_HTTP_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004634 if (!*args[2]) { /* no argument */
4635 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
4636 curproxy->check_len = strlen(DEF_CHECK_REQ);
4637 } else if (!*args[3]) { /* one argument : URI */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004638 int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004639 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004640 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004641 "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
Willy Tarreaubaaee002006-06-26 02:48:02 +02004642 } else { /* more arguments : METHOD URI [HTTP_VER] */
Willy Tarreaue9d87882010-01-27 11:28:42 +01004643 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004644 if (*args[4])
4645 reqlen += strlen(args[4]);
4646 else
4647 reqlen += strlen("HTTP/1.0");
4648
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004649 curproxy->check_req = malloc(reqlen);
Willy Tarreaubaaee002006-06-26 02:48:02 +02004650 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
Willy Tarreaue9d87882010-01-27 11:28:42 +01004651 "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
Willy Tarreaubaaee002006-06-26 02:48:02 +02004652 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004653 if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code))
4654 goto out;
Willy Tarreauf3c69202006-07-09 16:42:34 +02004655 }
4656 else if (!strcmp(args[1], "ssl-hello-chk")) {
4657 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01004658 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02004659 err_code |= ERR_WARN;
Willy Tarreau13943ab2006-12-31 00:24:10 +01004660
Willy Tarreaua534fea2008-08-03 12:19:50 +02004661 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004662 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004663 curproxy->options2 &= ~PR_O2_CHK_ANY;
Willy Tarreau07a54902010-03-29 18:33:29 +02004664 curproxy->options2 |= PR_O2_SSL3_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004665
4666 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4667 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02004668 }
Willy Tarreau23677902007-05-08 23:50:35 +02004669 else if (!strcmp(args[1], "smtpchk")) {
4670 /* use SMTP request to check servers' health */
Willy Tarreaua534fea2008-08-03 12:19:50 +02004671 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004672 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004673 curproxy->options2 &= ~PR_O2_CHK_ANY;
4674 curproxy->options2 |= PR_O2_SMTP_CHK;
Willy Tarreau23677902007-05-08 23:50:35 +02004675
4676 if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */
4677 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4678 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4679 } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */
4680 if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) {
4681 int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004682 curproxy->check_req = malloc(reqlen);
Willy Tarreau23677902007-05-08 23:50:35 +02004683 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
4684 "%s %s\r\n", args[2], args[3]); /* HELO hostname */
4685 } else {
4686 /* this just hits the default for now, but you could potentially expand it to allow for other stuff
4687 though, it's unlikely you'd want to send anything other than an EHLO or HELO */
4688 curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */
4689 curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ);
4690 }
4691 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004692 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4693 goto out;
Willy Tarreau23677902007-05-08 23:50:35 +02004694 }
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004695 else if (!strcmp(args[1], "pgsql-check")) {
4696 /* use PostgreSQL request to check servers' health */
4697 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4698 err_code |= ERR_WARN;
4699
4700 free(curproxy->check_req);
4701 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004702 curproxy->options2 &= ~PR_O2_CHK_ANY;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004703 curproxy->options2 |= PR_O2_PGSQL_CHK;
4704
4705 if (*(args[2])) {
4706 int cur_arg = 2;
4707
4708 while (*(args[cur_arg])) {
4709 if (strcmp(args[cur_arg], "user") == 0) {
4710 char * packet;
4711 uint32_t packet_len;
4712 uint32_t pv;
4713
4714 /* suboption header - needs additional argument for it */
4715 if (*(args[cur_arg+1]) == 0) {
4716 Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
4717 file, linenum, args[0], args[1], args[cur_arg]);
4718 err_code |= ERR_ALERT | ERR_FATAL;
4719 goto out;
4720 }
4721
4722 /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */
4723 packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1;
4724 pv = htonl(0x30000); /* protocol version 3.0 */
4725
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004726 packet = calloc(1, packet_len);
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004727
4728 memcpy(packet + 4, &pv, 4);
4729
4730 /* copy "user" */
4731 memcpy(packet + 8, "user", 4);
4732
4733 /* copy username */
4734 memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1]));
4735
4736 free(curproxy->check_req);
4737 curproxy->check_req = packet;
4738 curproxy->check_len = packet_len;
4739
4740 packet_len = htonl(packet_len);
4741 memcpy(packet, &packet_len, 4);
4742 cur_arg += 2;
4743 } else {
4744 /* unknown suboption - catchall */
4745 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
4746 file, linenum, args[0], args[1]);
4747 err_code |= ERR_ALERT | ERR_FATAL;
4748 goto out;
4749 }
4750 } /* end while loop */
4751 }
William Lallemanddf1425a2015-04-28 20:17:49 +02004752 if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code))
4753 goto out;
Rauf Kuliyev38b41562011-01-04 15:14:13 +01004754 }
4755
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004756 else if (!strcmp(args[1], "redis-check")) {
4757 /* use REDIS PING request to check servers' health */
4758 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4759 err_code |= ERR_WARN;
4760
4761 free(curproxy->check_req);
4762 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004763 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004764 curproxy->options2 |= PR_O2_REDIS_CHK;
4765
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004766 curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1);
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004767 memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1);
4768 curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02004769
4770 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4771 goto out;
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02004772 }
4773
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004774 else if (!strcmp(args[1], "mysql-check")) {
4775 /* use MYSQL request to check servers' health */
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004776 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4777 err_code |= ERR_WARN;
4778
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004779 free(curproxy->check_req);
Willy Tarreau54f6a582010-02-01 16:31:14 +01004780 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004781 curproxy->options2 &= ~PR_O2_CHK_ANY;
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004782 curproxy->options2 |= PR_O2_MYSQL_CHK;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004783
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004784 /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte.
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004785 * const char mysql40_client_auth_pkt[] = {
4786 * "\x0e\x00\x00" // packet length
4787 * "\x01" // packet number
4788 * "\x00\x00" // client capabilities
4789 * "\x00\x00\x01" // max packet
4790 * "haproxy\x00" // username (null terminated string)
4791 * "\x00" // filler (always 0x00)
4792 * "\x01\x00\x00" // packet length
4793 * "\x00" // packet number
4794 * "\x01" // COM_QUIT command
4795 * };
4796 */
4797
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004798 /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic.
4799 * const char mysql41_client_auth_pkt[] = {
4800 * "\x0e\x00\x00\" // packet length
4801 * "\x01" // packet number
4802 * "\x00\x00\x00\x00" // client capabilities
4803 * "\x00\x00\x00\x01" // max packet
4804 * "\x21" // character set (UTF-8)
4805 * char[23] // All zeroes
4806 * "haproxy\x00" // username (null terminated string)
4807 * "\x00" // filler (always 0x00)
4808 * "\x01\x00\x00" // packet length
4809 * "\x00" // packet number
4810 * "\x01" // COM_QUIT command
4811 * };
4812 */
4813
4814
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004815 if (*(args[2])) {
4816 int cur_arg = 2;
4817
4818 while (*(args[cur_arg])) {
4819 if (strcmp(args[cur_arg], "user") == 0) {
4820 char *mysqluser;
4821 int packetlen, reqlen, userlen;
4822
4823 /* suboption header - needs additional argument for it */
4824 if (*(args[cur_arg+1]) == 0) {
4825 Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
4826 file, linenum, args[0], args[1], args[cur_arg]);
4827 err_code |= ERR_ALERT | ERR_FATAL;
4828 goto out;
4829 }
4830 mysqluser = args[cur_arg + 1];
4831 userlen = strlen(mysqluser);
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004832
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004833 if (*(args[cur_arg+2])) {
4834 if (!strcmp(args[cur_arg+2], "post-41")) {
4835 packetlen = userlen + 7 + 27;
4836 reqlen = packetlen + 9;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004837
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004838 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004839 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004840 curproxy->check_len = reqlen;
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004841
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004842 snprintf(curproxy->check_req, 4, "%c%c%c",
4843 ((unsigned char) packetlen & 0xff),
4844 ((unsigned char) (packetlen >> 8) & 0xff),
4845 ((unsigned char) (packetlen >> 16) & 0xff));
4846
4847 curproxy->check_req[3] = 1;
4848 curproxy->check_req[5] = 130;
4849 curproxy->check_req[11] = 1;
4850 curproxy->check_req[12] = 33;
4851 memcpy(&curproxy->check_req[36], mysqluser, userlen);
4852 curproxy->check_req[36 + userlen + 1 + 1] = 1;
4853 curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1;
4854 cur_arg += 3;
4855 } else {
4856 Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]);
4857 err_code |= ERR_ALERT | ERR_FATAL;
4858 goto out;
4859 }
4860 } else {
4861 packetlen = userlen + 7;
4862 reqlen = packetlen + 9;
4863
4864 free(curproxy->check_req);
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004865 curproxy->check_req = calloc(1, reqlen);
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02004866 curproxy->check_len = reqlen;
4867
4868 snprintf(curproxy->check_req, 4, "%c%c%c",
4869 ((unsigned char) packetlen & 0xff),
4870 ((unsigned char) (packetlen >> 8) & 0xff),
4871 ((unsigned char) (packetlen >> 16) & 0xff));
4872
4873 curproxy->check_req[3] = 1;
4874 curproxy->check_req[5] = 128;
4875 curproxy->check_req[8] = 1;
4876 memcpy(&curproxy->check_req[9], mysqluser, userlen);
4877 curproxy->check_req[9 + userlen + 1 + 1] = 1;
4878 curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1;
4879 cur_arg += 2;
4880 }
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02004881 } else {
4882 /* unknown suboption - catchall */
4883 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
4884 file, linenum, args[0], args[1]);
4885 err_code |= ERR_ALERT | ERR_FATAL;
4886 goto out;
4887 }
4888 } /* end while loop */
4889 }
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01004890 }
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004891 else if (!strcmp(args[1], "ldap-check")) {
4892 /* use LDAP request to check servers' health */
4893 free(curproxy->check_req);
4894 curproxy->check_req = NULL;
Willy Tarreau1620ec32011-08-06 17:05:02 +02004895 curproxy->options2 &= ~PR_O2_CHK_ANY;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004896 curproxy->options2 |= PR_O2_LDAP_CHK;
4897
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02004898 curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1);
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004899 memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1);
4900 curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1;
William Lallemanddf1425a2015-04-28 20:17:49 +02004901 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4902 goto out;
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02004903 }
Christopher Fauletba7bc162016-11-07 21:07:38 +01004904 else if (!strcmp(args[1], "spop-check")) {
4905 if (curproxy == &defproxy) {
4906 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n",
4907 file, linenum, args[0], args[1]);
4908 err_code |= ERR_ALERT | ERR_FATAL;
4909 goto out;
4910 }
4911 if (curproxy->cap & PR_CAP_FE) {
4912 Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n",
4913 file, linenum, args[0], args[1]);
4914 err_code |= ERR_ALERT | ERR_FATAL;
4915 goto out;
4916 }
4917
4918 /* use SPOE request to check servers' health */
4919 free(curproxy->check_req);
4920 curproxy->check_req = NULL;
4921 curproxy->options2 &= ~PR_O2_CHK_ANY;
4922 curproxy->options2 |= PR_O2_SPOP_CHK;
4923
4924 if (prepare_spoe_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) {
4925 Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum);
4926 err_code |= ERR_ALERT | ERR_FATAL;
4927 goto out;
4928 }
4929 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4930 goto out;
4931 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004932 else if (!strcmp(args[1], "tcp-check")) {
4933 /* use raw TCPCHK send/expect to check servers' health */
4934 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
4935 err_code |= ERR_WARN;
4936
4937 free(curproxy->check_req);
4938 curproxy->check_req = NULL;
4939 curproxy->options2 &= ~PR_O2_CHK_ANY;
4940 curproxy->options2 |= PR_O2_TCPCHK_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004941 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4942 goto out;
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004943 }
Simon Horman98637e52014-06-20 12:30:16 +09004944 else if (!strcmp(args[1], "external-check")) {
4945 /* excute an external command to check servers' health */
4946 free(curproxy->check_req);
4947 curproxy->check_req = NULL;
4948 curproxy->options2 &= ~PR_O2_CHK_ANY;
4949 curproxy->options2 |= PR_O2_EXT_CHK;
William Lallemanddf1425a2015-04-28 20:17:49 +02004950 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
4951 goto out;
Simon Horman98637e52014-06-20 12:30:16 +09004952 }
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004953 else if (!strcmp(args[1], "forwardfor")) {
Ross Westaf72a1d2008-08-03 10:51:45 +02004954 int cur_arg;
4955
4956 /* insert x-forwarded-for field, but not for the IP address listed as an except.
4957 * set default options (ie: bitfield, header name, etc)
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004958 */
Ross Westaf72a1d2008-08-03 10:51:45 +02004959
Willy Tarreau87cf5142011-08-19 22:57:24 +02004960 curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS;
Ross Westaf72a1d2008-08-03 10:51:45 +02004961
4962 free(curproxy->fwdfor_hdr_name);
4963 curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
4964 curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR);
4965
4966 /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */
4967 cur_arg = 2;
4968 while (*(args[cur_arg])) {
4969 if (!strcmp(args[cur_arg], "except")) {
4970 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01004971 if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) {
Ross Westaf72a1d2008-08-03 10:51:45 +02004972 Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
4973 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02004974 err_code |= ERR_ALERT | ERR_FATAL;
4975 goto out;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004976 }
4977 /* flush useless bits */
4978 curproxy->except_net.s_addr &= curproxy->except_mask.s_addr;
Ross Westaf72a1d2008-08-03 10:51:45 +02004979 cur_arg += 2;
4980 } else if (!strcmp(args[cur_arg], "header")) {
4981 /* suboption header - needs additional argument for it */
4982 if (*(args[cur_arg+1]) == 0) {
4983 Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
4984 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02004985 err_code |= ERR_ALERT | ERR_FATAL;
4986 goto out;
Ross Westaf72a1d2008-08-03 10:51:45 +02004987 }
4988 free(curproxy->fwdfor_hdr_name);
4989 curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
4990 curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name);
4991 cur_arg += 2;
Willy Tarreau87cf5142011-08-19 22:57:24 +02004992 } else if (!strcmp(args[cur_arg], "if-none")) {
4993 curproxy->options &= ~PR_O_FF_ALWAYS;
4994 cur_arg += 1;
Willy Tarreau7ac51f62007-03-25 16:00:04 +02004995 } else {
Ross Westaf72a1d2008-08-03 10:51:45 +02004996 /* unknown suboption - catchall */
Willy Tarreau87cf5142011-08-19 22:57:24 +02004997 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n",
Ross Westaf72a1d2008-08-03 10:51:45 +02004998 file, linenum, args[0], args[1]);
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 }
Ross Westaf72a1d2008-08-03 10:51:45 +02005002 } /* end while loop */
Willy Tarreau7ac51f62007-03-25 16:00:04 +02005003 }
Maik Broemme2850cb42009-04-17 18:53:21 +02005004 else if (!strcmp(args[1], "originalto")) {
5005 int cur_arg;
5006
5007 /* insert x-original-to field, but not for the IP address listed as an except.
5008 * set default options (ie: bitfield, header name, etc)
5009 */
5010
5011 curproxy->options |= PR_O_ORGTO;
5012
5013 free(curproxy->orgto_hdr_name);
5014 curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
5015 curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR);
5016
Willy Tarreau87cf5142011-08-19 22:57:24 +02005017 /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */
Maik Broemme2850cb42009-04-17 18:53:21 +02005018 cur_arg = 2;
5019 while (*(args[cur_arg])) {
5020 if (!strcmp(args[cur_arg], "except")) {
5021 /* suboption except - needs additional argument for it */
Thierry FOURNIERfc7ac7b2014-02-11 15:23:04 +01005022 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 +02005023 Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n",
5024 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005025 err_code |= ERR_ALERT | ERR_FATAL;
5026 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005027 }
5028 /* flush useless bits */
5029 curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr;
5030 cur_arg += 2;
5031 } else if (!strcmp(args[cur_arg], "header")) {
5032 /* suboption header - needs additional argument for it */
5033 if (*(args[cur_arg+1]) == 0) {
5034 Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n",
5035 file, linenum, args[0], args[1], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02005036 err_code |= ERR_ALERT | ERR_FATAL;
5037 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005038 }
5039 free(curproxy->orgto_hdr_name);
5040 curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
5041 curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name);
5042 cur_arg += 2;
5043 } else {
5044 /* unknown suboption - catchall */
5045 Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n",
5046 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005047 err_code |= ERR_ALERT | ERR_FATAL;
5048 goto out;
Maik Broemme2850cb42009-04-17 18:53:21 +02005049 }
5050 } /* end while loop */
5051 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005052 else {
5053 Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005054 err_code |= ERR_ALERT | ERR_FATAL;
5055 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005056 }
Willy Tarreau93893792009-07-23 13:19:11 +02005057 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005058 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005059 else if (!strcmp(args[0], "default_backend")) {
5060 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005061 err_code |= ERR_WARN;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005062
5063 if (*(args[1]) == 0) {
5064 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005065 err_code |= ERR_ALERT | ERR_FATAL;
5066 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005067 }
Willy Tarreaua534fea2008-08-03 12:19:50 +02005068 free(curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005069 curproxy->defbe.name = strdup(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005070
5071 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5072 goto out;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01005073 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005074 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01005075 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005076 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005077
Willy Tarreaua3c504c2014-04-28 22:37:32 +02005078 if (!already_warned(WARN_REDISPATCH_DEPRECATED))
5079 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 +01005080 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005081 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005082 /* enable reconnections to dispatch */
5083 curproxy->options |= PR_O_REDISP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005084
5085 if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
5086 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005087 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005088 else if (!strcmp(args[0], "http-reuse")) {
5089 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5090 err_code |= ERR_WARN;
5091
5092 if (strcmp(args[1], "never") == 0) {
5093 /* enable a graceful server shutdown on an HTTP 404 response */
5094 curproxy->options &= ~PR_O_REUSE_MASK;
5095 curproxy->options |= PR_O_REUSE_NEVR;
5096 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5097 goto out;
5098 }
Willy Tarreau161d45f2015-08-05 16:02:46 +02005099 else if (strcmp(args[1], "safe") == 0) {
5100 /* enable a graceful server shutdown on an HTTP 404 response */
5101 curproxy->options &= ~PR_O_REUSE_MASK;
5102 curproxy->options |= PR_O_REUSE_SAFE;
5103 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5104 goto out;
5105 }
Willy Tarreau449d74a2015-08-05 17:16:33 +02005106 else if (strcmp(args[1], "aggressive") == 0) {
5107 curproxy->options &= ~PR_O_REUSE_MASK;
5108 curproxy->options |= PR_O_REUSE_AGGR;
5109 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5110 goto out;
5111 }
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005112 else if (strcmp(args[1], "always") == 0) {
5113 /* enable a graceful server shutdown on an HTTP 404 response */
5114 curproxy->options &= ~PR_O_REUSE_MASK;
5115 curproxy->options |= PR_O_REUSE_ALWS;
5116 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5117 goto out;
5118 }
5119 else {
Willy Tarreau449d74a2015-08-05 17:16:33 +02005120 Alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]);
Willy Tarreaud8fecee2015-08-05 14:12:31 +02005121 err_code |= ERR_ALERT | ERR_FATAL;
5122 goto out;
5123 }
5124 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005125 else if (!strcmp(args[0], "http-check")) {
5126 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005127 err_code |= ERR_WARN;
Willy Tarreau48494c02007-11-30 10:41:39 +01005128
5129 if (strcmp(args[1], "disable-on-404") == 0) {
5130 /* enable a graceful server shutdown on an HTTP 404 response */
5131 curproxy->options |= PR_O_DISABLE404;
William Lallemanddf1425a2015-04-28 20:17:49 +02005132 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5133 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005134 }
Willy Tarreauef781042010-01-27 11:53:01 +01005135 else if (strcmp(args[1], "send-state") == 0) {
5136 /* enable emission of the apparent state of a server in HTTP checks */
5137 curproxy->options2 |= PR_O2_CHK_SNDST;
William Lallemanddf1425a2015-04-28 20:17:49 +02005138 if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
5139 goto out;
Willy Tarreauef781042010-01-27 11:53:01 +01005140 }
Willy Tarreaubd741542010-03-16 18:46:54 +01005141 else if (strcmp(args[1], "expect") == 0) {
5142 const char *ptr_arg;
5143 int cur_arg;
5144
5145 if (curproxy->options2 & PR_O2_EXP_TYPE) {
5146 Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
5147 err_code |= ERR_ALERT | ERR_FATAL;
5148 goto out;
5149 }
5150
5151 cur_arg = 2;
5152 /* consider exclamation marks, sole or at the beginning of a word */
5153 while (*(ptr_arg = args[cur_arg])) {
5154 while (*ptr_arg == '!') {
5155 curproxy->options2 ^= PR_O2_EXP_INV;
5156 ptr_arg++;
5157 }
5158 if (*ptr_arg)
5159 break;
5160 cur_arg++;
5161 }
5162 /* now ptr_arg points to the beginning of a word past any possible
5163 * exclamation mark, and cur_arg is the argument which holds this word.
5164 */
5165 if (strcmp(ptr_arg, "status") == 0) {
5166 if (!*(args[cur_arg + 1])) {
5167 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5168 file, linenum, args[0], args[1], ptr_arg);
5169 err_code |= ERR_ALERT | ERR_FATAL;
5170 goto out;
5171 }
5172 curproxy->options2 |= PR_O2_EXP_STS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005173 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005174 curproxy->expect_str = strdup(args[cur_arg + 1]);
5175 }
5176 else if (strcmp(ptr_arg, "string") == 0) {
5177 if (!*(args[cur_arg + 1])) {
5178 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5179 file, linenum, args[0], args[1], ptr_arg);
5180 err_code |= ERR_ALERT | ERR_FATAL;
5181 goto out;
5182 }
5183 curproxy->options2 |= PR_O2_EXP_STR;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005184 free(curproxy->expect_str);
Willy Tarreaubd741542010-03-16 18:46:54 +01005185 curproxy->expect_str = strdup(args[cur_arg + 1]);
5186 }
5187 else if (strcmp(ptr_arg, "rstatus") == 0) {
5188 if (!*(args[cur_arg + 1])) {
5189 Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5190 file, linenum, args[0], args[1], ptr_arg);
5191 err_code |= ERR_ALERT | ERR_FATAL;
5192 goto out;
5193 }
5194 curproxy->options2 |= PR_O2_EXP_RSTS;
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005195 free(curproxy->expect_str);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005196 if (curproxy->expect_regex) {
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005197 regex_free(curproxy->expect_regex);
Thierry FOURNIER148f4082014-06-11 14:45:31 +02005198 free(curproxy->expect_regex);
5199 curproxy->expect_regex = NULL;
5200 }
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005201 curproxy->expect_str = strdup(args[cur_arg + 1]);
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005202 curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex));
5203 error = NULL;
5204 if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) {
5205 Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5206 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
5207 free(error);
Willy Tarreaubd741542010-03-16 18:46:54 +01005208 err_code |= ERR_ALERT | ERR_FATAL;
5209 goto out;
5210 }
5211 }
5212 else if (strcmp(ptr_arg, "rstring") == 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_RSTR;
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 {
5238 Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n",
5239 file, linenum, args[0], args[1], ptr_arg);
5240 err_code |= ERR_ALERT | ERR_FATAL;
5241 goto out;
5242 }
5243 }
Willy Tarreau48494c02007-11-30 10:41:39 +01005244 else {
Willy Tarreau1ee51a62011-08-19 20:04:17 +02005245 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 +02005246 err_code |= ERR_ALERT | ERR_FATAL;
5247 goto out;
Willy Tarreau48494c02007-11-30 10:41:39 +01005248 }
5249 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005250 else if (!strcmp(args[0], "tcp-check")) {
5251 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5252 err_code |= ERR_WARN;
5253
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005254 if (strcmp(args[1], "comment") == 0) {
5255 int cur_arg;
5256 struct tcpcheck_rule *tcpcheck;
5257
5258 cur_arg = 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005259 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005260 tcpcheck->action = TCPCHK_ACT_COMMENT;
5261
5262 if (!*args[cur_arg + 1]) {
5263 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5264 file, linenum, args[cur_arg]);
5265 err_code |= ERR_ALERT | ERR_FATAL;
5266 goto out;
5267 }
5268
5269 tcpcheck->comment = strdup(args[cur_arg + 1]);
5270
5271 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
William Lallemanddf1425a2015-04-28 20:17:49 +02005272 if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code))
5273 goto out;
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005274 }
5275 else if (strcmp(args[1], "connect") == 0) {
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005276 const char *ptr_arg;
5277 int cur_arg;
5278 struct tcpcheck_rule *tcpcheck;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005279
5280 /* check if first rule is also a 'connect' action */
Willy Tarreau5581c272015-05-13 12:24:53 +02005281 tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list);
5282 while (&tcpcheck->list != &curproxy->tcpcheck_rules &&
5283 tcpcheck->action == TCPCHK_ACT_COMMENT) {
5284 tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list);
5285 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005286
Willy Tarreau5581c272015-05-13 12:24:53 +02005287 if (&tcpcheck->list != &curproxy->tcpcheck_rules
5288 && tcpcheck->action != TCPCHK_ACT_CONNECT) {
5289 Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
5290 file, linenum);
5291 err_code |= ERR_ALERT | ERR_FATAL;
5292 goto out;
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005293 }
5294
5295 cur_arg = 2;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005296 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005297 tcpcheck->action = TCPCHK_ACT_CONNECT;
5298
5299 /* parsing each parameters to fill up the rule */
5300 while (*(ptr_arg = args[cur_arg])) {
5301 /* tcp port */
5302 if (strcmp(args[cur_arg], "port") == 0) {
5303 if ( (atol(args[cur_arg + 1]) > 65535) ||
5304 (atol(args[cur_arg + 1]) < 1) ){
5305 Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n",
5306 file, linenum, args[0], args[1], "port", args[cur_arg + 1]);
5307 err_code |= ERR_ALERT | ERR_FATAL;
5308 goto out;
5309 }
5310 tcpcheck->port = atol(args[cur_arg + 1]);
5311 cur_arg += 2;
5312 }
5313 /* send proxy protocol */
5314 else if (strcmp(args[cur_arg], "send-proxy") == 0) {
5315 tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY;
5316 cur_arg++;
5317 }
5318#ifdef USE_OPENSSL
5319 else if (strcmp(args[cur_arg], "ssl") == 0) {
5320 curproxy->options |= PR_O_TCPCHK_SSL;
5321 tcpcheck->conn_opts |= TCPCHK_OPT_SSL;
5322 cur_arg++;
5323 }
5324#endif /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005325 /* comment for this tcpcheck line */
5326 else if (strcmp(args[cur_arg], "comment") == 0) {
5327 if (!*args[cur_arg + 1]) {
5328 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5329 file, linenum, args[cur_arg]);
5330 err_code |= ERR_ALERT | ERR_FATAL;
5331 goto out;
5332 }
5333 tcpcheck->comment = strdup(args[cur_arg + 1]);
5334 cur_arg += 2;
5335 }
Baptiste Assmann69e273f2013-12-11 00:52:19 +01005336 else {
5337#ifdef USE_OPENSSL
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005338 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 +01005339#else /* USE_OPENSSL */
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005340 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 +01005341#endif /* USE_OPENSSL */
5342 file, linenum, args[0], args[1], args[cur_arg]);
5343 err_code |= ERR_ALERT | ERR_FATAL;
5344 goto out;
5345 }
5346
5347 }
5348
5349 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5350 }
5351 else if (strcmp(args[1], "send") == 0) {
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005352 if (! *(args[2]) ) {
5353 /* SEND string expected */
5354 Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n",
5355 file, linenum, args[0], args[1], args[2]);
5356 err_code |= ERR_ALERT | ERR_FATAL;
5357 goto out;
5358 } else {
5359 struct tcpcheck_rule *tcpcheck;
5360
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005361 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005362
5363 tcpcheck->action = TCPCHK_ACT_SEND;
5364 tcpcheck->string_len = strlen(args[2]);
5365 tcpcheck->string = strdup(args[2]);
5366 tcpcheck->expect_regex = NULL;
5367
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005368 /* comment for this tcpcheck line */
5369 if (strcmp(args[3], "comment") == 0) {
5370 if (!*args[4]) {
5371 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5372 file, linenum, args[3]);
5373 err_code |= ERR_ALERT | ERR_FATAL;
5374 goto out;
5375 }
5376 tcpcheck->comment = strdup(args[4]);
5377 }
5378
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005379 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5380 }
5381 }
5382 else if (strcmp(args[1], "send-binary") == 0) {
5383 if (! *(args[2]) ) {
5384 /* SEND binary string expected */
5385 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n",
5386 file, linenum, args[0], args[1], args[2]);
5387 err_code |= ERR_ALERT | ERR_FATAL;
5388 goto out;
5389 } else {
5390 struct tcpcheck_rule *tcpcheck;
5391 char *err = NULL;
5392
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005393 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005394
5395 tcpcheck->action = TCPCHK_ACT_SEND;
5396 if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
5397 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5398 file, linenum, args[0], args[1], args[2], err);
5399 err_code |= ERR_ALERT | ERR_FATAL;
5400 goto out;
5401 }
5402 tcpcheck->expect_regex = NULL;
5403
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005404 /* comment for this tcpcheck line */
5405 if (strcmp(args[3], "comment") == 0) {
5406 if (!*args[4]) {
5407 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5408 file, linenum, args[3]);
5409 err_code |= ERR_ALERT | ERR_FATAL;
5410 goto out;
5411 }
5412 tcpcheck->comment = strdup(args[4]);
5413 }
5414
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005415 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5416 }
5417 }
5418 else if (strcmp(args[1], "expect") == 0) {
5419 const char *ptr_arg;
5420 int cur_arg;
5421 int inverse = 0;
5422
5423 if (curproxy->options2 & PR_O2_EXP_TYPE) {
5424 Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]);
5425 err_code |= ERR_ALERT | ERR_FATAL;
5426 goto out;
5427 }
5428
5429 cur_arg = 2;
5430 /* consider exclamation marks, sole or at the beginning of a word */
5431 while (*(ptr_arg = args[cur_arg])) {
5432 while (*ptr_arg == '!') {
5433 inverse = !inverse;
5434 ptr_arg++;
5435 }
5436 if (*ptr_arg)
5437 break;
5438 cur_arg++;
5439 }
5440 /* now ptr_arg points to the beginning of a word past any possible
5441 * exclamation mark, and cur_arg is the argument which holds this word.
5442 */
5443 if (strcmp(ptr_arg, "binary") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005444 struct tcpcheck_rule *tcpcheck;
5445 char *err = NULL;
5446
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005447 if (!*(args[cur_arg + 1])) {
5448 Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n",
5449 file, linenum, args[0], args[1], ptr_arg);
5450 err_code |= ERR_ALERT | ERR_FATAL;
5451 goto out;
5452 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005453
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005454 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005455
5456 tcpcheck->action = TCPCHK_ACT_EXPECT;
5457 if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) {
5458 Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n",
5459 file, linenum, args[0], args[1], args[2], err);
5460 err_code |= ERR_ALERT | ERR_FATAL;
5461 goto out;
5462 }
5463 tcpcheck->expect_regex = NULL;
5464 tcpcheck->inverse = inverse;
5465
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005466 /* tcpcheck comment */
5467 cur_arg += 2;
5468 if (strcmp(args[cur_arg], "comment") == 0) {
5469 if (!*args[cur_arg + 1]) {
5470 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5471 file, linenum, args[cur_arg + 1]);
5472 err_code |= ERR_ALERT | ERR_FATAL;
5473 goto out;
5474 }
5475 tcpcheck->comment = strdup(args[cur_arg + 1]);
5476 }
5477
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005478 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5479 }
5480 else if (strcmp(ptr_arg, "string") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005481 struct tcpcheck_rule *tcpcheck;
5482
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005483 if (!*(args[cur_arg + 1])) {
5484 Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n",
5485 file, linenum, args[0], args[1], ptr_arg);
5486 err_code |= ERR_ALERT | ERR_FATAL;
5487 goto out;
5488 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005489
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005490 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005491
5492 tcpcheck->action = TCPCHK_ACT_EXPECT;
5493 tcpcheck->string_len = strlen(args[cur_arg + 1]);
5494 tcpcheck->string = strdup(args[cur_arg + 1]);
5495 tcpcheck->expect_regex = NULL;
5496 tcpcheck->inverse = inverse;
5497
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005498 /* tcpcheck comment */
5499 cur_arg += 2;
5500 if (strcmp(args[cur_arg], "comment") == 0) {
5501 if (!*args[cur_arg + 1]) {
5502 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5503 file, linenum, args[cur_arg + 1]);
5504 err_code |= ERR_ALERT | ERR_FATAL;
5505 goto out;
5506 }
5507 tcpcheck->comment = strdup(args[cur_arg + 1]);
5508 }
5509
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005510 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5511 }
5512 else if (strcmp(ptr_arg, "rstring") == 0) {
Willy Tarreaue7acee72015-02-27 16:37:05 +01005513 struct tcpcheck_rule *tcpcheck;
5514
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005515 if (!*(args[cur_arg + 1])) {
5516 Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
5517 file, linenum, args[0], args[1], ptr_arg);
5518 err_code |= ERR_ALERT | ERR_FATAL;
5519 goto out;
5520 }
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005521
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02005522 tcpcheck = calloc(1, sizeof(*tcpcheck));
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005523
5524 tcpcheck->action = TCPCHK_ACT_EXPECT;
5525 tcpcheck->string_len = 0;
5526 tcpcheck->string = NULL;
Thierry FOURNIER09af0d62014-06-18 11:35:54 +02005527 tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex));
5528 error = NULL;
5529 if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) {
5530 Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n",
5531 file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error);
5532 free(error);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005533 err_code |= ERR_ALERT | ERR_FATAL;
5534 goto out;
5535 }
5536 tcpcheck->inverse = inverse;
5537
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005538 /* tcpcheck comment */
5539 cur_arg += 2;
5540 if (strcmp(args[cur_arg], "comment") == 0) {
5541 if (!*args[cur_arg + 1]) {
5542 Alert("parsing [%s:%d] : '%s' expects a comment string.\n",
5543 file, linenum, args[cur_arg + 1]);
5544 err_code |= ERR_ALERT | ERR_FATAL;
5545 goto out;
5546 }
5547 tcpcheck->comment = strdup(args[cur_arg + 1]);
5548 }
5549
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005550 LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list);
5551 }
5552 else {
5553 Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n",
5554 file, linenum, args[0], args[1], ptr_arg);
5555 err_code |= ERR_ALERT | ERR_FATAL;
5556 goto out;
5557 }
5558 }
5559 else {
Baptiste Assmann22b09d22015-05-01 08:03:04 +02005560 Alert("parsing [%s:%d] : '%s' only supports 'comment', 'connect', 'send' or 'expect'.\n", file, linenum, args[0]);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02005561 err_code |= ERR_ALERT | ERR_FATAL;
5562 goto out;
5563 }
5564 }
Willy Tarreaub80c2302007-11-30 20:51:32 +01005565 else if (!strcmp(args[0], "monitor")) {
Willy Tarreaub099aca2008-10-12 17:26:37 +02005566 if (curproxy == &defproxy) {
5567 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005568 err_code |= ERR_ALERT | ERR_FATAL;
5569 goto out;
Willy Tarreaub099aca2008-10-12 17:26:37 +02005570 }
5571
Willy Tarreaub80c2302007-11-30 20:51:32 +01005572 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005573 err_code |= ERR_WARN;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005574
5575 if (strcmp(args[1], "fail") == 0) {
5576 /* add a condition to fail monitor requests */
Willy Tarreauef6494c2010-01-28 17:12:36 +01005577 if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
Willy Tarreaub80c2302007-11-30 20:51:32 +01005578 Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
5579 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005580 err_code |= ERR_ALERT | ERR_FATAL;
5581 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005582 }
5583
Willy Tarreaub7451bb2012-04-27 12:38:15 +02005584 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
5585 Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n",
5586 file, linenum, args[0], args[1], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005587 err_code |= ERR_ALERT | ERR_FATAL;
5588 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005589 }
5590 LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list);
5591 }
5592 else {
5593 Alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005594 err_code |= ERR_ALERT | ERR_FATAL;
5595 goto out;
Willy Tarreaub80c2302007-11-30 20:51:32 +01005596 }
5597 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005598#ifdef TPROXY
5599 else if (!strcmp(args[0], "transparent")) {
5600 /* enable transparent proxy connections */
5601 curproxy->options |= PR_O_TRANSP;
William Lallemanddf1425a2015-04-28 20:17:49 +02005602 if (alertif_too_many_args(0, file, linenum, args, &err_code))
5603 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005604 }
5605#endif
5606 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005607 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005608 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005609
Willy Tarreaubaaee002006-06-26 02:48:02 +02005610 if (*(args[1]) == 0) {
5611 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005612 err_code |= ERR_ALERT | ERR_FATAL;
5613 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005614 }
5615 curproxy->maxconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005616 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5617 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005618 }
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005619 else if (!strcmp(args[0], "backlog")) { /* backlog */
5620 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005621 err_code |= ERR_WARN;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005622
5623 if (*(args[1]) == 0) {
5624 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005625 err_code |= ERR_ALERT | ERR_FATAL;
5626 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005627 }
5628 curproxy->backlog = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005629 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5630 goto out;
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01005631 }
Willy Tarreau86034312006-12-29 00:10:33 +01005632 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005633 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
Willy Tarreau93893792009-07-23 13:19:11 +02005634 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005635
Willy Tarreau86034312006-12-29 00:10:33 +01005636 if (*(args[1]) == 0) {
5637 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005638 err_code |= ERR_ALERT | ERR_FATAL;
5639 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005640 }
5641 curproxy->fullconn = atol(args[1]);
William Lallemanddf1425a2015-04-28 20:17:49 +02005642 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5643 goto out;
Willy Tarreau86034312006-12-29 00:10:33 +01005644 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005645 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
5646 if (*(args[1]) == 0) {
5647 Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005648 err_code |= ERR_ALERT | ERR_FATAL;
5649 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005650 }
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005651 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
5652 if (err) {
5653 Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n",
5654 file, linenum, *err);
Willy Tarreau93893792009-07-23 13:19:11 +02005655 err_code |= ERR_ALERT | ERR_FATAL;
5656 goto out;
Willy Tarreaub3f32f52007-12-02 22:15:14 +01005657 }
5658 curproxy->grace = val;
William Lallemanddf1425a2015-04-28 20:17:49 +02005659 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5660 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005661 }
5662 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
David du Colombier6f5ccb12011-03-10 22:26:24 +01005663 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005664 int port1, port2;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005665 struct protocol *proto;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005666
Willy Tarreaubaaee002006-06-26 02:48:02 +02005667 if (curproxy == &defproxy) {
5668 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02005669 err_code |= ERR_ALERT | ERR_FATAL;
5670 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005671 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01005672 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005673 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005674
Willy Tarreau48ef4c92017-01-06 18:32:38 +01005675 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005676 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01005677 Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg);
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005678 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005679 goto out;
5680 }
Willy Tarreauf3559bf2013-03-06 16:52:04 +01005681
5682 proto = protocol_by_family(sk->ss_family);
5683 if (!proto || !proto->connect) {
5684 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
5685 file, linenum, args[0], args[1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005686 err_code |= ERR_ALERT | ERR_FATAL;
5687 goto out;
5688 }
5689
5690 if (port1 != port2) {
5691 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n",
5692 file, linenum, args[0], args[1]);
Willy Tarreau93893792009-07-23 13:19:11 +02005693 err_code |= ERR_ALERT | ERR_FATAL;
5694 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005695 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005696
5697 if (!port1) {
5698 Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n",
5699 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01005700 err_code |= ERR_ALERT | ERR_FATAL;
5701 goto out;
5702 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01005703
William Lallemanddf1425a2015-04-28 20:17:49 +02005704 if (alertif_too_many_args(1, file, linenum, args, &err_code))
5705 goto out;
5706
Willy Tarreaud5191e72010-02-09 20:50:45 +01005707 curproxy->dispatch_addr = *sk;
Willy Tarreau1620ec32011-08-06 17:05:02 +02005708 curproxy->options |= PR_O_DISPATCH;
Willy Tarreaubaaee002006-06-26 02:48:02 +02005709 }
5710 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01005711 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02005712 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01005713
Willy Tarreaua93c74b2012-05-08 18:14:39 +02005714 if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
5715 Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02005716 err_code |= ERR_ALERT | ERR_FATAL;
5717 goto out;
Willy Tarreau2fcb5002007-05-08 13:35:26 +02005718 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005719 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005720 else if (!strcmp(args[0], "hash-type")) { /* set hashing method */
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005721 /**
5722 * The syntax for hash-type config element is
5723 * hash-type {map-based|consistent} [[<algo>] avalanche]
5724 *
5725 * The default hash function is sdbm for map-based and sdbm+avalanche for consistent.
5726 */
5727 curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
Bhaskar98634f02013-10-29 23:30:51 -04005728
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005729 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
5730 err_code |= ERR_WARN;
5731
5732 if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005733 curproxy->lbprm.algo |= BE_LB_HASH_CONS;
5734 }
5735 else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005736 curproxy->lbprm.algo |= BE_LB_HASH_MAP;
5737 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005738 else if (strcmp(args[1], "avalanche") == 0) {
5739 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]);
5740 err_code |= ERR_ALERT | ERR_FATAL;
5741 goto out;
Willy Tarreau798a39c2010-11-24 15:04:29 +01005742 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005743 else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005744 Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02005745 err_code |= ERR_ALERT | ERR_FATAL;
5746 goto out;
5747 }
Bhaskar98634f02013-10-29 23:30:51 -04005748
5749 /* set the hash function to use */
5750 if (!*args[2]) {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005751 /* the default algo is sdbm */
Bhaskar98634f02013-10-29 23:30:51 -04005752 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005753
5754 /* if consistent with no argument, then avalanche modifier is also applied */
5755 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS)
5756 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
Bhaskar98634f02013-10-29 23:30:51 -04005757 } else {
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005758 /* set the hash function */
5759 if (!strcmp(args[2], "sdbm")) {
5760 curproxy->lbprm.algo |= BE_LB_HFCN_SDBM;
5761 }
5762 else if (!strcmp(args[2], "djb2")) {
5763 curproxy->lbprm.algo |= BE_LB_HFCN_DJB2;
Willy Tarreau324f07f2015-01-20 19:44:50 +01005764 }
5765 else if (!strcmp(args[2], "wt6")) {
Willy Tarreaua0f42712013-11-14 14:30:35 +01005766 curproxy->lbprm.algo |= BE_LB_HFCN_WT6;
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005767 }
Willy Tarreau324f07f2015-01-20 19:44:50 +01005768 else if (!strcmp(args[2], "crc32")) {
5769 curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
5770 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05005771 else {
Willy Tarreau324f07f2015-01-20 19:44:50 +01005772 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 -05005773 err_code |= ERR_ALERT | ERR_FATAL;
5774 goto out;
5775 }
5776
5777 /* set the hash modifier */
5778 if (!strcmp(args[3], "avalanche")) {
5779 curproxy->lbprm.algo |= BE_LB_HMOD_AVAL;
5780 }
5781 else if (*args[3]) {
5782 Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]);
5783 err_code |= ERR_ALERT | ERR_FATAL;
5784 goto out;
5785 }
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01005786 }
William Lallemanda73203e2012-03-12 12:48:57 +01005787 }
Andrew Rodlandb1f48e32016-10-25 12:49:05 -04005788 else if (strcmp(args[0], "hash-balance-factor") == 0) {
5789 if (*(args[1]) == 0) {
5790 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
5791 err_code |= ERR_ALERT | ERR_FATAL;
5792 goto out;
5793 }
5794 curproxy->lbprm.chash.balance_factor = atol(args[1]);
5795 if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) {
5796 Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
5797 err_code |= ERR_ALERT | ERR_FATAL;
5798 goto out;
5799 }
5800 }
William Lallemanda73203e2012-03-12 12:48:57 +01005801 else if (strcmp(args[0], "unique-id-format") == 0) {
5802 if (!*(args[1])) {
5803 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5804 err_code |= ERR_ALERT | ERR_FATAL;
5805 goto out;
5806 }
William Lallemand3203ff42012-11-11 17:30:56 +01005807 if (*(args[2])) {
5808 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5809 err_code |= ERR_ALERT | ERR_FATAL;
5810 goto out;
5811 }
Willy Tarreau62a61232013-04-12 18:13:46 +02005812 free(curproxy->conf.uniqueid_format_string);
5813 curproxy->conf.uniqueid_format_string = strdup(args[1]);
Willy Tarreaua4312fa2013-04-02 16:34:32 +02005814
Willy Tarreau62a61232013-04-12 18:13:46 +02005815 free(curproxy->conf.uif_file);
5816 curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
5817 curproxy->conf.uif_line = curproxy->conf.args.line;
William Lallemand723b73a2012-02-08 16:37:49 +01005818 }
William Lallemanda73203e2012-03-12 12:48:57 +01005819
5820 else if (strcmp(args[0], "unique-id-header") == 0) {
5821 if (!*(args[1])) {
5822 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5823 err_code |= ERR_ALERT | ERR_FATAL;
5824 goto out;
5825 }
5826 free(curproxy->header_unique_id);
5827 curproxy->header_unique_id = strdup(args[1]);
5828 }
5829
William Lallemand723b73a2012-02-08 16:37:49 +01005830 else if (strcmp(args[0], "log-format") == 0) {
5831 if (!*(args[1])) {
5832 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5833 err_code |= ERR_ALERT | ERR_FATAL;
5834 goto out;
5835 }
William Lallemand3203ff42012-11-11 17:30:56 +01005836 if (*(args[2])) {
5837 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5838 err_code |= ERR_ALERT | ERR_FATAL;
5839 goto out;
5840 }
Willy Tarreau196729e2012-05-31 19:30:26 +02005841
Willy Tarreau62a61232013-04-12 18:13:46 +02005842 if (curproxy->conf.logformat_string != default_http_log_format &&
5843 curproxy->conf.logformat_string != default_tcp_log_format &&
5844 curproxy->conf.logformat_string != clf_http_log_format)
5845 free(curproxy->conf.logformat_string);
5846 curproxy->conf.logformat_string = strdup(args[1]);
5847
5848 free(curproxy->conf.lfs_file);
5849 curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
5850 curproxy->conf.lfs_line = curproxy->conf.args.line;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02005851
5852 /* get a chance to improve log-format error reporting by
5853 * reporting the correct line-number when possible.
5854 */
5855 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
5856 Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n",
5857 file, linenum, curproxy->id);
5858 err_code |= ERR_WARN;
5859 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005860 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02005861 else if (!strcmp(args[0], "log-format-sd")) {
5862 if (!*(args[1])) {
5863 Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
5864 err_code |= ERR_ALERT | ERR_FATAL;
5865 goto out;
5866 }
5867 if (*(args[2])) {
5868 Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]);
5869 err_code |= ERR_ALERT | ERR_FATAL;
5870 goto out;
5871 }
5872
5873 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
5874 free(curproxy->conf.logformat_sd_string);
5875 curproxy->conf.logformat_sd_string = strdup(args[1]);
5876
5877 free(curproxy->conf.lfsd_file);
5878 curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
5879 curproxy->conf.lfsd_line = curproxy->conf.args.line;
5880
5881 /* get a chance to improve log-format-sd error reporting by
5882 * reporting the correct line-number when possible.
5883 */
5884 if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) {
5885 Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n",
5886 file, linenum, curproxy->id);
5887 err_code |= ERR_WARN;
5888 }
5889 }
Willy Tarreau094af4e2015-01-07 15:03:42 +01005890 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
5891 if (*(args[1]) == 0) {
5892 Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
5893 err_code |= ERR_ALERT | ERR_FATAL;
5894 goto out;
5895 }
Dragan Dosen43885c72015-10-01 13:18:13 +02005896 chunk_destroy(&curproxy->log_tag);
5897 chunk_initstr(&curproxy->log_tag, strdup(args[1]));
Willy Tarreau094af4e2015-01-07 15:03:42 +01005898 }
William Lallemand0f99e342011-10-12 17:50:54 +02005899 else if (!strcmp(args[0], "log") && kwm == KWM_NO) {
5900 /* delete previous herited or defined syslog servers */
5901 struct logsrv *back;
5902
5903 if (*(args[1]) != 0) {
5904 Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]);
5905 err_code |= ERR_ALERT | ERR_FATAL;
5906 goto out;
5907 }
5908
William Lallemand723b73a2012-02-08 16:37:49 +01005909 list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) {
5910 LIST_DEL(&tmplogsrv->list);
5911 free(tmplogsrv);
William Lallemand0f99e342011-10-12 17:50:54 +02005912 }
5913 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005914 else if (!strcmp(args[0], "log")) { /* syslog server address */
William Lallemand0f99e342011-10-12 17:50:54 +02005915 struct logsrv *logsrv;
5916
Willy Tarreaubaaee002006-06-26 02:48:02 +02005917 if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
William Lallemand0f99e342011-10-12 17:50:54 +02005918 /* copy global.logrsvs linked list to the end of curproxy->logsrvs */
William Lallemand723b73a2012-02-08 16:37:49 +01005919 list_for_each_entry(tmplogsrv, &global.logsrvs, list) {
Vincent Bernat02779b62016-04-03 13:48:43 +02005920 struct logsrv *node = malloc(sizeof(*node));
William Lallemand723b73a2012-02-08 16:37:49 +01005921 memcpy(node, tmplogsrv, sizeof(struct logsrv));
William Lallemand0f99e342011-10-12 17:50:54 +02005922 LIST_INIT(&node->list);
5923 LIST_ADDQ(&curproxy->logsrvs, &node->list);
5924 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02005925 }
5926 else if (*(args[1]) && *(args[2])) {
Willy Tarreau9b435bc2013-03-06 15:02:49 +01005927 struct sockaddr_storage *sk;
5928 int port1, port2;
Willy Tarreau18324f52014-06-27 18:10:07 +02005929 int arg = 0;
5930 int len = 0;
William Lallemand0f99e342011-10-12 17:50:54 +02005931
Vincent Bernat02779b62016-04-03 13:48:43 +02005932 logsrv = calloc(1, sizeof(*logsrv));
Willy Tarreaubaaee002006-06-26 02:48:02 +02005933
Willy Tarreau18324f52014-06-27 18:10:07 +02005934 /* just after the address, a length may be specified */
5935 if (strcmp(args[arg+2], "len") == 0) {
5936 len = atoi(args[arg+3]);
5937 if (len < 80 || len > 65535) {
5938 Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n",
5939 file, linenum, args[arg+3]);
5940 err_code |= ERR_ALERT | ERR_FATAL;
5941 goto out;
5942 }
5943 logsrv->maxlen = len;
5944
5945 /* skip these two args */
5946 arg += 2;
5947 }
5948 else
5949 logsrv->maxlen = MAX_SYSLOG_LEN;
5950
5951 if (logsrv->maxlen > global.max_syslog_len) {
5952 global.max_syslog_len = logsrv->maxlen;
Hubert Verstraete831962e2016-06-28 22:44:26 +02005953 logheader = my_realloc2(logheader, global.max_syslog_len + 1);
5954 logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
5955 logline = my_realloc2(logline, global.max_syslog_len + 1);
5956 logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
Willy Tarreau18324f52014-06-27 18:10:07 +02005957 }
5958
Dragan Dosen1322d092015-09-22 16:05:32 +02005959 /* after the length, a format may be specified */
5960 if (strcmp(args[arg+2], "format") == 0) {
5961 logsrv->format = get_log_format(args[arg+3]);
5962 if (logsrv->format < 0) {
5963 Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]);
5964 err_code |= ERR_ALERT | ERR_FATAL;
5965 goto out;
5966 }
5967
5968 /* skip these two args */
5969 arg += 2;
5970 }
5971
William Lallemanddf1425a2015-04-28 20:17:49 +02005972 if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code))
5973 goto out;
5974
Willy Tarreau18324f52014-06-27 18:10:07 +02005975 logsrv->facility = get_log_facility(args[arg+2]);
William Lallemand0f99e342011-10-12 17:50:54 +02005976 if (logsrv->facility < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02005977 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]);
William Lallemand0f99e342011-10-12 17:50:54 +02005978 err_code |= ERR_ALERT | ERR_FATAL;
5979 goto out;
5980
Willy Tarreaubaaee002006-06-26 02:48:02 +02005981 }
5982
William Lallemand0f99e342011-10-12 17:50:54 +02005983 logsrv->level = 7; /* max syslog level = debug */
Willy Tarreau18324f52014-06-27 18:10:07 +02005984 if (*(args[arg+3])) {
5985 logsrv->level = get_log_level(args[arg+3]);
William Lallemand0f99e342011-10-12 17:50:54 +02005986 if (logsrv->level < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02005987 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]);
William Lallemand0f99e342011-10-12 17:50:54 +02005988 err_code |= ERR_ALERT | ERR_FATAL;
5989 goto out;
5990
Willy Tarreaubaaee002006-06-26 02:48:02 +02005991 }
5992 }
5993
William Lallemand0f99e342011-10-12 17:50:54 +02005994 logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */
Willy Tarreau18324f52014-06-27 18:10:07 +02005995 if (*(args[arg+4])) {
5996 logsrv->minlvl = get_log_level(args[arg+4]);
Willy Tarreauf7f057b2013-01-24 00:31:24 +01005997 if (logsrv->minlvl < 0) {
Willy Tarreau18324f52014-06-27 18:10:07 +02005998 Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]);
William Lallemand0f99e342011-10-12 17:50:54 +02005999 err_code |= ERR_ALERT | ERR_FATAL;
6000 goto out;
6001
Willy Tarreauf7edefa2009-05-10 17:20:05 +02006002 }
6003 }
6004
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006005 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006006 if (!sk) {
Willy Tarreau902636f2013-03-10 19:44:48 +01006007 Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006008 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006009 goto out;
6010 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006011
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006012 logsrv->addr = *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006013
Willy Tarreau9b435bc2013-03-06 15:02:49 +01006014 if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006015 if (port1 != port2) {
6016 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6017 file, linenum, args[0], args[1]);
6018 err_code |= ERR_ALERT | ERR_FATAL;
6019 goto out;
6020 }
6021
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006022 if (!port1)
William Lallemand0f99e342011-10-12 17:50:54 +02006023 set_host_port(&logsrv->addr, SYSLOG_PORT);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006024 }
William Lallemand0f99e342011-10-12 17:50:54 +02006025
6026 LIST_ADDQ(&curproxy->logsrvs, &logsrv->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006027 }
6028 else {
6029 Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n",
6030 file, linenum);
Willy Tarreau93893792009-07-23 13:19:11 +02006031 err_code |= ERR_ALERT | ERR_FATAL;
6032 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006033 }
6034 }
6035 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006036 int cur_arg;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006037 int port1, port2;
David du Colombier6f5ccb12011-03-10 22:26:24 +01006038 struct sockaddr_storage *sk;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006039 struct protocol *proto;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006040
Willy Tarreau977b8e42006-12-29 14:19:17 +01006041 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006042 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006043
Willy Tarreaubaaee002006-06-26 02:48:02 +02006044 if (!*args[1]) {
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006045 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n",
6046 file, linenum, "source", "usesrc", "interface");
Willy Tarreau93893792009-07-23 13:19:11 +02006047 err_code |= ERR_ALERT | ERR_FATAL;
6048 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006049 }
Willy Tarreau368480c2009-03-01 08:27:21 +01006050
6051 /* we must first clear any optional default setting */
Willy Tarreauef9a3602012-12-08 22:29:20 +01006052 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6053 free(curproxy->conn_src.iface_name);
6054 curproxy->conn_src.iface_name = NULL;
6055 curproxy->conn_src.iface_len = 0;
Willy Tarreau368480c2009-03-01 08:27:21 +01006056
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006057 sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006058 if (!sk) {
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006059 Alert("parsing [%s:%d] : '%s %s' : %s\n",
Willy Tarreau902636f2013-03-10 19:44:48 +01006060 file, linenum, args[0], args[1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006061 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006062 goto out;
6063 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006064
6065 proto = protocol_by_family(sk->ss_family);
6066 if (!proto || !proto->connect) {
6067 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006068 file, linenum, args[0], args[1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006069 err_code |= ERR_ALERT | ERR_FATAL;
6070 goto out;
6071 }
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006072
6073 if (port1 != port2) {
6074 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6075 file, linenum, args[0], args[1]);
6076 err_code |= ERR_ALERT | ERR_FATAL;
6077 goto out;
6078 }
6079
Willy Tarreauef9a3602012-12-08 22:29:20 +01006080 curproxy->conn_src.source_addr = *sk;
6081 curproxy->conn_src.opts |= CO_SRC_BIND;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006082
6083 cur_arg = 2;
6084 while (*(args[cur_arg])) {
6085 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau29fbe512015-08-20 19:35:14 +02006086#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006087 if (!*args[cur_arg + 1]) {
6088 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
6089 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006090 err_code |= ERR_ALERT | ERR_FATAL;
6091 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006092 }
6093
6094 if (!strcmp(args[cur_arg + 1], "client")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006095 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6096 curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006097 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
Willy Tarreauef9a3602012-12-08 22:29:20 +01006098 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6099 curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP;
Willy Tarreaubce70882009-09-07 11:51:47 +02006100 } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) {
6101 char *name, *end;
6102
6103 name = args[cur_arg+1] + 7;
6104 while (isspace(*name))
6105 name++;
6106
6107 end = name;
6108 while (*end && !isspace(*end) && *end != ',' && *end != ')')
6109 end++;
6110
Willy Tarreauef9a3602012-12-08 22:29:20 +01006111 curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
6112 curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
6113 curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
6114 curproxy->conn_src.bind_hdr_len = end - name;
6115 memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
6116 curproxy->conn_src.bind_hdr_name[end-name] = '\0';
6117 curproxy->conn_src.bind_hdr_occ = -1;
Willy Tarreaubce70882009-09-07 11:51:47 +02006118
6119 /* now look for an occurrence number */
6120 while (isspace(*end))
6121 end++;
6122 if (*end == ',') {
6123 end++;
6124 name = end;
6125 if (*end == '-')
6126 end++;
Willy Tarreau83d84cf2012-11-22 01:04:31 +01006127 while (isdigit((int)*end))
Willy Tarreaubce70882009-09-07 11:51:47 +02006128 end++;
Willy Tarreauef9a3602012-12-08 22:29:20 +01006129 curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name);
Willy Tarreaubce70882009-09-07 11:51:47 +02006130 }
6131
Willy Tarreauef9a3602012-12-08 22:29:20 +01006132 if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) {
Willy Tarreaubce70882009-09-07 11:51:47 +02006133 Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative"
6134 " occurrences values smaller than %d.\n",
6135 file, linenum, MAX_HDR_HISTORY);
6136 err_code |= ERR_ALERT | ERR_FATAL;
6137 goto out;
6138 }
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006139 } else {
Willy Tarreau902636f2013-03-10 19:44:48 +01006140 struct sockaddr_storage *sk;
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006141
Willy Tarreau48ef4c92017-01-06 18:32:38 +01006142 sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006143 if (!sk) {
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006144 Alert("parsing [%s:%d] : '%s %s' : %s\n",
Willy Tarreau902636f2013-03-10 19:44:48 +01006145 file, linenum, args[cur_arg], args[cur_arg+1], errmsg);
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006146 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006147 goto out;
6148 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006149
6150 proto = protocol_by_family(sk->ss_family);
6151 if (!proto || !proto->connect) {
6152 Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
6153 file, linenum, args[cur_arg], args[cur_arg+1]);
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006154 err_code |= ERR_ALERT | ERR_FATAL;
6155 goto out;
6156 }
Willy Tarreau2de5dae2013-03-10 18:51:54 +01006157
Willy Tarreau6d03cc32013-02-20 17:26:02 +01006158 if (port1 != port2) {
6159 Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n",
6160 file, linenum, args[cur_arg], args[cur_arg + 1]);
Willy Tarreaud5191e72010-02-09 20:50:45 +01006161 err_code |= ERR_ALERT | ERR_FATAL;
6162 goto out;
6163 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006164 curproxy->conn_src.tproxy_addr = *sk;
6165 curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006166 }
6167 global.last_checks |= LSTCHK_NETADM;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006168#else /* no TPROXY support */
6169 Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n",
Willy Tarreau77074d52006-11-12 23:57:19 +01006170 file, linenum, "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006171 err_code |= ERR_ALERT | ERR_FATAL;
6172 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006173#endif
6174 cur_arg += 2;
6175 continue;
Willy Tarreau77074d52006-11-12 23:57:19 +01006176 }
6177
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006178 if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */
6179#ifdef SO_BINDTODEVICE
6180 if (!*args[cur_arg + 1]) {
6181 Alert("parsing [%s:%d] : '%s' : missing interface name.\n",
6182 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006183 err_code |= ERR_ALERT | ERR_FATAL;
6184 goto out;
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006185 }
Willy Tarreauef9a3602012-12-08 22:29:20 +01006186 free(curproxy->conn_src.iface_name);
6187 curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
6188 curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name);
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006189 global.last_checks |= LSTCHK_NETADM;
6190#else
6191 Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n",
6192 file, linenum, args[0], args[cur_arg]);
Willy Tarreau93893792009-07-23 13:19:11 +02006193 err_code |= ERR_ALERT | ERR_FATAL;
6194 goto out;
Willy Tarreau5b6995c2008-01-13 16:31:17 +01006195#endif
Willy Tarreaud53f96b2009-02-04 18:46:54 +01006196 cur_arg += 2;
6197 continue;
6198 }
6199 Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n",
Willy Tarreau3631d412012-09-25 16:31:00 +02006200 file, linenum, args[0], "interface", "usesrc");
Willy Tarreau93893792009-07-23 13:19:11 +02006201 err_code |= ERR_ALERT | ERR_FATAL;
6202 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006203 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006204 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006205 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
6206 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
6207 file, linenum, "usesrc", "source");
Willy Tarreau93893792009-07-23 13:19:11 +02006208 err_code |= ERR_ALERT | ERR_FATAL;
6209 goto out;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01006210 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006211 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006212 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006213 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6214 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006215 err_code |= ERR_ALERT | ERR_FATAL;
6216 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006217 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006218
6219 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006220 SMP_OPT_DIR_REQ, ACT_REPLACE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006221 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006222 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006223 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006224 }
6225 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006226 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006227 SMP_OPT_DIR_REQ, ACT_REMOVE, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006228 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006229 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006230 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006231 }
6232 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006233 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006234 SMP_OPT_DIR_REQ, ACT_DENY, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006235 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006236 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006237 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006238 }
6239 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006240 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006241 SMP_OPT_DIR_REQ, ACT_PASS, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006242 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006243 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006244 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006245 }
6246 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006247 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006248 SMP_OPT_DIR_REQ, ACT_ALLOW, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006249 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006250 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006251 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006252 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006253 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006254 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006255 SMP_OPT_DIR_REQ, ACT_TARPIT, 0,
Willy Tarreau5321c422010-01-28 20:35:13 +01006256 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006257 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006258 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006259 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006260 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006261 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006262 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6263 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006264 err_code |= ERR_ALERT | ERR_FATAL;
6265 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006266 }
Willy Tarreauade5ec42010-01-28 19:33:49 +01006267
6268 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006269 SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006270 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006271 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006272 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006273 }
6274 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006275 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006276 SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006277 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006278 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006279 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006280 }
6281 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006282 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006283 SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006284 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006285 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006286 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006287 }
6288 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006289 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006290 SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006291 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006292 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006293 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006294 }
6295 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006296 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006297 SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006298 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006299 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006300 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006301 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02006302 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006303 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006304 SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE,
Willy Tarreau5321c422010-01-28 20:35:13 +01006305 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006306 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006307 goto out;
Willy Tarreaub8750a82006-09-03 09:56:00 +02006308 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006309 else if (!strcmp(args[0], "reqadd")) { /* add request header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006310 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006311
Willy Tarreaubaaee002006-06-26 02:48:02 +02006312 if (curproxy == &defproxy) {
6313 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006314 err_code |= ERR_ALERT | ERR_FATAL;
6315 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006316 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006317 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006318 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006319
Willy Tarreaubaaee002006-06-26 02:48:02 +02006320 if (*(args[1]) == 0) {
6321 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006322 err_code |= ERR_ALERT | ERR_FATAL;
6323 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006324 }
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006325
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006326 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02006327 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) {
6328 Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6329 file, linenum, args[0], errmsg);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006330 err_code |= ERR_ALERT | ERR_FATAL;
6331 goto out;
6332 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006333 err_code |= warnif_cond_conflicts(cond,
6334 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
6335 file, linenum);
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006336 }
6337 else if (*args[2]) {
6338 Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6339 file, linenum, args[0], args[2]);
6340 err_code |= ERR_ALERT | ERR_FATAL;
6341 goto out;
6342 }
6343
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006344 wl = calloc(1, sizeof(*wl));
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006345 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006346 wl->s = strdup(args[1]);
6347 LIST_ADDQ(&curproxy->req_add, &wl->list);
Willy Tarreau61d18892009-03-31 10:49:21 +02006348 warnif_misplaced_reqadd(curproxy, file, linenum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006349 }
6350 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006351 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006352 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6353 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006354 err_code |= ERR_ALERT | ERR_FATAL;
6355 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006356 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01006357
Willy Tarreauade5ec42010-01-28 19:33:49 +01006358 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006359 SMP_OPT_DIR_RES, ACT_REPLACE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006360 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006361 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006362 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006363 }
6364 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006365 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006366 SMP_OPT_DIR_RES, ACT_REMOVE, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006367 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006368 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006369 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006370 }
6371 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006372 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006373 SMP_OPT_DIR_RES, ACT_DENY, 0,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006374 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006375 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006376 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006377 }
6378 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006379 if (*(args[2]) == 0) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006380 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
6381 file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006382 err_code |= ERR_ALERT | ERR_FATAL;
6383 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006384 }
6385
Willy Tarreauade5ec42010-01-28 19:33:49 +01006386 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006387 SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006388 args[0], args[1], args[2], (const char **)args+3);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006389 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006390 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006391 }
6392 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006393 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006394 SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006395 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006396 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006397 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006398 }
6399 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
Willy Tarreauade5ec42010-01-28 19:33:49 +01006400 err_code |= create_cond_regex_rule(file, linenum, curproxy,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +02006401 SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE,
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006402 args[0], args[1], NULL, (const char **)args+2);
Willy Tarreauade5ec42010-01-28 19:33:49 +01006403 if (err_code & ERR_FATAL)
Willy Tarreau93893792009-07-23 13:19:11 +02006404 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006405 }
6406 else if (!strcmp(args[0], "rspadd")) { /* add response header */
Willy Tarreauf4f04122010-01-28 18:10:50 +01006407 struct cond_wordlist *wl;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006408
Willy Tarreaubaaee002006-06-26 02:48:02 +02006409 if (curproxy == &defproxy) {
6410 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006411 err_code |= ERR_ALERT | ERR_FATAL;
6412 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006413 }
Christopher Faulet898566e2016-10-26 11:06:28 +02006414 else if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006415 err_code |= ERR_WARN;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006416
Willy Tarreaubaaee002006-06-26 02:48:02 +02006417 if (*(args[1]) == 0) {
6418 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006419 err_code |= ERR_ALERT | ERR_FATAL;
6420 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006421 }
6422
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006423 if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) {
Willy Tarreaub7451bb2012-04-27 12:38:15 +02006424 if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) {
6425 Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n",
6426 file, linenum, args[0], errmsg);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006427 err_code |= ERR_ALERT | ERR_FATAL;
6428 goto out;
6429 }
Willy Tarreaua91d0a52013-03-25 08:12:18 +01006430 err_code |= warnif_cond_conflicts(cond,
6431 (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
6432 file, linenum);
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006433 }
6434 else if (*args[2]) {
6435 Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n",
6436 file, linenum, args[0], args[2]);
6437 err_code |= ERR_ALERT | ERR_FATAL;
6438 goto out;
6439 }
6440
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006441 wl = calloc(1, sizeof(*wl));
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006442 wl->cond = cond;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +01006443 wl->s = strdup(args[1]);
6444 LIST_ADDQ(&curproxy->rsp_add, &wl->list);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006445 }
6446 else if (!strcmp(args[0], "errorloc") ||
6447 !strcmp(args[0], "errorloc302") ||
6448 !strcmp(args[0], "errorloc303")) { /* error location */
6449 int errnum, errlen;
6450 char *err;
6451
Willy Tarreau977b8e42006-12-29 14:19:17 +01006452 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006453 err_code |= ERR_WARN;
Willy Tarreau977b8e42006-12-29 14:19:17 +01006454
Willy Tarreaubaaee002006-06-26 02:48:02 +02006455 if (*(args[2]) == 0) {
Willy Tarreau1772ece2009-04-03 14:49:12 +02006456 Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006457 err_code |= ERR_ALERT | ERR_FATAL;
6458 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006459 }
6460
6461 errnum = atol(args[1]);
6462 if (!strcmp(args[0], "errorloc303")) {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006463 errlen = strlen(HTTP_303) + strlen(args[2]) + 5;
6464 err = malloc(errlen);
6465 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006466 } else {
Willy Tarreau348acfe2014-04-14 15:00:39 +02006467 errlen = strlen(HTTP_302) + strlen(args[2]) + 5;
6468 err = malloc(errlen);
6469 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006470 }
6471
Willy Tarreau0f772532006-12-23 20:51:41 +01006472 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6473 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006474 chunk_destroy(&curproxy->errmsg[rc]);
6475 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau0f772532006-12-23 20:51:41 +01006476 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006477 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006478 }
Willy Tarreau0f772532006-12-23 20:51:41 +01006479
6480 if (rc >= HTTP_ERR_SIZE) {
Willy Tarreaubb3c09a2015-09-27 15:13:30 +02006481 Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n",
6482 file, linenum, errnum, args[0]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006483 free(err);
6484 }
6485 }
Willy Tarreau3f49b302007-06-11 00:29:26 +02006486 else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
6487 int errnum, errlen, fd;
6488 char *err;
6489 struct stat stat;
6490
6491 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
Willy Tarreau93893792009-07-23 13:19:11 +02006492 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006493
6494 if (*(args[2]) == 0) {
Willy Tarreau1772ece2009-04-03 14:49:12 +02006495 Alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006496 err_code |= ERR_ALERT | ERR_FATAL;
6497 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006498 }
6499
6500 fd = open(args[2], O_RDONLY);
6501 if ((fd < 0) || (fstat(fd, &stat) < 0)) {
6502 Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n",
6503 file, linenum, args[2], args[1]);
6504 if (fd >= 0)
6505 close(fd);
Willy Tarreau93893792009-07-23 13:19:11 +02006506 err_code |= ERR_ALERT | ERR_FATAL;
6507 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006508 }
6509
Willy Tarreau27a674e2009-08-17 07:23:33 +02006510 if (stat.st_size <= global.tune.bufsize) {
Willy Tarreau3f49b302007-06-11 00:29:26 +02006511 errlen = stat.st_size;
6512 } else {
6513 Warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n",
Willy Tarreau27a674e2009-08-17 07:23:33 +02006514 file, linenum, args[2], global.tune.bufsize);
Willy Tarreau93893792009-07-23 13:19:11 +02006515 err_code |= ERR_WARN;
Willy Tarreau27a674e2009-08-17 07:23:33 +02006516 errlen = global.tune.bufsize;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006517 }
6518
6519 err = malloc(errlen); /* malloc() must succeed during parsing */
6520 errnum = read(fd, err, errlen);
6521 if (errnum != errlen) {
6522 Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n",
6523 file, linenum, args[2], args[1]);
6524 close(fd);
6525 free(err);
Willy Tarreau93893792009-07-23 13:19:11 +02006526 err_code |= ERR_ALERT | ERR_FATAL;
6527 goto out;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006528 }
6529 close(fd);
6530
6531 errnum = atol(args[1]);
6532 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
6533 if (http_err_codes[rc] == errnum) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006534 chunk_destroy(&curproxy->errmsg[rc]);
6535 chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
Willy Tarreau3f49b302007-06-11 00:29:26 +02006536 break;
6537 }
6538 }
6539
6540 if (rc >= HTTP_ERR_SIZE) {
Willy Tarreaubb3c09a2015-09-27 15:13:30 +02006541 Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n",
6542 file, linenum, errnum, args[0]);
Willy Tarreau93893792009-07-23 13:19:11 +02006543 err_code |= ERR_WARN;
Willy Tarreau3f49b302007-06-11 00:29:26 +02006544 free(err);
6545 }
6546 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006547 else {
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006548 struct cfg_kw_list *kwl;
6549 int index;
6550
6551 list_for_each_entry(kwl, &cfg_keywords.list, list) {
6552 for (index = 0; kwl->kw[index].kw != NULL; index++) {
6553 if (kwl->kw[index].section != CFG_LISTEN)
6554 continue;
6555 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
6556 /* prepare error message just in case */
Willy Tarreau28a47d62012-09-18 20:02:48 +02006557 rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
Willy Tarreau39f23b62008-07-09 20:22:56 +02006558 if (rc < 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02006559 Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006560 err_code |= ERR_ALERT | ERR_FATAL;
6561 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006562 }
Willy Tarreau39f23b62008-07-09 20:22:56 +02006563 else if (rc > 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +02006564 Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006565 err_code |= ERR_WARN;
6566 goto out;
Willy Tarreau39f23b62008-07-09 20:22:56 +02006567 }
Willy Tarreau93893792009-07-23 13:19:11 +02006568 goto out;
Willy Tarreau5b2c3362008-07-09 19:39:06 +02006569 }
6570 }
6571 }
William Lallemand82fe75c2012-10-23 10:25:10 +02006572
Willy Tarreau6daf3432008-01-22 16:44:08 +01006573 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
Willy Tarreau93893792009-07-23 13:19:11 +02006574 err_code |= ERR_ALERT | ERR_FATAL;
6575 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006576 }
Willy Tarreau93893792009-07-23 13:19:11 +02006577 out:
Willy Tarreauf4068b62012-05-08 17:37:49 +02006578 free(errmsg);
Willy Tarreau93893792009-07-23 13:19:11 +02006579 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006580}
6581
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006582int
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01006583cfg_parse_netns(const char *file, int linenum, char **args, int kwm)
6584{
6585#ifdef CONFIG_HAP_NS
6586 const char *err;
6587 const char *item = args[0];
6588
6589 if (!strcmp(item, "namespace_list")) {
6590 return 0;
6591 }
6592 else if (!strcmp(item, "namespace")) {
6593 size_t idx = 1;
6594 const char *current;
6595 while (*(current = args[idx++])) {
6596 err = invalid_char(current);
6597 if (err) {
6598 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6599 file, linenum, *err, item, current);
6600 return ERR_ALERT | ERR_FATAL;
6601 }
6602
6603 if (netns_store_lookup(current, strlen(current))) {
6604 Alert("parsing [%s:%d]: Namespace '%s' is already added.\n",
6605 file, linenum, current);
6606 return ERR_ALERT | ERR_FATAL;
6607 }
6608 if (!netns_store_insert(current)) {
6609 Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n",
6610 file, linenum, current);
6611 return ERR_ALERT | ERR_FATAL;
6612 }
6613 }
6614 }
6615
6616 return 0;
6617#else
6618 Alert("parsing [%s:%d]: namespace support is not compiled in.",
6619 file, linenum);
6620 return ERR_ALERT | ERR_FATAL;
6621#endif
6622}
6623
6624int
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006625cfg_parse_users(const char *file, int linenum, char **args, int kwm)
6626{
6627
6628 int err_code = 0;
6629 const char *err;
6630
6631 if (!strcmp(args[0], "userlist")) { /* new userlist */
6632 struct userlist *newul;
6633
6634 if (!*args[1]) {
6635 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6636 file, linenum, args[0]);
6637 err_code |= ERR_ALERT | ERR_FATAL;
6638 goto out;
6639 }
William Lallemand6e62fb62015-04-28 16:55:23 +02006640 if (alertif_too_many_args(1, file, linenum, args, &err_code))
6641 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006642
6643 err = invalid_char(args[1]);
6644 if (err) {
6645 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6646 file, linenum, *err, args[0], args[1]);
6647 err_code |= ERR_ALERT | ERR_FATAL;
6648 goto out;
6649 }
6650
6651 for (newul = userlist; newul; newul = newul->next)
6652 if (!strcmp(newul->name, args[1])) {
6653 Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n",
6654 file, linenum, args[1]);
6655 err_code |= ERR_WARN;
6656 goto out;
6657 }
6658
Vincent Bernat02779b62016-04-03 13:48:43 +02006659 newul = calloc(1, sizeof(*newul));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006660 if (!newul) {
6661 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6662 err_code |= ERR_ALERT | ERR_ABORT;
6663 goto out;
6664 }
6665
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006666 newul->name = strdup(args[1]);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006667 if (!newul->name) {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006668 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6669 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier97880bb2016-04-08 10:35:26 +01006670 free(newul);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006671 goto out;
6672 }
6673
6674 newul->next = userlist;
6675 userlist = newul;
6676
6677 } else if (!strcmp(args[0], "group")) { /* new group */
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006678 int cur_arg;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006679 const char *err;
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006680 struct auth_groups *ag;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006681
6682 if (!*args[1]) {
6683 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6684 file, linenum, args[0]);
6685 err_code |= ERR_ALERT | ERR_FATAL;
6686 goto out;
6687 }
6688
6689 err = invalid_char(args[1]);
6690 if (err) {
6691 Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n",
6692 file, linenum, *err, args[0], args[1]);
6693 err_code |= ERR_ALERT | ERR_FATAL;
6694 goto out;
6695 }
6696
William Lallemand4ac9f542015-05-28 18:03:51 +02006697 if (!userlist)
6698 goto out;
6699
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006700 for (ag = userlist->groups; ag; ag = ag->next)
6701 if (!strcmp(ag->name, args[1])) {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006702 Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n",
6703 file, linenum, args[1], userlist->name);
6704 err_code |= ERR_ALERT;
6705 goto out;
6706 }
6707
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006708 ag = calloc(1, sizeof(*ag));
6709 if (!ag) {
6710 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6711 err_code |= ERR_ALERT | ERR_ABORT;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006712 goto out;
6713 }
6714
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006715 ag->name = strdup(args[1]);
David Carlier70d60452016-08-22 23:27:42 +01006716 if (!ag->name) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006717 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6718 err_code |= ERR_ALERT | ERR_ABORT;
David Carlier70d60452016-08-22 23:27:42 +01006719 free(ag);
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006720 goto out;
6721 }
6722
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006723 cur_arg = 2;
6724
6725 while (*args[cur_arg]) {
6726 if (!strcmp(args[cur_arg], "users")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006727 ag->groupusers = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006728 cur_arg += 2;
6729 continue;
6730 } else {
6731 Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n",
6732 file, linenum, args[0]);
6733 err_code |= ERR_ALERT | ERR_FATAL;
David Carlier70d60452016-08-22 23:27:42 +01006734 free(ag->groupusers);
6735 free(ag->name);
6736 free(ag);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006737 goto out;
6738 }
6739 }
6740
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006741 ag->next = userlist->groups;
6742 userlist->groups = ag;
6743
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006744 } else if (!strcmp(args[0], "user")) { /* new user */
6745 struct auth_users *newuser;
6746 int cur_arg;
6747
6748 if (!*args[1]) {
6749 Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n",
6750 file, linenum, args[0]);
6751 err_code |= ERR_ALERT | ERR_FATAL;
6752 goto out;
6753 }
William Lallemand4ac9f542015-05-28 18:03:51 +02006754 if (!userlist)
6755 goto out;
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006756
6757 for (newuser = userlist->users; newuser; newuser = newuser->next)
6758 if (!strcmp(newuser->user, args[1])) {
6759 Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n",
6760 file, linenum, args[1], userlist->name);
6761 err_code |= ERR_ALERT;
6762 goto out;
6763 }
6764
Vincent Bernat02779b62016-04-03 13:48:43 +02006765 newuser = calloc(1, sizeof(*newuser));
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006766 if (!newuser) {
6767 Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
6768 err_code |= ERR_ALERT | ERR_ABORT;
6769 goto out;
6770 }
6771
6772 newuser->user = strdup(args[1]);
6773
6774 newuser->next = userlist->users;
6775 userlist->users = newuser;
6776
6777 cur_arg = 2;
6778
6779 while (*args[cur_arg]) {
6780 if (!strcmp(args[cur_arg], "password")) {
Cyril Bonté1a0191d2014-08-29 20:20:02 +02006781#ifdef CONFIG_HAP_CRYPT
6782 if (!crypt("", args[cur_arg + 1])) {
6783 Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n",
6784 file, linenum, newuser->user);
6785 err_code |= ERR_ALERT | ERR_FATAL;
6786 goto out;
6787 }
6788#else
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006789 Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n",
6790 file, linenum);
6791 err_code |= ERR_ALERT;
6792#endif
6793 newuser->pass = strdup(args[cur_arg + 1]);
6794 cur_arg += 2;
6795 continue;
6796 } else if (!strcmp(args[cur_arg], "insecure-password")) {
6797 newuser->pass = strdup(args[cur_arg + 1]);
6798 newuser->flags |= AU_O_INSECURE;
6799 cur_arg += 2;
6800 continue;
6801 } else if (!strcmp(args[cur_arg], "groups")) {
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01006802 newuser->u.groups_names = strdup(args[cur_arg + 1]);
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01006803 cur_arg += 2;
6804 continue;
6805 } else {
6806 Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n",
6807 file, linenum, args[0]);
6808 err_code |= ERR_ALERT | ERR_FATAL;
6809 goto out;
6810 }
6811 }
6812 } else {
6813 Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users");
6814 err_code |= ERR_ALERT | ERR_FATAL;
6815 }
6816
6817out:
6818 return err_code;
6819}
Willy Tarreaubaaee002006-06-26 02:48:02 +02006820
Christopher Faulet79bdef32016-11-04 22:36:15 +01006821int
6822cfg_parse_scope(const char *file, int linenum, char *line)
6823{
6824 char *beg, *end, *scope = NULL;
6825 int err_code = 0;
6826 const char *err;
6827
6828 beg = line + 1;
6829 end = strchr(beg, ']');
6830
6831 /* Detect end of scope declaration */
6832 if (!end || end == beg) {
6833 Alert("parsing [%s:%d] : empty scope name is forbidden.\n",
6834 file, linenum);
6835 err_code |= ERR_ALERT | ERR_FATAL;
6836 goto out;
6837 }
6838
6839 /* Get scope name and check its validity */
6840 scope = my_strndup(beg, end-beg);
6841 err = invalid_char(scope);
6842 if (err) {
6843 Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n",
6844 file, linenum, *err);
6845 err_code |= ERR_ALERT | ERR_ABORT;
6846 goto out;
6847 }
6848
6849 /* Be sure to have a scope declaration alone on its line */
6850 line = end+1;
6851 while (isspace((unsigned char)*line))
6852 line++;
6853 if (*line && *line != '#' && *line != '\n' && *line != '\r') {
6854 Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n",
6855 file, linenum, *line);
6856 err_code |= ERR_ALERT | ERR_ABORT;
6857 goto out;
6858 }
6859
6860 /* We have a valid scope declaration, save it */
6861 free(cfg_scope);
6862 cfg_scope = scope;
6863 scope = NULL;
6864
6865 out:
6866 free(scope);
6867 return err_code;
6868}
6869
Willy Tarreaubaaee002006-06-26 02:48:02 +02006870/*
6871 * This function reads and parses the configuration file given in the argument.
Willy Tarreau058e9072009-07-20 09:30:05 +02006872 * Returns the error code, 0 if OK, or any combination of :
6873 * - ERR_ABORT: must abort ASAP
6874 * - ERR_FATAL: we can continue parsing but not start the service
6875 * - ERR_WARN: a warning has been emitted
6876 * - ERR_ALERT: an alert has been emitted
6877 * Only the two first ones can stop processing, the two others are just
6878 * indicators.
Willy Tarreaubaaee002006-06-26 02:48:02 +02006879 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02006880int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02006881{
William Lallemand64e84512015-05-12 14:25:37 +02006882 char *thisline;
6883 int linesize = LINESIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02006884 FILE *f;
6885 int linenum = 0;
Willy Tarreau058e9072009-07-20 09:30:05 +02006886 int err_code = 0;
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01006887 struct cfg_section *cs = NULL;
6888 struct cfg_section *ics;
William Lallemand64e84512015-05-12 14:25:37 +02006889 int readbytes = 0;
6890
6891 if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
William Lallemandb2f07452015-05-12 14:27:13 +02006892 Alert("parsing [%s] : out of memory.\n", file);
William Lallemand64e84512015-05-12 14:25:37 +02006893 return -1;
6894 }
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01006895
David Carlier97880bb2016-04-08 10:35:26 +01006896 if ((f=fopen(file,"r")) == NULL) {
6897 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02006898 return -1;
David Carlier97880bb2016-04-08 10:35:26 +01006899 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006900
William Lallemandb2f07452015-05-12 14:27:13 +02006901next_line:
William Lallemand64e84512015-05-12 14:25:37 +02006902 while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) {
Willy Tarreau3842f002009-06-14 11:39:52 +02006903 int arg, kwm = KWM_STD;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006904 char *end;
6905 char *args[MAX_LINE_ARGS + 1];
6906 char *line = thisline;
William Lallemandf9873ba2015-05-05 17:37:14 +02006907 int dquote = 0; /* double quote */
6908 int squote = 0; /* simple quote */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006909
Willy Tarreaubaaee002006-06-26 02:48:02 +02006910 linenum++;
6911
6912 end = line + strlen(line);
6913
William Lallemand64e84512015-05-12 14:25:37 +02006914 if (end-line == linesize-1 && *(end-1) != '\n') {
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006915 /* Check if we reached the limit and the last char is not \n.
6916 * Watch out for the last line without the terminating '\n'!
6917 */
William Lallemand64e84512015-05-12 14:25:37 +02006918 char *newline;
6919 int newlinesize = linesize * 2;
6920
6921 newline = realloc(thisline, sizeof(*thisline) * newlinesize);
6922 if (newline == NULL) {
6923 Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
6924 file, linenum);
6925 err_code |= ERR_ALERT | ERR_FATAL;
6926 continue;
6927 }
6928
6929 readbytes = linesize - 1;
6930 linesize = newlinesize;
6931 thisline = newline;
6932 continue;
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01006933 }
6934
William Lallemand64e84512015-05-12 14:25:37 +02006935 readbytes = 0;
6936
Willy Tarreaubaaee002006-06-26 02:48:02 +02006937 /* skip leading spaces */
Willy Tarreau8f8e6452007-06-17 21:51:38 +02006938 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02006939 line++;
William Lallemandf9873ba2015-05-05 17:37:14 +02006940
Christopher Faulet79bdef32016-11-04 22:36:15 +01006941
6942 if (*line == '[') {/* This is the begining if a scope */
6943 err_code |= cfg_parse_scope(file, linenum, line);
6944 goto next_line;
6945 }
6946
Willy Tarreaubaaee002006-06-26 02:48:02 +02006947 arg = 0;
6948 args[arg] = line;
6949
6950 while (*line && arg < MAX_LINE_ARGS) {
William Lallemandf9873ba2015-05-05 17:37:14 +02006951 if (*line == '"' && !squote) { /* double quote outside single quotes */
6952 if (dquote)
6953 dquote = 0;
6954 else
6955 dquote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02006956 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02006957 end--;
6958 }
6959 else if (*line == '\'' && !dquote) { /* single quote outside double quotes */
6960 if (squote)
6961 squote = 0;
6962 else
6963 squote = 1;
William Lallemand3f415602015-05-12 14:01:09 +02006964 memmove(line, line + 1, end - line);
William Lallemandf9873ba2015-05-05 17:37:14 +02006965 end--;
6966 }
6967 else if (*line == '\\' && !squote) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006968 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
6969 * C equivalent value. Other combinations left unchanged (eg: \1).
6970 */
Willy Tarreaubaaee002006-06-26 02:48:02 +02006971 int skip = 0;
6972 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
6973 *line = line[1];
6974 skip = 1;
6975 }
6976 else if (line[1] == 'r') {
6977 *line = '\r';
6978 skip = 1;
William Lallemandf9873ba2015-05-05 17:37:14 +02006979 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02006980 else if (line[1] == 'n') {
6981 *line = '\n';
6982 skip = 1;
6983 }
6984 else if (line[1] == 't') {
6985 *line = '\t';
6986 skip = 1;
6987 }
6988 else if (line[1] == 'x') {
Emeric Brunb982a3d2010-01-04 15:45:53 +01006989 if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02006990 unsigned char hex1, hex2;
6991 hex1 = toupper(line[2]) - '0';
6992 hex2 = toupper(line[3]) - '0';
6993 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
6994 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
6995 *line = (hex1<<4) + hex2;
6996 skip = 3;
6997 }
6998 else {
6999 Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007000 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007001 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007002 } else if (line[1] == '"') {
7003 *line = '"';
7004 skip = 1;
7005 } else if (line[1] == '\'') {
7006 *line = '\'';
7007 skip = 1;
William Lallemandb2f07452015-05-12 14:27:13 +02007008 } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */
7009 *line = '$';
7010 skip = 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007011 }
7012 if (skip) {
Cyril Bontédd1b01d2009-12-06 13:43:42 +01007013 memmove(line + 1, line + 1 + skip, end - (line + skip));
Willy Tarreaubaaee002006-06-26 02:48:02 +02007014 end -= skip;
7015 }
7016 line++;
7017 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007018 else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007019 /* end of string, end of loop */
7020 *line = 0;
7021 break;
7022 }
William Lallemandf9873ba2015-05-05 17:37:14 +02007023 else if (!squote && !dquote && isspace((unsigned char)*line)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007024 /* a non-escaped space is an argument separator */
Krzysztof Piotr Oledzkie6bbd742007-11-01 00:33:12 +01007025 *line++ = '\0';
Willy Tarreau8f8e6452007-06-17 21:51:38 +02007026 while (isspace((unsigned char)*line))
Willy Tarreaubaaee002006-06-26 02:48:02 +02007027 line++;
7028 args[++arg] = line;
7029 }
William Lallemandb2f07452015-05-12 14:27:13 +02007030 else if (dquote && *line == '$') {
7031 /* environment variables are evaluated inside double quotes */
7032 char *var_beg;
7033 char *var_end;
7034 char save_char;
7035 char *value;
7036 int val_len;
7037 int newlinesize;
7038 int braces = 0;
7039
7040 var_beg = line + 1;
7041 var_end = var_beg;
7042
7043 if (*var_beg == '{') {
7044 var_beg++;
7045 var_end++;
7046 braces = 1;
7047 }
7048
7049 if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') {
7050 Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg);
7051 err_code |= ERR_ALERT | ERR_FATAL;
7052 goto next_line; /* skip current line */
7053 }
7054
7055 while (isalnum((int)(unsigned char)*var_end) || *var_end == '_')
7056 var_end++;
7057
7058 save_char = *var_end;
7059 *var_end = '\0';
7060 value = getenv(var_beg);
7061 *var_end = save_char;
7062 val_len = value ? strlen(value) : 0;
7063
7064 if (braces) {
7065 if (*var_end == '}') {
7066 var_end++;
7067 braces = 0;
7068 } else {
7069 Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum);
7070 err_code |= ERR_ALERT | ERR_FATAL;
7071 goto next_line; /* skip current line */
7072 }
7073 }
7074
7075 newlinesize = (end - thisline) - (var_end - line) + val_len + 1;
7076
7077 /* if not enough space in thisline */
7078 if (newlinesize > linesize) {
7079 char *newline;
7080
7081 newline = realloc(thisline, newlinesize * sizeof(*thisline));
7082 if (newline == NULL) {
7083 Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum);
7084 err_code |= ERR_ALERT | ERR_FATAL;
7085 goto next_line; /* slip current line */
7086 }
7087 /* recompute pointers if realloc returns a new pointer */
7088 if (newline != thisline) {
7089 int i;
7090 int diff;
7091
7092 for (i = 0; i <= arg; i++) {
7093 diff = args[i] - thisline;
7094 args[i] = newline + diff;
7095 }
7096
7097 diff = var_end - thisline;
7098 var_end = newline + diff;
7099 diff = end - thisline;
7100 end = newline + diff;
7101 diff = line - thisline;
7102 line = newline + diff;
7103 thisline = newline;
7104 }
7105 linesize = newlinesize;
7106 }
7107
7108 /* insert value inside the line */
7109 memmove(line + val_len, var_end, end - var_end + 1);
7110 memcpy(line, value, val_len);
7111 end += val_len - (var_end - line);
7112 line += val_len;
7113 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007114 else {
7115 line++;
7116 }
7117 }
William Lallemandb2f07452015-05-12 14:27:13 +02007118
William Lallemandf9873ba2015-05-05 17:37:14 +02007119 if (dquote) {
7120 Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum);
7121 err_code |= ERR_ALERT | ERR_FATAL;
7122 }
7123
7124 if (squote) {
7125 Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum);
7126 err_code |= ERR_ALERT | ERR_FATAL;
7127 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007128
7129 /* empty line */
7130 if (!**args)
7131 continue;
7132
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007133 if (*line) {
7134 /* we had to stop due to too many args.
7135 * Let's terminate the string, print the offending part then cut the
7136 * last arg.
7137 */
7138 while (*line && *line != '#' && *line != '\n' && *line != '\r')
7139 line++;
7140 *line = '\0';
7141
Krzysztof Piotr Oledzki500b8f02009-12-15 22:34:51 +01007142 Alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n",
Willy Tarreau3ccf94e2009-12-17 21:12:16 +01007143 file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]);
Willy Tarreau7bb651e2009-11-09 21:16:53 +01007144 err_code |= ERR_ALERT | ERR_FATAL;
7145 args[arg] = line;
7146 }
7147
Willy Tarreau540abe42007-05-02 20:50:16 +02007148 /* zero out remaining args and ensure that at least one entry
7149 * is zeroed out.
7150 */
7151 while (++arg <= MAX_LINE_ARGS) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02007152 args[arg] = line;
7153 }
7154
Willy Tarreau3842f002009-06-14 11:39:52 +02007155 /* check for keyword modifiers "no" and "default" */
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007156 if (!strcmp(args[0], "no")) {
William Lallemand0f99e342011-10-12 17:50:54 +02007157 char *tmp;
7158
Willy Tarreau3842f002009-06-14 11:39:52 +02007159 kwm = KWM_NO;
William Lallemand0f99e342011-10-12 17:50:54 +02007160 tmp = args[0];
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007161 for (arg=0; *args[arg+1]; arg++)
7162 args[arg] = args[arg+1]; // shift args after inversion
William Lallemand0f99e342011-10-12 17:50:54 +02007163 *tmp = '\0'; // fix the next arg to \0
7164 args[arg] = tmp;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007165 }
Willy Tarreau3842f002009-06-14 11:39:52 +02007166 else if (!strcmp(args[0], "default")) {
7167 kwm = KWM_DEF;
7168 for (arg=0; *args[arg+1]; arg++)
7169 args[arg] = args[arg+1]; // shift args after inversion
7170 }
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007171
William Lallemand0f99e342011-10-12 17:50:54 +02007172 if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \
7173 strcmp(args[0], "log") != 0) {
7174 Alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum);
Willy Tarreau058e9072009-07-20 09:30:05 +02007175 err_code |= ERR_ALERT | ERR_FATAL;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01007176 }
7177
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007178 /* detect section start */
7179 list_for_each_entry(ics, &sections, list) {
7180 if (strcmp(args[0], ics->section_name) == 0) {
7181 cursection = ics->section_name;
7182 cs = ics;
7183 break;
7184 }
Emeric Brun32da3c42010-09-23 18:39:19 +02007185 }
7186
Willy Tarreaubaaee002006-06-26 02:48:02 +02007187 /* else it's a section keyword */
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01007188 if (cs)
7189 err_code |= cs->section_parser(file, linenum, args, kwm);
7190 else {
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01007191 Alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]);
Willy Tarreau058e9072009-07-20 09:30:05 +02007192 err_code |= ERR_ALERT | ERR_FATAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007193 }
Willy Tarreau058e9072009-07-20 09:30:05 +02007194
7195 if (err_code & ERR_ABORT)
7196 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007197 }
Christopher Faulet79bdef32016-11-04 22:36:15 +01007198 free(cfg_scope);
7199 cfg_scope = NULL;
Willy Tarreau6daf3432008-01-22 16:44:08 +01007200 cursection = NULL;
William Lallemand64e84512015-05-12 14:25:37 +02007201 free(thisline);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007202 fclose(f);
Willy Tarreau058e9072009-07-20 09:30:05 +02007203 return err_code;
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007204}
7205
Willy Tarreau64ab6072014-09-16 12:17:36 +02007206/* This function propagates processes from frontend <from> to backend <to> so
7207 * that it is always guaranteed that a backend pointed to by a frontend is
7208 * bound to all of its processes. After that, if the target is a "listen"
7209 * instance, the function recursively descends the target's own targets along
Willy Tarreau98d04852015-05-26 12:18:29 +02007210 * default_backend and use_backend rules. Since the bits are
Willy Tarreau64ab6072014-09-16 12:17:36 +02007211 * checked first to ensure that <to> is already bound to all processes of
7212 * <from>, there is no risk of looping and we ensure to follow the shortest
7213 * path to the destination.
7214 *
7215 * It is possible to set <to> to NULL for the first call so that the function
7216 * takes care of visiting the initial frontend in <from>.
7217 *
7218 * It is important to note that the function relies on the fact that all names
7219 * have already been resolved.
7220 */
7221void propagate_processes(struct proxy *from, struct proxy *to)
7222{
7223 struct switching_rule *rule;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007224
7225 if (to) {
7226 /* check whether we need to go down */
7227 if (from->bind_proc &&
7228 (from->bind_proc & to->bind_proc) == from->bind_proc)
7229 return;
7230
7231 if (!from->bind_proc && !to->bind_proc)
7232 return;
7233
7234 to->bind_proc = from->bind_proc ?
7235 (to->bind_proc | from->bind_proc) : 0;
7236
7237 /* now propagate down */
7238 from = to;
7239 }
7240
Willy Tarreau8a95d8c2014-12-18 13:56:26 +01007241 if (!(from->cap & PR_CAP_FE))
Willy Tarreau64ab6072014-09-16 12:17:36 +02007242 return;
7243
Willy Tarreauf6b70012014-12-18 14:00:43 +01007244 if (from->state == PR_STSTOPPED)
7245 return;
7246
Willy Tarreau64ab6072014-09-16 12:17:36 +02007247 /* default_backend */
7248 if (from->defbe.be)
7249 propagate_processes(from, from->defbe.be);
7250
7251 /* use_backend */
7252 list_for_each_entry(rule, &from->switching_rules, list) {
Cyril Bonté51639692014-10-02 19:56:25 +02007253 if (rule->dynamic)
7254 continue;
Willy Tarreau64ab6072014-09-16 12:17:36 +02007255 to = rule->be.backend;
7256 propagate_processes(from, to);
7257 }
Willy Tarreau64ab6072014-09-16 12:17:36 +02007258}
7259
Willy Tarreaubb925012009-07-23 13:36:36 +02007260/*
7261 * Returns the error code, 0 if OK, or any combination of :
7262 * - ERR_ABORT: must abort ASAP
7263 * - ERR_FATAL: we can continue parsing but not start the service
7264 * - ERR_WARN: a warning has been emitted
7265 * - ERR_ALERT: an alert has been emitted
7266 * Only the two first ones can stop processing, the two others are just
7267 * indicators.
7268 */
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007269int check_config_validity()
7270{
7271 int cfgerr = 0;
7272 struct proxy *curproxy = NULL;
7273 struct server *newsrv = NULL;
Willy Tarreaubb925012009-07-23 13:36:36 +02007274 int err_code = 0;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007275 unsigned int next_pxid = 1;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007276 struct bind_conf *bind_conf;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007277 char *err;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007278
Willy Tarreau2a65ff02012-09-13 17:54:29 +02007279 bind_conf = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007280 /*
7281 * Now, check for the integrity of all that we have collected.
7282 */
7283
7284 /* will be needed further to delay some tasks */
Willy Tarreaub0b37bc2008-06-23 14:00:57 +02007285 tv_update_date(0,1);
Willy Tarreaubaaee002006-06-26 02:48:02 +02007286
Willy Tarreau193b8c62012-11-22 00:17:38 +01007287 if (!global.tune.max_http_hdr)
7288 global.tune.max_http_hdr = MAX_HTTP_HDR;
7289
7290 if (!global.tune.cookie_len)
7291 global.tune.cookie_len = CAPTURE_LEN;
7292
7293 pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
7294
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01007295 /* Post initialisation of the users and groups lists. */
7296 err_code = userlist_postinit();
7297 if (err_code != ERR_NONE)
7298 goto out;
7299
Willy Tarreau55bc0f82009-03-15 14:51:53 +01007300 /* first, we will invert the proxy list order */
7301 curproxy = NULL;
7302 while (proxy) {
7303 struct proxy *next;
7304
7305 next = proxy->next;
7306 proxy->next = curproxy;
7307 curproxy = proxy;
7308 if (!next)
7309 break;
7310 proxy = next;
7311 }
7312
Willy Tarreau419ead82014-09-16 13:41:21 +02007313 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007314 struct switching_rule *rule;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007315 struct server_rule *srule;
Emeric Brunb982a3d2010-01-04 15:45:53 +01007316 struct sticking_rule *mrule;
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02007317 struct act_rule *trule;
7318 struct act_rule *hrqrule;
Dragan Dosen1322d092015-09-22 16:05:32 +02007319 struct logsrv *tmplogsrv;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007320 unsigned int next_id;
Willy Tarreau16a21472012-11-19 12:39:59 +01007321 int nbproc;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007322
Willy Tarreau050536d2012-10-04 08:47:34 +02007323 if (curproxy->uuid < 0) {
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007324 /* proxy ID not set, use automatic numbering with first
7325 * spare entry starting with next_pxid.
7326 */
7327 next_pxid = get_next_id(&used_proxy_id, next_pxid);
7328 curproxy->conf.id.key = curproxy->uuid = next_pxid;
7329 eb32_insert(&used_proxy_id, &curproxy->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02007330 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01007331 next_pxid++;
7332
Willy Tarreau55ea7572007-06-17 19:56:27 +02007333
Willy Tarreaubaaee002006-06-26 02:48:02 +02007334 if (curproxy->state == PR_STSTOPPED) {
Willy Tarreauda250db2008-10-12 12:07:48 +02007335 /* ensure we don't keep listeners uselessly bound */
7336 stop_proxy(curproxy);
Willy Tarreau02df7742015-05-01 19:59:56 +02007337 free((void *)curproxy->table.peers.name);
7338 curproxy->table.peers.p = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007339 continue;
7340 }
7341
Willy Tarreau102df612014-05-07 23:56:38 +02007342 /* Check multi-process mode compatibility for the current proxy */
7343
7344 if (curproxy->bind_proc) {
7345 /* an explicit bind-process was specified, let's check how many
7346 * processes remain.
7347 */
David Carliere6c39412015-07-02 07:00:17 +00007348 nbproc = my_popcountl(curproxy->bind_proc);
Willy Tarreau102df612014-05-07 23:56:38 +02007349
7350 curproxy->bind_proc &= nbits(global.nbproc);
7351 if (!curproxy->bind_proc && nbproc == 1) {
7352 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);
7353 curproxy->bind_proc = 1;
7354 }
7355 else if (!curproxy->bind_proc && nbproc > 1) {
7356 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);
7357 curproxy->bind_proc = 0;
7358 }
7359 }
7360
Willy Tarreau3d209582014-05-09 17:06:11 +02007361 /* check and reduce the bind-proc of each listener */
7362 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
7363 unsigned long mask;
7364
7365 if (!bind_conf->bind_proc)
7366 continue;
7367
7368 mask = nbits(global.nbproc);
7369 if (curproxy->bind_proc)
7370 mask &= curproxy->bind_proc;
7371 /* mask cannot be null here thanks to the previous checks */
7372
David Carliere6c39412015-07-02 07:00:17 +00007373 nbproc = my_popcountl(bind_conf->bind_proc);
Willy Tarreau3d209582014-05-09 17:06:11 +02007374 bind_conf->bind_proc &= mask;
7375
7376 if (!bind_conf->bind_proc && nbproc == 1) {
7377 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",
7378 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
7379 bind_conf->bind_proc = mask & ~(mask - 1);
7380 }
7381 else if (!bind_conf->bind_proc && nbproc > 1) {
7382 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",
7383 curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line);
7384 bind_conf->bind_proc = 0;
7385 }
7386 }
7387
Willy Tarreauff01a212009-03-15 13:46:16 +01007388 switch (curproxy->mode) {
7389 case PR_MODE_HEALTH:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007390 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007391 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007392 Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n",
7393 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007394 cfgerr++;
7395 }
7396
7397 if (curproxy->srv != NULL)
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007398 Warning("config : servers will be ignored for %s '%s'.\n",
7399 proxy_type_str(curproxy), curproxy->id);
Willy Tarreauff01a212009-03-15 13:46:16 +01007400 break;
7401
7402 case PR_MODE_TCP:
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007403 cfgerr += proxy_cfg_ensure_no_http(curproxy);
Willy Tarreauff01a212009-03-15 13:46:16 +01007404 break;
7405
7406 case PR_MODE_HTTP:
Willy Tarreau25320b22013-03-24 07:22:08 +01007407 curproxy->http_needed = 1;
Willy Tarreauff01a212009-03-15 13:46:16 +01007408 break;
7409 }
7410
Willy Tarreauf3934b82015-08-11 11:36:45 +02007411 if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) {
7412 Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n",
7413 proxy_type_str(curproxy), curproxy->id);
7414 err_code |= ERR_WARN;
7415 }
7416
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007417 if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
Willy Tarreauf3e49f92009-10-03 12:21:20 +02007418 if (curproxy->lbprm.algo & BE_LB_KIND) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007419 if (curproxy->options & PR_O_TRANSP) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007420 Alert("config : %s '%s' cannot use both transparent and balance mode.\n",
7421 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007422 cfgerr++;
7423 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007424#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007425 else if (curproxy->srv == NULL) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007426 Alert("config : %s '%s' needs at least 1 server in balance mode.\n",
7427 proxy_type_str(curproxy), curproxy->id);
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007428 cfgerr++;
7429 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007430#endif
Willy Tarreau1620ec32011-08-06 17:05:02 +02007431 else if (curproxy->options & PR_O_DISPATCH) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02007432 Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n",
7433 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02007434 err_code |= ERR_WARN;
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007435 }
7436 }
Willy Tarreau1620ec32011-08-06 17:05:02 +02007437 else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) {
Willy Tarreau3cd9af22009-03-15 14:06:41 +01007438 /* If no LB algo is set in a backend, and we're not in
7439 * transparent mode, dispatch mode nor proxy mode, we
7440 * want to use balance roundrobin by default.
7441 */
7442 curproxy->lbprm.algo &= ~BE_LB_ALGO;
7443 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaubaaee002006-06-26 02:48:02 +02007444 }
7445 }
Willy Tarreau193cf932007-09-17 10:17:23 +02007446
Willy Tarreau1620ec32011-08-06 17:05:02 +02007447 if (curproxy->options & PR_O_DISPATCH)
7448 curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY);
7449 else if (curproxy->options & PR_O_HTTP_PROXY)
7450 curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP);
7451 else if (curproxy->options & PR_O_TRANSP)
7452 curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY);
Willy Tarreau82936582007-11-30 15:20:09 +01007453
Willy Tarreau1620ec32011-08-06 17:05:02 +02007454 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) {
7455 if (curproxy->options & PR_O_DISABLE404) {
7456 Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7457 "disable-on-404", proxy_type_str(curproxy), curproxy->id);
7458 err_code |= ERR_WARN;
7459 curproxy->options &= ~PR_O_DISABLE404;
7460 }
7461 if (curproxy->options2 & PR_O2_CHK_SNDST) {
7462 Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
7463 "send-state", proxy_type_str(curproxy), curproxy->id);
7464 err_code |= ERR_WARN;
7465 curproxy->options &= ~PR_O2_CHK_SNDST;
7466 }
Willy Tarreauef781042010-01-27 11:53:01 +01007467 }
7468
Simon Horman98637e52014-06-20 12:30:16 +09007469 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
7470 if (!global.external_check) {
7471 Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
7472 curproxy->id, "option external-check");
7473 cfgerr++;
7474 }
7475 if (!curproxy->check_command) {
7476 Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n",
7477 curproxy->id, "option external-check");
7478 cfgerr++;
7479 }
7480 }
7481
Simon Horman64e34162015-02-06 11:11:57 +09007482 if (curproxy->email_alert.set) {
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007483 if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) {
7484 Warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of "
Pieter Baauw8669e972015-08-17 00:45:05 +02007485 "'email-alert from', 'email-alert level' 'email-alert mailers', "
7486 "'email-alert myhostname', or 'email-alert to' "
7487 "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' "
Simon Horman0ba0e4a2015-01-30 11:23:00 +09007488 "to be present).\n",
7489 proxy_type_str(curproxy), curproxy->id);
7490 err_code |= ERR_WARN;
7491 free_email_alert(curproxy);
7492 }
7493 if (!curproxy->email_alert.myhostname)
Cyril Bontée22bfd62015-12-04 03:07:07 +01007494 curproxy->email_alert.myhostname = strdup(hostname);
Simon Horman9dc49962015-01-30 11:22:59 +09007495 }
7496
Simon Horman98637e52014-06-20 12:30:16 +09007497 if (curproxy->check_command) {
7498 int clear = 0;
7499 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
7500 Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7501 "external-check command", proxy_type_str(curproxy), curproxy->id);
7502 err_code |= ERR_WARN;
7503 clear = 1;
7504 }
7505 if (curproxy->check_command[0] != '/' && !curproxy->check_path) {
Ben Cabot49795eb2015-09-16 12:07:51 +01007506 Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n",
Simon Horman98637e52014-06-20 12:30:16 +09007507 curproxy->id, "external-check command");
7508 cfgerr++;
7509 }
7510 if (clear) {
7511 free(curproxy->check_command);
7512 curproxy->check_command = NULL;
7513 }
7514 }
7515
7516 if (curproxy->check_path) {
7517 if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) {
7518 Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
7519 "external-check path", proxy_type_str(curproxy), curproxy->id);
7520 err_code |= ERR_WARN;
7521 free(curproxy->check_path);
7522 curproxy->check_path = NULL;
7523 }
7524 }
7525
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007526 /* if a default backend was specified, let's find it */
7527 if (curproxy->defbe.name) {
7528 struct proxy *target;
7529
Willy Tarreauafb39922015-05-26 12:04:09 +02007530 target = proxy_be_by_name(curproxy->defbe.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007531 if (!target) {
7532 Alert("Proxy '%s': unable to find required default_backend: '%s'.\n",
7533 curproxy->id, curproxy->defbe.name);
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007534 cfgerr++;
7535 } else if (target == curproxy) {
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007536 Alert("Proxy '%s': loop detected for default_backend: '%s'.\n",
7537 curproxy->id, curproxy->defbe.name);
Willy Tarreaubb925012009-07-23 13:36:36 +02007538 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007539 } else if (target->mode != curproxy->mode &&
7540 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7541
7542 Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n",
7543 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7544 curproxy->conf.file, curproxy->conf.line,
7545 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7546 target->conf.file, target->conf.line);
7547 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01007548 } else {
7549 free(curproxy->defbe.name);
7550 curproxy->defbe.be = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007551 /* Update tot_fe_maxconn for a further fullconn's computation */
7552 target->tot_fe_maxconn += curproxy->maxconn;
Willy Tarreauff678132012-02-13 14:32:34 +01007553 /* Emit a warning if this proxy also has some servers */
7554 if (curproxy->srv) {
7555 Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n",
7556 curproxy->id);
7557 err_code |= ERR_WARN;
7558 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02007559 }
7560 }
7561
Emeric Brun3f783572017-01-12 11:21:28 +01007562 if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) {
7563 /* Case of listen without default backend
7564 * The curproxy will be its own default backend
7565 * so we update tot_fe_maxconn for a further
7566 * fullconn's computation */
7567 curproxy->tot_fe_maxconn += curproxy->maxconn;
7568 }
7569
Willy Tarreau55ea7572007-06-17 19:56:27 +02007570 /* find the target proxy for 'use_backend' rules */
7571 list_for_each_entry(rule, &curproxy->switching_rules, list) {
Willy Tarreau55ea7572007-06-17 19:56:27 +02007572 struct proxy *target;
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007573 struct logformat_node *node;
7574 char *pxname;
7575
7576 /* Try to parse the string as a log format expression. If the result
7577 * of the parsing is only one entry containing a simple string, then
7578 * it's a standard string corresponding to a static rule, thus the
7579 * parsing is cancelled and be.name is restored to be resolved.
7580 */
7581 pxname = rule->be.name;
7582 LIST_INIT(&rule->be.expr);
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +01007583 curproxy->conf.args.ctx = ARGC_UBK;
7584 curproxy->conf.args.file = rule->file;
7585 curproxy->conf.args.line = rule->line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01007586 err = NULL;
7587 if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) {
7588 Alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n",
7589 rule->file, rule->line, pxname, err);
7590 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01007591 cfgerr++;
7592 continue;
7593 }
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01007594 node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list);
7595
7596 if (!LIST_ISEMPTY(&rule->be.expr)) {
7597 if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) {
7598 rule->dynamic = 1;
7599 free(pxname);
7600 continue;
7601 }
7602 /* simple string: free the expression and fall back to static rule */
7603 free(node->arg);
7604 free(node);
7605 }
7606
7607 rule->dynamic = 0;
7608 rule->be.name = pxname;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007609
Willy Tarreauafb39922015-05-26 12:04:09 +02007610 target = proxy_be_by_name(rule->be.name);
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007611 if (!target) {
7612 Alert("Proxy '%s': unable to find required use_backend: '%s'.\n",
7613 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007614 cfgerr++;
7615 } else if (target == curproxy) {
Krzysztof Piotr Oledzki6eb730d2007-11-03 23:41:58 +01007616 Alert("Proxy '%s': loop detected for use_backend: '%s'.\n",
7617 curproxy->id, rule->be.name);
Willy Tarreau55ea7572007-06-17 19:56:27 +02007618 cfgerr++;
Willy Tarreauafb39922015-05-26 12:04:09 +02007619 } else if (target->mode != curproxy->mode &&
7620 !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) {
7621
7622 Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n",
7623 proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id,
7624 curproxy->conf.file, curproxy->conf.line,
7625 proxy_mode_str(target->mode), proxy_type_str(target), target->id,
7626 target->conf.file, target->conf.line);
7627 cfgerr++;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007628 } else {
7629 free((void *)rule->be.name);
7630 rule->be.backend = target;
Emeric Brun3f783572017-01-12 11:21:28 +01007631 /* For each target of switching rules, we update
7632 * their tot_fe_maxconn, except if a previous rule point
7633 * on the same backend or on the default backend */
7634 if (rule->be.backend != curproxy->defbe.be) {
7635 struct switching_rule *swrule;
7636
7637 list_for_each_entry(swrule, &curproxy->switching_rules, list) {
7638 if (rule == swrule) {
7639 target->tot_fe_maxconn += curproxy->maxconn;
7640 break;
7641 }
7642 else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) {
7643 /* there is multiple ref of this backend */
7644 break;
7645 }
7646 }
7647 }
Willy Tarreau55ea7572007-06-17 19:56:27 +02007648 }
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007649 }
7650
Willy Tarreau64ab6072014-09-16 12:17:36 +02007651 /* find the target server for 'use_server' rules */
Willy Tarreau4a5cade2012-04-05 21:09:48 +02007652 list_for_each_entry(srule, &curproxy->server_rules, list) {
7653 struct server *target = findserver(curproxy, srule->srv.name);
7654
7655 if (!target) {
7656 Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n",
7657 proxy_type_str(curproxy), curproxy->id, srule->srv.name);
7658 cfgerr++;
7659 continue;
7660 }
7661 free((void *)srule->srv.name);
7662 srule->srv.ptr = target;
Willy Tarreau55ea7572007-06-17 19:56:27 +02007663 }
7664
Emeric Brunb982a3d2010-01-04 15:45:53 +01007665 /* find the target table for 'stick' rules */
7666 list_for_each_entry(mrule, &curproxy->sticking_rules, list) {
7667 struct proxy *target;
7668
Emeric Brun1d33b292010-01-04 15:47:17 +01007669 curproxy->be_req_ana |= AN_REQ_STICKING_RULES;
7670 if (mrule->flags & STK_IS_STORE)
7671 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7672
Emeric Brunb982a3d2010-01-04 15:45:53 +01007673 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007674 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007675 else
7676 target = curproxy;
7677
7678 if (!target) {
7679 Alert("Proxy '%s': unable to find stick-table '%s'.\n",
7680 curproxy->id, mrule->table.name);
7681 cfgerr++;
7682 }
7683 else if (target->table.size == 0) {
7684 Alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7685 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7686 cfgerr++;
7687 }
Willy Tarreau12785782012-04-27 21:37:17 +02007688 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
7689 Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
Emeric Brunb982a3d2010-01-04 15:45:53 +01007690 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7691 cfgerr++;
7692 }
7693 else {
7694 free((void *)mrule->table.name);
7695 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007696 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007697 }
7698 }
7699
7700 /* find the target table for 'store response' rules */
7701 list_for_each_entry(mrule, &curproxy->storersp_rules, list) {
7702 struct proxy *target;
7703
Emeric Brun1d33b292010-01-04 15:47:17 +01007704 curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
7705
Emeric Brunb982a3d2010-01-04 15:45:53 +01007706 if (mrule->table.name)
Willy Tarreau9e0bb102015-05-26 11:24:42 +02007707 target = proxy_tbl_by_name(mrule->table.name);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007708 else
7709 target = curproxy;
7710
7711 if (!target) {
7712 Alert("Proxy '%s': unable to find store table '%s'.\n",
7713 curproxy->id, mrule->table.name);
7714 cfgerr++;
7715 }
7716 else if (target->table.size == 0) {
7717 Alert("Proxy '%s': stick-table '%s' used but not configured.\n",
7718 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7719 cfgerr++;
7720 }
Willy Tarreau12785782012-04-27 21:37:17 +02007721 else if (!stktable_compatible_sample(mrule->expr, target->table.type)) {
7722 Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n",
Emeric Brunb982a3d2010-01-04 15:45:53 +01007723 curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id);
7724 cfgerr++;
7725 }
7726 else {
7727 free((void *)mrule->table.name);
7728 mrule->table.t = &(target->table);
Willy Tarreau888617d2010-06-20 09:11:39 +02007729 stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL);
Emeric Brunb982a3d2010-01-04 15:45:53 +01007730 }
7731 }
7732
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007733 /* find the target table for 'tcp-request' layer 4 rules */
7734 list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) {
7735 struct proxy *target;
7736
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007737 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007738 continue;
7739
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007740 if (trule->arg.trk_ctr.table.n)
7741 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007742 else
7743 target = curproxy;
7744
7745 if (!target) {
Willy Tarreau56123282010-08-06 19:06:56 +02007746 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007747 curproxy->id, trule->arg.trk_ctr.table.n,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007748 tcp_trk_idx(trule->action));
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007749 cfgerr++;
7750 }
7751 else if (target->table.size == 0) {
7752 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007753 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007754 cfgerr++;
7755 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007756 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau5f53de72012-12-12 00:25:44 +01007757 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007758 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007759 tcp_trk_idx(trule->action));
Willy Tarreau5f53de72012-12-12 00:25:44 +01007760 cfgerr++;
7761 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007762 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007763 free(trule->arg.trk_ctr.table.n);
7764 trule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau56123282010-08-06 19:06:56 +02007765 /* Note: if we decide to enhance the track-sc syntax, we may be able
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02007766 * to pass a list of counters to track and allocate them right here using
7767 * stktable_alloc_data_type().
7768 */
7769 }
7770 }
7771
Willy Tarreau620408f2016-10-21 16:37:51 +02007772 /* find the target table for 'tcp-request' layer 5 rules */
7773 list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) {
7774 struct proxy *target;
7775
7776 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
7777 continue;
7778
7779 if (trule->arg.trk_ctr.table.n)
7780 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
7781 else
7782 target = curproxy;
7783
7784 if (!target) {
7785 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
7786 curproxy->id, trule->arg.trk_ctr.table.n,
7787 tcp_trk_idx(trule->action));
7788 cfgerr++;
7789 }
7790 else if (target->table.size == 0) {
7791 Alert("Proxy '%s': table '%s' used but not configured.\n",
7792 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
7793 cfgerr++;
7794 }
7795 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
7796 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
7797 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
7798 tcp_trk_idx(trule->action));
7799 cfgerr++;
7800 }
7801 else {
7802 free(trule->arg.trk_ctr.table.n);
7803 trule->arg.trk_ctr.table.t = &target->table;
7804 /* Note: if we decide to enhance the track-sc syntax, we may be able
7805 * to pass a list of counters to track and allocate them right here using
7806 * stktable_alloc_data_type().
7807 */
7808 }
7809 }
7810
Willy Tarreaud1f96522010-08-03 19:34:32 +02007811 /* find the target table for 'tcp-request' layer 6 rules */
7812 list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
7813 struct proxy *target;
7814
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007815 if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreaud1f96522010-08-03 19:34:32 +02007816 continue;
7817
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007818 if (trule->arg.trk_ctr.table.n)
7819 target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n);
Willy Tarreaud1f96522010-08-03 19:34:32 +02007820 else
7821 target = curproxy;
7822
7823 if (!target) {
Willy Tarreau56123282010-08-06 19:06:56 +02007824 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007825 curproxy->id, trule->arg.trk_ctr.table.n,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007826 tcp_trk_idx(trule->action));
Willy Tarreaud1f96522010-08-03 19:34:32 +02007827 cfgerr++;
7828 }
7829 else if (target->table.size == 0) {
7830 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007831 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreaud1f96522010-08-03 19:34:32 +02007832 cfgerr++;
7833 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007834 else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau5f53de72012-12-12 00:25:44 +01007835 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007836 curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id,
Willy Tarreau34c2fb62013-12-02 23:29:05 +01007837 tcp_trk_idx(trule->action));
Willy Tarreau5f53de72012-12-12 00:25:44 +01007838 cfgerr++;
7839 }
Willy Tarreaud1f96522010-08-03 19:34:32 +02007840 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007841 free(trule->arg.trk_ctr.table.n);
7842 trule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau56123282010-08-06 19:06:56 +02007843 /* Note: if we decide to enhance the track-sc syntax, we may be able
Willy Tarreaud1f96522010-08-03 19:34:32 +02007844 * to pass a list of counters to track and allocate them right here using
7845 * stktable_alloc_data_type().
7846 */
7847 }
7848 }
7849
Baptiste Assmanne9544932015-11-03 23:31:35 +01007850 /* parse http-request capture rules to ensure id really exists */
7851 list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) {
7852 if (hrqrule->action != ACT_CUSTOM ||
7853 hrqrule->action_ptr != http_action_req_capture_by_id)
7854 continue;
7855
7856 if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) {
7857 Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n",
7858 curproxy->id, hrqrule->arg.capid.idx);
7859 cfgerr++;
7860 }
7861 }
7862
7863 /* parse http-response capture rules to ensure id really exists */
7864 list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) {
7865 if (hrqrule->action != ACT_CUSTOM ||
7866 hrqrule->action_ptr != http_action_res_capture_by_id)
7867 continue;
7868
7869 if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) {
7870 Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n",
7871 curproxy->id, hrqrule->arg.capid.idx);
7872 cfgerr++;
7873 }
7874 }
7875
Willy Tarreau09448f72014-06-25 18:12:15 +02007876 /* find the target table for 'http-request' layer 7 rules */
7877 list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) {
7878 struct proxy *target;
7879
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02007880 if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX)
Willy Tarreau09448f72014-06-25 18:12:15 +02007881 continue;
7882
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007883 if (hrqrule->arg.trk_ctr.table.n)
7884 target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n);
Willy Tarreau09448f72014-06-25 18:12:15 +02007885 else
7886 target = curproxy;
7887
7888 if (!target) {
7889 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007890 curproxy->id, hrqrule->arg.trk_ctr.table.n,
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08007891 http_trk_idx(hrqrule->action));
Willy Tarreau09448f72014-06-25 18:12:15 +02007892 cfgerr++;
7893 }
7894 else if (target->table.size == 0) {
7895 Alert("Proxy '%s': table '%s' used but not configured.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007896 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id);
Willy Tarreau09448f72014-06-25 18:12:15 +02007897 cfgerr++;
7898 }
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007899 else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) {
Willy Tarreau09448f72014-06-25 18:12:15 +02007900 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007901 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id,
Ruoshan Huange4edc6b2016-07-14 15:07:45 +08007902 http_trk_idx(hrqrule->action));
7903 cfgerr++;
7904 }
7905 else {
7906 free(hrqrule->arg.trk_ctr.table.n);
7907 hrqrule->arg.trk_ctr.table.t = &target->table;
7908 /* Note: if we decide to enhance the track-sc syntax, we may be able
7909 * to pass a list of counters to track and allocate them right here using
7910 * stktable_alloc_data_type().
7911 */
7912 }
7913 }
7914
7915 /* find the target table for 'http-response' layer 7 rules */
7916 list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) {
7917 struct proxy *target;
7918
7919 if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX)
7920 continue;
7921
7922 if (hrqrule->arg.trk_ctr.table.n)
7923 target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n);
7924 else
7925 target = curproxy;
7926
7927 if (!target) {
7928 Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
7929 curproxy->id, hrqrule->arg.trk_ctr.table.n,
7930 http_trk_idx(hrqrule->action));
7931 cfgerr++;
7932 }
7933 else if (target->table.size == 0) {
7934 Alert("Proxy '%s': table '%s' used but not configured.\n",
7935 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id);
7936 cfgerr++;
7937 }
7938 else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) {
7939 Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
7940 curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id,
7941 http_trk_idx(hrqrule->action));
Willy Tarreau09448f72014-06-25 18:12:15 +02007942 cfgerr++;
7943 }
7944 else {
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02007945 free(hrqrule->arg.trk_ctr.table.n);
7946 hrqrule->arg.trk_ctr.table.t = &target->table;
Willy Tarreau09448f72014-06-25 18:12:15 +02007947 /* Note: if we decide to enhance the track-sc syntax, we may be able
7948 * to pass a list of counters to track and allocate them right here using
7949 * stktable_alloc_data_type().
7950 */
7951 }
7952 }
7953
Willy Tarreaub3dc39d2014-04-28 22:06:57 +02007954 /* move any "block" rules at the beginning of the http-request rules */
7955 if (!LIST_ISEMPTY(&curproxy->block_rules)) {
7956 /* insert block_rules into http_req_rules at the beginning */
7957 curproxy->block_rules.p->n = curproxy->http_req_rules.n;
7958 curproxy->http_req_rules.n->p = curproxy->block_rules.p;
7959 curproxy->block_rules.n->p = &curproxy->http_req_rules;
7960 curproxy->http_req_rules.n = curproxy->block_rules.n;
7961 LIST_INIT(&curproxy->block_rules);
7962 }
7963
Emeric Brun32da3c42010-09-23 18:39:19 +02007964 if (curproxy->table.peers.name) {
7965 struct peers *curpeers = peers;
7966
7967 for (curpeers = peers; curpeers; curpeers = curpeers->next) {
7968 if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
7969 free((void *)curproxy->table.peers.name);
Willy Tarreau973ca492013-01-17 21:34:52 +01007970 curproxy->table.peers.p = curpeers;
Emeric Brun32da3c42010-09-23 18:39:19 +02007971 break;
7972 }
7973 }
7974
7975 if (!curpeers) {
7976 Alert("Proxy '%s': unable to find sync peers '%s'.\n",
7977 curproxy->id, curproxy->table.peers.name);
Willy Tarreaud66bf962011-10-28 14:16:49 +02007978 free((void *)curproxy->table.peers.name);
7979 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02007980 cfgerr++;
7981 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02007982 else if (curpeers->state == PR_STSTOPPED) {
7983 /* silently disable this peers section */
7984 curproxy->table.peers.p = NULL;
7985 }
Emeric Brun32da3c42010-09-23 18:39:19 +02007986 else if (!curpeers->peers_fe) {
Willy Tarreau122541c2011-09-07 21:24:49 +02007987 Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n",
7988 curproxy->id, localpeer, curpeers->id);
Willy Tarreaud66bf962011-10-28 14:16:49 +02007989 curproxy->table.peers.p = NULL;
Emeric Brun32da3c42010-09-23 18:39:19 +02007990 cfgerr++;
7991 }
7992 }
7993
Simon Horman9dc49962015-01-30 11:22:59 +09007994
7995 if (curproxy->email_alert.mailers.name) {
7996 struct mailers *curmailers = mailers;
7997
7998 for (curmailers = mailers; curmailers; curmailers = curmailers->next) {
7999 if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) {
8000 free(curproxy->email_alert.mailers.name);
8001 curproxy->email_alert.mailers.m = curmailers;
8002 curmailers->users++;
8003 break;
8004 }
8005 }
8006
8007 if (!curmailers) {
8008 Alert("Proxy '%s': unable to find mailers '%s'.\n",
8009 curproxy->id, curproxy->email_alert.mailers.name);
8010 free_email_alert(curproxy);
8011 cfgerr++;
8012 }
8013 }
8014
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008015 if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) &&
Willy Tarreauff011f22011-01-06 17:51:27 +01008016 !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008017 (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) {
8018 Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n",
8019 "proxy", curproxy->id);
8020 cfgerr++;
8021 goto out_uri_auth_compat;
8022 }
8023
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008024 if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008025 const char *uri_auth_compat_req[10];
Thierry FOURNIERa28a9422015-08-04 19:35:46 +02008026 struct act_rule *rule;
Willy Tarreau95fa4692010-02-01 13:05:50 +01008027 int i = 0;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008028
Willy Tarreau95fa4692010-02-01 13:05:50 +01008029 /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */
8030 uri_auth_compat_req[i++] = "auth";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008031
8032 if (curproxy->uri_auth->auth_realm) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008033 uri_auth_compat_req[i++] = "realm";
8034 uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm;
8035 }
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008036
Willy Tarreau95fa4692010-02-01 13:05:50 +01008037 uri_auth_compat_req[i++] = "unless";
8038 uri_auth_compat_req[i++] = "{";
8039 uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)";
8040 uri_auth_compat_req[i++] = "}";
8041 uri_auth_compat_req[i++] = "";
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008042
Willy Tarreauff011f22011-01-06 17:51:27 +01008043 rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy);
8044 if (!rule) {
Willy Tarreau95fa4692010-02-01 13:05:50 +01008045 cfgerr++;
8046 break;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008047 }
8048
Willy Tarreauff011f22011-01-06 17:51:27 +01008049 LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
Willy Tarreau95fa4692010-02-01 13:05:50 +01008050
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008051 if (curproxy->uri_auth->auth_realm) {
8052 free(curproxy->uri_auth->auth_realm);
8053 curproxy->uri_auth->auth_realm = NULL;
8054 }
Krzysztof Piotr Oledzki329f74d2010-02-22 20:27:23 +01008055
8056 curproxy->uri_auth->flags |= ST_CONVDONE;
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01008057 }
8058out_uri_auth_compat:
8059
Dragan Dosen43885c72015-10-01 13:18:13 +02008060 /* check whether we have a log server that uses RFC5424 log format */
Dragan Dosen1322d092015-09-22 16:05:32 +02008061 list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) {
Dragan Dosen43885c72015-10-01 13:18:13 +02008062 if (tmplogsrv->format == LOG_FORMAT_RFC5424) {
8063 if (!curproxy->conf.logformat_sd_string) {
8064 /* set the default logformat_sd_string */
8065 curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format;
8066 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008067 break;
Dragan Dosen1322d092015-09-22 16:05:32 +02008068 }
Dragan Dosen1322d092015-09-22 16:05:32 +02008069 }
Dragan Dosen68d2e3a2015-09-19 22:35:44 +02008070
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008071 /* compile the log format */
8072 if (!(curproxy->cap & PR_CAP_FE)) {
Willy Tarreau62a61232013-04-12 18:13:46 +02008073 if (curproxy->conf.logformat_string != default_http_log_format &&
8074 curproxy->conf.logformat_string != default_tcp_log_format &&
8075 curproxy->conf.logformat_string != clf_http_log_format)
8076 free(curproxy->conf.logformat_string);
8077 curproxy->conf.logformat_string = NULL;
8078 free(curproxy->conf.lfs_file);
8079 curproxy->conf.lfs_file = NULL;
8080 curproxy->conf.lfs_line = 0;
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008081
8082 if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
8083 free(curproxy->conf.logformat_sd_string);
8084 curproxy->conf.logformat_sd_string = NULL;
8085 free(curproxy->conf.lfsd_file);
8086 curproxy->conf.lfsd_file = NULL;
8087 curproxy->conf.lfsd_line = 0;
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008088 }
8089
Willy Tarreau62a61232013-04-12 18:13:46 +02008090 if (curproxy->conf.logformat_string) {
8091 curproxy->conf.args.ctx = ARGC_LOG;
8092 curproxy->conf.args.file = curproxy->conf.lfs_file;
8093 curproxy->conf.args.line = curproxy->conf.lfs_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008094 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008095 if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008096 SMP_VAL_FE_LOG_END, &err)) {
8097 Alert("Parsing [%s:%d]: failed to parse log-format : %s.\n",
8098 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8099 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008100 cfgerr++;
8101 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008102 curproxy->conf.args.file = NULL;
8103 curproxy->conf.args.line = 0;
8104 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008105
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008106 if (curproxy->conf.logformat_sd_string) {
8107 curproxy->conf.args.ctx = ARGC_LOGSD;
8108 curproxy->conf.args.file = curproxy->conf.lfsd_file;
8109 curproxy->conf.args.line = curproxy->conf.lfsd_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008110 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008111 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 +01008112 SMP_VAL_FE_LOG_END, &err)) {
8113 Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8114 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8115 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008116 cfgerr++;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008117 } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) {
8118 Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n",
8119 curproxy->conf.lfs_file, curproxy->conf.lfs_line, err);
8120 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008121 cfgerr++;
8122 }
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008123 curproxy->conf.args.file = NULL;
8124 curproxy->conf.args.line = 0;
8125 }
8126
Willy Tarreau62a61232013-04-12 18:13:46 +02008127 if (curproxy->conf.uniqueid_format_string) {
8128 curproxy->conf.args.ctx = ARGC_UIF;
8129 curproxy->conf.args.file = curproxy->conf.uif_file;
8130 curproxy->conf.args.line = curproxy->conf.uif_line;
Thierry FOURNIER / OZON.IO8a4e4422016-11-23 00:41:28 +01008131 err = NULL;
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008132 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 +01008133 (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) {
8134 Alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n",
8135 curproxy->conf.uif_file, curproxy->conf.uif_line, err);
8136 free(err);
Thierry FOURNIER / OZON.IO59fd5112016-11-22 23:50:02 +01008137 cfgerr++;
8138 }
Willy Tarreau62a61232013-04-12 18:13:46 +02008139 curproxy->conf.args.file = NULL;
8140 curproxy->conf.args.line = 0;
8141 }
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008142
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +01008143 /* only now we can check if some args remain unresolved.
8144 * This must be done after the users and groups resolution.
8145 */
Willy Tarreaua4312fa2013-04-02 16:34:32 +02008146 cfgerr += smp_resolve_args(curproxy);
8147 if (!cfgerr)
8148 cfgerr += acl_find_targets(curproxy);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01008149
Willy Tarreau2738a142006-07-08 17:28:09 +02008150 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008151 (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) ||
Willy Tarreaud825eef2007-05-12 22:35:00 +02008152 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) &&
Willy Tarreauce887fd2012-05-12 12:50:00 +02008153 (!curproxy->timeout.connect ||
8154 (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008155 Warning("config : missing timeouts for %s '%s'.\n"
Willy Tarreau2738a142006-07-08 17:28:09 +02008156 " | While not properly invalid, you will certainly encounter various problems\n"
8157 " | with such a configuration. To fix this, please ensure that all following\n"
Willy Tarreau0f68eac2008-01-20 23:25:06 +01008158 " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n",
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008159 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008160 err_code |= ERR_WARN;
Willy Tarreau2738a142006-07-08 17:28:09 +02008161 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02008162
Willy Tarreau1fa31262007-12-03 00:36:16 +01008163 /* Historically, the tarpit and queue timeouts were inherited from contimeout.
8164 * We must still support older configurations, so let's find out whether those
8165 * parameters have been set or must be copied from contimeouts.
8166 */
8167 if (curproxy != &defproxy) {
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008168 if (!curproxy->timeout.tarpit ||
8169 curproxy->timeout.tarpit == defproxy.timeout.tarpit) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008170 /* tarpit timeout not set. We search in the following order:
8171 * default.tarpit, curr.connect, default.connect.
8172 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008173 if (defproxy.timeout.tarpit)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008174 curproxy->timeout.tarpit = defproxy.timeout.tarpit;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008175 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008176 curproxy->timeout.tarpit = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008177 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008178 curproxy->timeout.tarpit = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008179 }
8180 if ((curproxy->cap & PR_CAP_BE) &&
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008181 (!curproxy->timeout.queue ||
8182 curproxy->timeout.queue == defproxy.timeout.queue)) {
Willy Tarreau1fa31262007-12-03 00:36:16 +01008183 /* queue timeout not set. We search in the following order:
8184 * default.queue, curr.connect, default.connect.
8185 */
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008186 if (defproxy.timeout.queue)
Willy Tarreau1fa31262007-12-03 00:36:16 +01008187 curproxy->timeout.queue = defproxy.timeout.queue;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008188 else if (curproxy->timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008189 curproxy->timeout.queue = curproxy->timeout.connect;
Willy Tarreau0c303ee2008-07-07 00:09:58 +02008190 else if (defproxy.timeout.connect)
Willy Tarreaud7c30f92007-12-03 01:38:36 +01008191 curproxy->timeout.queue = defproxy.timeout.connect;
Willy Tarreau1fa31262007-12-03 00:36:16 +01008192 }
8193 }
8194
Willy Tarreau1620ec32011-08-06 17:05:02 +02008195 if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) {
Willy Tarreau137325d2010-02-01 16:38:17 +01008196 curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1;
Vincent Bernat3c2f2f22016-04-03 13:48:42 +02008197 curproxy->check_req = malloc(curproxy->check_len);
Willy Tarreau137325d2010-02-01 16:38:17 +01008198 memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len);
Willy Tarreauf3c69202006-07-09 16:42:34 +02008199 }
8200
Willy Tarreau215663d2014-06-13 18:30:23 +02008201 if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) &&
8202 (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) {
8203 Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n",
8204 proxy_type_str(curproxy), curproxy->id);
8205 err_code |= ERR_WARN;
8206 }
8207
Willy Tarreau193b8c62012-11-22 00:17:38 +01008208 /* ensure that cookie capture length is not too large */
8209 if (curproxy->capture_len >= global.tune.cookie_len) {
8210 Warning("config : truncating capture length to %d bytes for %s '%s'.\n",
8211 global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id);
8212 err_code |= ERR_WARN;
8213 curproxy->capture_len = global.tune.cookie_len - 1;
8214 }
8215
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008216 /* The small pools required for the capture lists */
Willy Tarreau9a54e132012-03-24 08:33:05 +01008217 if (curproxy->nb_req_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008218 curproxy->req_cap_pool = create_pool("ptrcap",
8219 curproxy->nb_req_cap * sizeof(char *),
8220 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008221 }
8222
8223 if (curproxy->nb_rsp_cap) {
Willy Tarreaud9ed3d22014-06-13 12:23:06 +02008224 curproxy->rsp_cap_pool = create_pool("ptrcap",
8225 curproxy->nb_rsp_cap * sizeof(char *),
8226 MEM_F_SHARED);
Willy Tarreau9a54e132012-03-24 08:33:05 +01008227 }
Willy Tarreaucf7f3202007-05-13 22:46:04 +02008228
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02008229 switch (curproxy->load_server_state_from_file) {
8230 case PR_SRV_STATE_FILE_UNSPEC:
8231 curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE;
8232 break;
8233 case PR_SRV_STATE_FILE_GLOBAL:
8234 if (!global.server_state_file) {
8235 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",
8236 curproxy->id);
8237 err_code |= ERR_WARN;
8238 }
8239 break;
8240 }
8241
Willy Tarreaubaaee002006-06-26 02:48:02 +02008242 /* first, we will invert the servers list order */
8243 newsrv = NULL;
8244 while (curproxy->srv) {
8245 struct server *next;
8246
8247 next = curproxy->srv->next;
8248 curproxy->srv->next = newsrv;
8249 newsrv = curproxy->srv;
8250 if (!next)
8251 break;
8252 curproxy->srv = next;
8253 }
8254
Willy Tarreau17edc812014-01-03 12:14:34 +01008255 /* Check that no server name conflicts. This causes trouble in the stats.
8256 * We only emit a warning for the first conflict affecting each server,
8257 * in order to avoid combinatory explosion if all servers have the same
8258 * name. We do that only for servers which do not have an explicit ID,
8259 * because these IDs were made also for distinguishing them and we don't
8260 * want to annoy people who correctly manage them.
8261 */
8262 for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
8263 struct server *other_srv;
8264
8265 if (newsrv->puid)
8266 continue;
8267
8268 for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) {
8269 if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) {
8270 Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n",
8271 newsrv->conf.file, newsrv->conf.line,
8272 proxy_type_str(curproxy), curproxy->id,
8273 newsrv->id, other_srv->conf.line);
8274 break;
8275 }
8276 }
8277 }
8278
Willy Tarreaudd701652010-05-25 23:03:02 +02008279 /* assign automatic UIDs to servers which don't have one yet */
8280 next_id = 1;
8281 newsrv = curproxy->srv;
8282 while (newsrv != NULL) {
8283 if (!newsrv->puid) {
8284 /* server ID not set, use automatic numbering with first
8285 * spare entry starting with next_svid.
8286 */
8287 next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
8288 newsrv->conf.id.key = newsrv->puid = next_id;
8289 eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
8290 }
8291 next_id++;
8292 newsrv = newsrv->next;
8293 }
8294
Willy Tarreau20697042007-11-15 23:26:18 +01008295 curproxy->lbprm.wmult = 1; /* default weight multiplier */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +01008296 curproxy->lbprm.wdiv = 1; /* default weight divider */
Willy Tarreaubaaee002006-06-26 02:48:02 +02008297
Willy Tarreau62c3be22012-01-20 13:12:32 +01008298 /*
8299 * If this server supports a maxconn parameter, it needs a dedicated
8300 * tasks to fill the emptied slots when a connection leaves.
8301 * Also, resolve deferred tracking dependency if needed.
8302 */
8303 newsrv = curproxy->srv;
8304 while (newsrv != NULL) {
8305 if (newsrv->minconn > newsrv->maxconn) {
8306 /* Only 'minconn' was specified, or it was higher than or equal
8307 * to 'maxconn'. Let's turn this into maxconn and clean it, as
8308 * this will avoid further useless expensive computations.
8309 */
8310 newsrv->maxconn = newsrv->minconn;
8311 } else if (newsrv->maxconn && !newsrv->minconn) {
8312 /* minconn was not specified, so we set it to maxconn */
8313 newsrv->minconn = newsrv->maxconn;
8314 }
8315
Willy Tarreau17d45382016-12-22 21:16:08 +01008316 /* this will also properly set the transport layer for prod and checks */
8317 if (newsrv->use_ssl || newsrv->check.use_ssl) {
8318 if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv)
8319 cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv);
8320 }
Emeric Brun94324a42012-10-11 14:00:19 +02008321
Willy Tarreau2f075e92013-12-03 11:11:34 +01008322 /* set the check type on the server */
8323 newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
8324
Willy Tarreau62c3be22012-01-20 13:12:32 +01008325 if (newsrv->trackit) {
8326 struct proxy *px;
Willy Tarreau32091232014-05-16 13:52:00 +02008327 struct server *srv, *loop;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008328 char *pname, *sname;
8329
8330 pname = newsrv->trackit;
8331 sname = strrchr(pname, '/');
8332
8333 if (sname)
8334 *sname++ = '\0';
8335 else {
8336 sname = pname;
8337 pname = NULL;
8338 }
8339
8340 if (pname) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02008341 px = proxy_be_by_name(pname);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008342 if (!px) {
8343 Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
8344 proxy_type_str(curproxy), curproxy->id,
8345 newsrv->id, pname);
8346 cfgerr++;
8347 goto next_srv;
8348 }
8349 } else
8350 px = curproxy;
8351
8352 srv = findserver(px, sname);
8353 if (!srv) {
8354 Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n",
8355 proxy_type_str(curproxy), curproxy->id,
8356 newsrv->id, sname);
8357 cfgerr++;
8358 goto next_srv;
8359 }
8360
Willy Tarreau32091232014-05-16 13:52:00 +02008361 if (!(srv->check.state & CHK_ST_CONFIGURED) &&
8362 !(srv->agent.state & CHK_ST_CONFIGURED) &&
8363 !srv->track && !srv->trackit) {
Willy Tarreau62c3be22012-01-20 13:12:32 +01008364 Alert("config : %s '%s', server '%s': unable to use %s/%s for "
Willy Tarreau32091232014-05-16 13:52:00 +02008365 "tracking as it does not have any check nor agent enabled.\n",
8366 proxy_type_str(curproxy), curproxy->id,
8367 newsrv->id, px->id, srv->id);
8368 cfgerr++;
8369 goto next_srv;
8370 }
8371
8372 for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
8373
8374 if (loop) {
8375 Alert("config : %s '%s', server '%s': unable to track %s/%s as it "
8376 "belongs to a tracking chain looping back to %s/%s.\n",
8377 proxy_type_str(curproxy), curproxy->id,
8378 newsrv->id, px->id, srv->id, px->id, loop->id);
Willy Tarreau62c3be22012-01-20 13:12:32 +01008379 cfgerr++;
8380 goto next_srv;
8381 }
8382
8383 if (curproxy != px &&
8384 (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
8385 Alert("config : %s '%s', server '%s': unable to use %s/%s for"
8386 "tracking: disable-on-404 option inconsistency.\n",
8387 proxy_type_str(curproxy), curproxy->id,
8388 newsrv->id, px->id, srv->id);
8389 cfgerr++;
8390 goto next_srv;
8391 }
8392
Willy Tarreau62c3be22012-01-20 13:12:32 +01008393 newsrv->track = srv;
Willy Tarreau1a53a3a2013-12-11 15:27:05 +01008394 newsrv->tracknext = srv->trackers;
8395 srv->trackers = newsrv;
Willy Tarreau62c3be22012-01-20 13:12:32 +01008396
8397 free(newsrv->trackit);
8398 newsrv->trackit = NULL;
8399 }
Baptiste Assmanna68ca962015-04-14 01:15:08 +02008400
8401 /*
8402 * resolve server's resolvers name and update the resolvers pointer
8403 * accordingly
8404 */
8405 if (newsrv->resolvers_id) {
8406 struct dns_resolvers *curr_resolvers;
8407 int found;
8408
8409 found = 0;
8410 list_for_each_entry(curr_resolvers, &dns_resolvers, list) {
8411 if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) {
8412 found = 1;
8413 break;
8414 }
8415 }
8416
8417 if (!found) {
8418 Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n",
8419 proxy_type_str(curproxy), curproxy->id,
8420 newsrv->id, newsrv->resolvers_id);
8421 cfgerr++;
8422 } else {
8423 free(newsrv->resolvers_id);
8424 newsrv->resolvers_id = NULL;
8425 if (newsrv->resolution)
8426 newsrv->resolution->resolvers = curr_resolvers;
8427 }
8428 }
8429 else {
8430 /* if no resolvers section associated to this server
8431 * we can clean up the associated resolution structure
8432 */
8433 if (newsrv->resolution) {
8434 free(newsrv->resolution->hostname_dn);
8435 newsrv->resolution->hostname_dn = NULL;
8436 free(newsrv->resolution);
8437 newsrv->resolution = NULL;
8438 }
8439 }
8440
Willy Tarreau62c3be22012-01-20 13:12:32 +01008441 next_srv:
8442 newsrv = newsrv->next;
8443 }
8444
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008445 /* We have to initialize the server lookup mechanism depending
8446 * on what LB algorithm was choosen.
8447 */
8448
8449 curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
8450 switch (curproxy->lbprm.algo & BE_LB_KIND) {
8451 case BE_LB_KIND_RR:
Willy Tarreau9757a382009-10-03 12:56:50 +02008452 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
8453 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8454 init_server_map(curproxy);
8455 } else {
8456 curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
8457 fwrr_init_server_groups(curproxy);
8458 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008459 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008460
Willy Tarreau3ebb1162012-02-13 16:57:44 +01008461 case BE_LB_KIND_CB:
Willy Tarreauf09c6602012-02-13 17:12:08 +01008462 if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
8463 curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
8464 fwlc_init_server_tree(curproxy);
8465 } else {
8466 curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
8467 fas_init_server_tree(curproxy);
8468 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008469 break;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008470
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008471 case BE_LB_KIND_HI:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02008472 if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
8473 curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
8474 chash_init_server_tree(curproxy);
8475 } else {
8476 curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
8477 init_server_map(curproxy);
8478 }
Willy Tarreauf3e49f92009-10-03 12:21:20 +02008479 break;
8480 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02008481
8482 if (curproxy->options & PR_O_LOGASAP)
8483 curproxy->to_log &= ~LW_BYTES;
8484
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008485 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Dragan Dosen0b85ece2015-09-25 19:17:44 +02008486 (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) &&
8487 (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) {
Willy Tarreaue7ded1f2009-08-09 10:11:45 +02008488 Warning("config : log format ignored for %s '%s' since it has no log address.\n",
8489 proxy_type_str(curproxy), curproxy->id);
8490 err_code |= ERR_WARN;
8491 }
8492
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008493 if (curproxy->mode != PR_MODE_HTTP) {
8494 int optnum;
8495
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008496 if (curproxy->uri_auth) {
8497 Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n",
8498 proxy_type_str(curproxy), curproxy->id);
8499 err_code |= ERR_WARN;
8500 curproxy->uri_auth = NULL;
8501 }
8502
Willy Tarreau87cf5142011-08-19 22:57:24 +02008503 if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) {
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008504 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8505 "forwardfor", proxy_type_str(curproxy), curproxy->id);
8506 err_code |= ERR_WARN;
Willy Tarreau87cf5142011-08-19 22:57:24 +02008507 curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS);
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008508 }
8509
8510 if (curproxy->options & PR_O_ORGTO) {
8511 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8512 "originalto", proxy_type_str(curproxy), curproxy->id);
8513 err_code |= ERR_WARN;
8514 curproxy->options &= ~PR_O_ORGTO;
8515 }
8516
8517 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
8518 if (cfg_opts[optnum].mode == PR_MODE_HTTP &&
8519 (curproxy->cap & cfg_opts[optnum].cap) &&
8520 (curproxy->options & cfg_opts[optnum].val)) {
8521 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8522 cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id);
8523 err_code |= ERR_WARN;
8524 curproxy->options &= ~cfg_opts[optnum].val;
8525 }
8526 }
8527
8528 for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
8529 if (cfg_opts2[optnum].mode == PR_MODE_HTTP &&
8530 (curproxy->cap & cfg_opts2[optnum].cap) &&
8531 (curproxy->options2 & cfg_opts2[optnum].val)) {
8532 Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n",
8533 cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id);
8534 err_code |= ERR_WARN;
8535 curproxy->options2 &= ~cfg_opts2[optnum].val;
8536 }
8537 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008538
Willy Tarreau29fbe512015-08-20 19:35:14 +02008539#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008540 if (curproxy->conn_src.bind_hdr_occ) {
8541 curproxy->conn_src.bind_hdr_occ = 0;
Willy Tarreaubce70882009-09-07 11:51:47 +02008542 Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n",
Willy Tarreauef9a3602012-12-08 22:29:20 +01008543 proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008544 err_code |= ERR_WARN;
8545 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008546#endif
Willy Tarreaue24fdfb2010-03-25 07:22:56 +01008547 }
8548
Willy Tarreaubaaee002006-06-26 02:48:02 +02008549 /*
Willy Tarreau21d2af32008-02-14 20:25:24 +01008550 * ensure that we're not cross-dressing a TCP server into HTTP.
8551 */
8552 newsrv = curproxy->srv;
8553 while (newsrv != NULL) {
Willy Tarreau0cec3312011-10-31 13:49:26 +01008554 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) {
Willy Tarreau915e1eb2009-06-22 15:48:36 +02008555 Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
8556 proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubb925012009-07-23 13:36:36 +02008557 cfgerr++;
Willy Tarreau21d2af32008-02-14 20:25:24 +01008558 }
Willy Tarreaubce70882009-09-07 11:51:47 +02008559
Willy Tarreau0cec3312011-10-31 13:49:26 +01008560 if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) {
8561 Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n",
8562 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8563 err_code |= ERR_WARN;
8564 }
8565
Willy Tarreauc93cd162014-05-13 15:54:22 +02008566 if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) {
Willy Tarreau82ffa392013-08-13 17:19:08 +02008567 Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n",
8568 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8569 err_code |= ERR_WARN;
8570 }
8571
Willy Tarreau29fbe512015-08-20 19:35:14 +02008572#if defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreauef9a3602012-12-08 22:29:20 +01008573 if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) {
8574 newsrv->conn_src.bind_hdr_occ = 0;
Willy Tarreaubce70882009-09-07 11:51:47 +02008575 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 +01008576 proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name);
Willy Tarreaubce70882009-09-07 11:51:47 +02008577 err_code |= ERR_WARN;
8578 }
Willy Tarreauefa5f512010-03-30 20:13:29 +02008579#endif
Willy Tarreau4c183462017-01-06 12:21:38 +01008580
8581 if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) {
8582 if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8583 (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP ||
8584 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI ||
8585 (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) {
8586 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",
8587 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8588 err_code |= ERR_WARN;
8589 }
8590
8591
8592 if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) {
8593 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",
8594 proxy_type_str(curproxy), curproxy->id, newsrv->id);
8595 err_code |= ERR_WARN;
8596 }
8597 }
8598
Willy Tarreau21d2af32008-02-14 20:25:24 +01008599 newsrv = newsrv->next;
8600 }
8601
Willy Tarreaue42bd962014-09-16 16:21:19 +02008602 /* check if we have a frontend with "tcp-request content" looking at L7
8603 * with no inspect-delay
8604 */
8605 if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) {
8606 list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02008607 if (trule->action == ACT_TCP_CAPTURE &&
Thierry FOURNIERd0d65ae2015-08-04 08:21:12 +02008608 !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008609 break;
Thierry FOURNIER0ea5c7f2015-08-05 19:05:19 +02008610 if ((trule->action >= ACT_ACTION_TRK_SC0 && trule->action <= ACT_ACTION_TRK_SCMAX) &&
Thierry FOURNIER5ec63e02015-08-04 09:09:48 +02008611 !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC))
Willy Tarreaue42bd962014-09-16 16:21:19 +02008612 break;
8613 }
8614
8615 if (&trule->list != &curproxy->tcp_req.inspect_rules) {
8616 Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request"
8617 " contents were found in a frontend without any 'tcp-request inspect-delay' setting."
8618 " This means that these rules will randomly find their contents. This can be fixed by"
8619 " setting the tcp-request inspect-delay.\n",
8620 proxy_type_str(curproxy), curproxy->id);
8621 err_code |= ERR_WARN;
8622 }
8623 }
8624
Christopher Fauletd7c91962015-04-30 11:48:27 +02008625 /* Check filter configuration, if any */
8626 cfgerr += flt_check(curproxy);
8627
Willy Tarreauc1a21672009-08-16 22:37:44 +02008628 if (curproxy->cap & PR_CAP_FE) {
Willy Tarreau050536d2012-10-04 08:47:34 +02008629 if (!curproxy->accept)
8630 curproxy->accept = frontend_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +02008631
Willy Tarreauc1a21672009-08-16 22:37:44 +02008632 if (curproxy->tcp_req.inspect_delay ||
8633 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
Willy Tarreaufb356202010-08-03 14:02:05 +02008634 curproxy->fe_req_ana |= AN_REQ_INSPECT_FE;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008635
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008636 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008637 curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008638 curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008639 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008640
8641 /* both TCP and HTTP must check switching rules */
8642 curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008643
8644 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008645 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008646 curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8647 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 +01008648 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008649 curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8650 curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008651 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008652 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008653 }
8654
8655 if (curproxy->cap & PR_CAP_BE) {
Willy Tarreaufb356202010-08-03 14:02:05 +02008656 if (curproxy->tcp_req.inspect_delay ||
8657 !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
8658 curproxy->be_req_ana |= AN_REQ_INSPECT_BE;
8659
Emeric Brun97679e72010-09-23 17:56:44 +02008660 if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules))
8661 curproxy->be_rsp_ana |= AN_RES_INSPECT;
8662
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008663 if (curproxy->mode == PR_MODE_HTTP) {
Willy Tarreauc1a21672009-08-16 22:37:44 +02008664 curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02008665 curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE;
Willy Tarreau4e5b8282009-08-16 22:57:50 +02008666 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008667
8668 /* If the backend does requires RDP cookie persistence, we have to
8669 * enable the corresponding analyser.
8670 */
8671 if (curproxy->options2 & PR_O2_RDPC_PRST)
8672 curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02008673
8674 /* Add filters analyzers if needed */
Christopher Faulet443ea1a2016-02-04 13:40:26 +01008675 if (!LIST_ISEMPTY(&curproxy->filter_configs)) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008676 curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END;
8677 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 +01008678 if (curproxy->mode == PR_MODE_HTTP) {
Christopher Faulet0184ea72017-01-05 14:06:34 +01008679 curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS;
8680 curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS;
Christopher Faulet309c6412015-12-02 09:57:32 +01008681 }
Christopher Fauletd7c91962015-04-30 11:48:27 +02008682 }
Willy Tarreauc1a21672009-08-16 22:37:44 +02008683 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008684 }
8685
8686 /***********************************************************/
8687 /* At this point, target names have already been resolved. */
8688 /***********************************************************/
8689
8690 /* Check multi-process mode compatibility */
8691
8692 if (global.nbproc > 1 && global.stats_fe) {
8693 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8694 unsigned long mask;
8695
8696 mask = nbits(global.nbproc);
8697 if (global.stats_fe->bind_proc)
8698 mask &= global.stats_fe->bind_proc;
8699
8700 if (bind_conf->bind_proc)
8701 mask &= bind_conf->bind_proc;
8702
8703 /* stop here if more than one process is used */
David Carliere6c39412015-07-02 07:00:17 +00008704 if (my_popcountl(mask) > 1)
Willy Tarreau419ead82014-09-16 13:41:21 +02008705 break;
8706 }
8707 if (&bind_conf->by_fe != &global.stats_fe->conf.bind) {
8708 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");
8709 }
8710 }
8711
8712 /* Make each frontend inherit bind-process from its listeners when not specified. */
8713 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8714 if (curproxy->bind_proc)
8715 continue;
8716
8717 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
8718 unsigned long mask;
8719
Willy Tarreaue428b082015-05-04 21:57:58 +02008720 mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008721 curproxy->bind_proc |= mask;
8722 }
8723
8724 if (!curproxy->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008725 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008726 }
8727
8728 if (global.stats_fe) {
8729 list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
8730 unsigned long mask;
8731
Cyril Bonté06181952016-02-24 00:14:54 +01008732 mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
Willy Tarreau419ead82014-09-16 13:41:21 +02008733 global.stats_fe->bind_proc |= mask;
8734 }
8735 if (!global.stats_fe->bind_proc)
Willy Tarreaue428b082015-05-04 21:57:58 +02008736 global.stats_fe->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008737 }
8738
Willy Tarreauacbe8ab2014-10-01 20:50:17 +02008739 /* propagate bindings from frontends to backends. Don't do it if there
8740 * are any fatal errors as we must not call it with unresolved proxies.
8741 */
8742 if (!cfgerr) {
8743 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8744 if (curproxy->cap & PR_CAP_FE)
8745 propagate_processes(curproxy, NULL);
8746 }
Willy Tarreau419ead82014-09-16 13:41:21 +02008747 }
8748
8749 /* Bind each unbound backend to all processes when not specified. */
8750 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8751 if (curproxy->bind_proc)
8752 continue;
Willy Tarreaue428b082015-05-04 21:57:58 +02008753 curproxy->bind_proc = nbits(global.nbproc);
Willy Tarreau419ead82014-09-16 13:41:21 +02008754 }
8755
8756 /*******************************************************/
8757 /* At this step, all proxies have a non-null bind_proc */
8758 /*******************************************************/
8759
8760 /* perform the final checks before creating tasks */
8761
8762 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8763 struct listener *listener;
8764 unsigned int next_id;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008765
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008766 /* Configure SSL for each bind line.
8767 * Note: if configuration fails at some point, the ->ctx member
8768 * remains NULL so that listeners can later detach.
8769 */
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008770 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau55d37912016-12-21 23:38:39 +01008771 if (bind_conf->xprt->prepare_bind_conf &&
8772 bind_conf->xprt->prepare_bind_conf(bind_conf) < 0)
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008773 cfgerr++;
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008774 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008775
Willy Tarreaue6b98942007-10-29 01:09:36 +01008776 /* adjust this proxy's listeners */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008777 next_id = 1;
Willy Tarreau4348fad2012-09-20 16:48:07 +02008778 list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) {
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008779 int nbproc;
8780
8781 nbproc = my_popcountl(curproxy->bind_proc &
Cyril Bonté4920d702016-04-15 07:58:43 +02008782 (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) &
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008783 nbits(global.nbproc));
8784
8785 if (!nbproc) /* no intersection between listener and frontend */
8786 nbproc = 1;
8787
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008788 if (!listener->luid) {
8789 /* listener ID not set, use automatic numbering with first
8790 * spare entry starting with next_luid.
8791 */
8792 next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
8793 listener->conf.id.key = listener->luid = next_id;
8794 eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008795 }
Krzysztof Piotr Oledzkidf5cb9f2010-02-05 20:58:27 +01008796 next_id++;
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02008797
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008798 /* enable separate counters */
8799 if (curproxy->options2 & PR_O2_SOCKSTAT) {
Willy Tarreauae9bea02016-11-25 14:44:52 +01008800 listener->counters = calloc(1, sizeof(*listener->counters));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01008801 if (!listener->name)
8802 memprintf(&listener->name, "sock-%d", listener->luid);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02008803 }
Willy Tarreau81796be2012-09-22 19:11:47 +02008804
Willy Tarreaue6b98942007-10-29 01:09:36 +01008805 if (curproxy->options & PR_O_TCP_NOLING)
8806 listener->options |= LI_O_NOLINGER;
Willy Tarreau32368ce2012-09-06 11:10:55 +02008807 if (!listener->maxconn)
8808 listener->maxconn = curproxy->maxconn;
8809 if (!listener->backlog)
8810 listener->backlog = curproxy->backlog;
Willy Tarreau16a21472012-11-19 12:39:59 +01008811 if (!listener->maxaccept)
8812 listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;
8813
8814 /* we want to have an optimal behaviour on single process mode to
8815 * maximize the work at once, but in multi-process we want to keep
8816 * some fairness between processes, so we target half of the max
8817 * number of events to be balanced over all the processes the proxy
8818 * is bound to. Rememeber that maxaccept = -1 must be kept as it is
8819 * used to disable the limit.
8820 */
8821 if (listener->maxaccept > 0) {
8822 if (nbproc > 1)
8823 listener->maxaccept = (listener->maxaccept + 1) / 2;
8824 listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc;
8825 }
8826
Willy Tarreau9903f0e2015-04-04 18:50:31 +02008827 listener->accept = session_accept_fd;
Willy Tarreau87b09662015-04-03 00:22:06 +02008828 listener->handler = process_stream;
Willy Tarreauc1a21672009-08-16 22:37:44 +02008829 listener->analysers |= curproxy->fe_req_ana;
Willy Tarreau10b688f2015-03-13 16:43:12 +01008830 listener->default_target = curproxy->default_target;
Willy Tarreau3bc13772008-12-07 11:50:35 +01008831
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008832 if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules))
Willy Tarreau7d9736f2016-10-21 16:34:21 +02008833 listener->options |= LI_O_TCP_L4_RULES;
Willy Tarreaua5c0ab22010-05-31 10:30:33 +02008834
Willy Tarreau620408f2016-10-21 16:37:51 +02008835 if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules))
8836 listener->options |= LI_O_TCP_L5_RULES;
8837
Willy Tarreaude3041d2010-05-31 10:56:17 +02008838 if (curproxy->mon_mask.s_addr)
8839 listener->options |= LI_O_CHK_MONNET;
8840
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008841 /* smart accept mode is automatic in HTTP mode */
8842 if ((curproxy->options2 & PR_O2_SMARTACC) ||
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008843 ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) &&
Willy Tarreau9ea05a72009-06-14 12:07:01 +02008844 !(curproxy->no_options2 & PR_O2_SMARTACC)))
8845 listener->options |= LI_O_NOQUICKACK;
Willy Tarreaue6b98942007-10-29 01:09:36 +01008846 }
8847
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008848 /* Release unused SSL configs */
8849 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
Willy Tarreau795cdab2016-12-22 17:30:54 +01008850 if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf)
8851 bind_conf->xprt->destroy_bind_conf(bind_conf);
Willy Tarreau2a65ff02012-09-13 17:54:29 +02008852 }
Willy Tarreauf5ae8f72012-09-07 16:58:00 +02008853
Willy Tarreau7c0ffd22016-04-14 11:47:38 +02008854 if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) {
Willy Tarreau102df612014-05-07 23:56:38 +02008855 if (curproxy->uri_auth) {
Willy Tarreaueb791e02014-09-16 15:11:04 +02008856 int count, maxproc = 0;
8857
8858 list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
David Carliere6c39412015-07-02 07:00:17 +00008859 count = my_popcountl(bind_conf->bind_proc);
Willy Tarreaueb791e02014-09-16 15:11:04 +02008860 if (count > maxproc)
8861 maxproc = count;
8862 }
8863 /* backends have 0, frontends have 1 or more */
8864 if (maxproc != 1)
8865 Warning("Proxy '%s': in multi-process mode, stats will be"
8866 " limited to process assigned to the current request.\n",
8867 curproxy->id);
8868
Willy Tarreau102df612014-05-07 23:56:38 +02008869 if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
8870 Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n",
8871 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008872 }
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008873 }
Willy Tarreau102df612014-05-07 23:56:38 +02008874 if (!LIST_ISEMPTY(&curproxy->sticking_rules)) {
8875 Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n",
8876 curproxy->id);
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008877 }
8878 }
Willy Tarreau918ff602011-07-25 16:33:49 +02008879
8880 /* create the task associated with the proxy */
8881 curproxy->task = task_new();
8882 if (curproxy->task) {
8883 curproxy->task->context = curproxy;
8884 curproxy->task->process = manage_proxy;
8885 /* no need to queue, it will be done automatically if some
8886 * listener gets limited.
8887 */
8888 curproxy->task->expire = TICK_ETERNITY;
8889 } else {
8890 Alert("Proxy '%s': no more memory when trying to allocate the management task\n",
8891 curproxy->id);
8892 cfgerr++;
8893 }
Willy Tarreaub369a042014-09-16 13:21:03 +02008894 }
8895
Willy Tarreaufbb78422011-06-05 15:38:35 +02008896 /* automatically compute fullconn if not set. We must not do it in the
8897 * loop above because cross-references are not yet fully resolved.
8898 */
8899 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8900 /* If <fullconn> is not set, let's set it to 10% of the sum of
8901 * the possible incoming frontend's maxconns.
8902 */
8903 if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) {
Willy Tarreaufbb78422011-06-05 15:38:35 +02008904 /* we have the sum of the maxconns in <total>. We only
8905 * keep 10% of that sum to set the default fullconn, with
8906 * a hard minimum of 1 (to avoid a divide by zero).
8907 */
Emeric Brun3f783572017-01-12 11:21:28 +01008908 curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10;
Willy Tarreaufbb78422011-06-05 15:38:35 +02008909 if (!curproxy->fullconn)
8910 curproxy->fullconn = 1;
8911 }
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +01008912 }
8913
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008914 /*
8915 * Recount currently required checks.
8916 */
8917
8918 for (curproxy=proxy; curproxy; curproxy=curproxy->next) {
8919 int optnum;
8920
Willy Tarreau66aa61f2009-01-18 21:44:07 +01008921 for (optnum = 0; cfg_opts[optnum].name; optnum++)
8922 if (curproxy->options & cfg_opts[optnum].val)
8923 global.last_checks |= cfg_opts[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008924
Willy Tarreau66aa61f2009-01-18 21:44:07 +01008925 for (optnum = 0; cfg_opts2[optnum].name; optnum++)
8926 if (curproxy->options2 & cfg_opts2[optnum].val)
8927 global.last_checks |= cfg_opts2[optnum].checks;
Krzysztof Oledzki336d4752007-12-25 02:40:22 +01008928 }
8929
Willy Tarreau0fca4832015-05-01 19:12:05 +02008930 /* compute the required process bindings for the peers */
8931 for (curproxy = proxy; curproxy; curproxy = curproxy->next)
8932 if (curproxy->table.peers.p)
8933 curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
8934
Willy Tarreau122541c2011-09-07 21:24:49 +02008935 if (peers) {
8936 struct peers *curpeers = peers, **last;
8937 struct peer *p, *pb;
8938
Willy Tarreau1e273012015-05-01 19:15:17 +02008939 /* Remove all peers sections which don't have a valid listener,
8940 * which are not used by any table, or which are bound to more
8941 * than one process.
Willy Tarreau122541c2011-09-07 21:24:49 +02008942 */
8943 last = &peers;
8944 while (*last) {
8945 curpeers = *last;
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008946
8947 if (curpeers->state == PR_STSTOPPED) {
8948 /* the "disabled" keyword was present */
8949 if (curpeers->peers_fe)
8950 stop_proxy(curpeers->peers_fe);
8951 curpeers->peers_fe = NULL;
8952 }
8953 else if (!curpeers->peers_fe) {
8954 Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n",
8955 curpeers->id, localpeer);
8956 }
David Carliere6c39412015-07-02 07:00:17 +00008957 else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) {
Willy Tarreau1e273012015-05-01 19:15:17 +02008958 /* either it's totally stopped or too much used */
8959 if (curpeers->peers_fe->bind_proc) {
8960 Alert("Peers section '%s': peers referenced by sections "
Willy Tarreau64c57222015-05-04 21:48:51 +02008961 "running in different processes (%d different ones). "
8962 "Check global.nbproc and all tables' bind-process "
David Carliere6c39412015-07-02 07:00:17 +00008963 "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc));
Willy Tarreau1e273012015-05-01 19:15:17 +02008964 cfgerr++;
8965 }
8966 stop_proxy(curpeers->peers_fe);
8967 curpeers->peers_fe = NULL;
8968 }
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008969 else {
Emeric Brunb3971ab2015-05-12 18:49:09 +02008970 peers_init_sync(curpeers);
Willy Tarreau122541c2011-09-07 21:24:49 +02008971 last = &curpeers->next;
8972 continue;
8973 }
8974
Willy Tarreau77e4bd12015-05-01 20:02:17 +02008975 /* clean what has been detected above */
Willy Tarreau122541c2011-09-07 21:24:49 +02008976 p = curpeers->remote;
8977 while (p) {
8978 pb = p->next;
8979 free(p->id);
8980 free(p);
8981 p = pb;
8982 }
8983
8984 /* Destroy and unlink this curpeers section.
8985 * Note: curpeers is backed up into *last.
8986 */
8987 free(curpeers->id);
8988 curpeers = curpeers->next;
8989 free(*last);
8990 *last = curpeers;
8991 }
8992 }
8993
Willy Tarreau6866f3f2015-05-01 19:09:08 +02008994 /* initialize stick-tables on backend capable proxies. This must not
8995 * be done earlier because the data size may be discovered while parsing
8996 * other proxies.
8997 */
8998 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
8999 if (curproxy->state == PR_STSTOPPED)
9000 continue;
9001
9002 if (!stktable_init(&curproxy->table)) {
9003 Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id);
9004 cfgerr++;
9005 }
9006 }
9007
Simon Horman0d16a402015-01-30 11:22:58 +09009008 if (mailers) {
9009 struct mailers *curmailers = mailers, **last;
9010 struct mailer *m, *mb;
9011
9012 /* Remove all mailers sections which don't have a valid listener.
9013 * This can happen when a mailers section is never referenced.
9014 */
9015 last = &mailers;
9016 while (*last) {
9017 curmailers = *last;
9018 if (curmailers->users) {
9019 last = &curmailers->next;
9020 continue;
9021 }
9022
9023 Warning("Removing incomplete section 'mailers %s'.\n",
9024 curmailers->id);
9025
9026 m = curmailers->mailer_list;
9027 while (m) {
9028 mb = m->next;
9029 free(m->id);
9030 free(m);
9031 m = mb;
9032 }
9033
9034 /* Destroy and unlink this curmailers section.
9035 * Note: curmailers is backed up into *last.
9036 */
9037 free(curmailers->id);
9038 curmailers = curmailers->next;
9039 free(*last);
9040 *last = curmailers;
9041 }
9042 }
9043
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +02009044 /* Update server_state_file_name to backend name if backend is supposed to use
9045 * a server-state file locally defined and none has been provided */
9046 for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
9047 if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
9048 curproxy->server_state_file_name == NULL)
9049 curproxy->server_state_file_name = strdup(curproxy->id);
9050 }
9051
Willy Tarreau34eb6712011-10-24 18:15:04 +02009052 pool2_hdr_idx = create_pool("hdr_idx",
Willy Tarreauac1932d2011-10-24 19:14:41 +02009053 global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
Willy Tarreau34eb6712011-10-24 18:15:04 +02009054 MEM_F_SHARED);
9055
Willy Tarreaubb925012009-07-23 13:36:36 +02009056 if (cfgerr > 0)
9057 err_code |= ERR_ALERT | ERR_FATAL;
9058 out:
9059 return err_code;
Willy Tarreaubaaee002006-06-26 02:48:02 +02009060}
9061
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009062/*
9063 * Registers the CFG keyword list <kwl> as a list of valid keywords for next
9064 * parsing sessions.
9065 */
9066void cfg_register_keywords(struct cfg_kw_list *kwl)
9067{
9068 LIST_ADDQ(&cfg_keywords.list, &kwl->list);
9069}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009070
Willy Tarreau5b2c3362008-07-09 19:39:06 +02009071/*
9072 * Unregisters the CFG keyword list <kwl> from the list of valid keywords.
9073 */
9074void cfg_unregister_keywords(struct cfg_kw_list *kwl)
9075{
9076 LIST_DEL(&kwl->list);
9077 LIST_INIT(&kwl->list);
9078}
Willy Tarreaubaaee002006-06-26 02:48:02 +02009079
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009080/* this function register new section in the haproxy configuration file.
9081 * <section_name> is the name of this new section and <section_parser>
9082 * is the called parser. If two section declaration have the same name,
9083 * only the first declared is used.
9084 */
9085int cfg_register_section(char *section_name,
9086 int (*section_parser)(const char *, int, char **, int))
9087{
9088 struct cfg_section *cs;
9089
Willy Tarreau5e4261b2016-05-17 16:16:09 +02009090 list_for_each_entry(cs, &sections, list) {
9091 if (strcmp(cs->section_name, section_name) == 0) {
9092 Alert("register section '%s': already registered.\n", section_name);
9093 return 0;
9094 }
9095 }
9096
Thierry FOURNIERfa45f1d2014-03-18 13:54:18 +01009097 cs = calloc(1, sizeof(*cs));
9098 if (!cs) {
9099 Alert("register section '%s': out of memory.\n", section_name);
9100 return 0;
9101 }
9102
9103 cs->section_name = section_name;
9104 cs->section_parser = section_parser;
9105
9106 LIST_ADDQ(&sections, &cs->list);
9107
9108 return 1;
9109}
9110
Willy Tarreaubaaee002006-06-26 02:48:02 +02009111/*
David Carlier845efb52015-09-25 11:49:18 +01009112 * free all config section entries
9113 */
9114void cfg_unregister_sections(void)
9115{
9116 struct cfg_section *cs, *ics;
9117
9118 list_for_each_entry_safe(cs, ics, &sections, list) {
9119 LIST_DEL(&cs->list);
9120 free(cs);
9121 }
9122}
9123
Christopher Faulet7110b402016-10-26 11:09:44 +02009124void cfg_backup_sections(struct list *backup_sections)
9125{
9126 struct cfg_section *cs, *ics;
9127
9128 list_for_each_entry_safe(cs, ics, &sections, list) {
9129 LIST_DEL(&cs->list);
9130 LIST_ADDQ(backup_sections, &cs->list);
9131 }
9132}
9133
9134void cfg_restore_sections(struct list *backup_sections)
9135{
9136 struct cfg_section *cs, *ics;
9137
9138 list_for_each_entry_safe(cs, ics, backup_sections, list) {
9139 LIST_DEL(&cs->list);
9140 LIST_ADDQ(&sections, &cs->list);
9141 }
9142}
9143
Willy Tarreau659fbf02016-05-26 17:55:28 +02009144__attribute__((constructor))
9145static void cfgparse_init(void)
9146{
9147 /* Register internal sections */
9148 cfg_register_section("listen", cfg_parse_listen);
9149 cfg_register_section("frontend", cfg_parse_listen);
9150 cfg_register_section("backend", cfg_parse_listen);
9151 cfg_register_section("defaults", cfg_parse_listen);
9152 cfg_register_section("global", cfg_parse_global);
9153 cfg_register_section("userlist", cfg_parse_users);
9154 cfg_register_section("peers", cfg_parse_peers);
9155 cfg_register_section("mailers", cfg_parse_mailers);
9156 cfg_register_section("namespace_list", cfg_parse_netns);
9157 cfg_register_section("resolvers", cfg_parse_resolvers);
9158}
9159
David Carlier845efb52015-09-25 11:49:18 +01009160/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02009161 * Local variables:
9162 * c-indent-level: 8
9163 * c-basic-offset: 8
9164 * End:
9165 */