Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 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é | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 13 | #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 Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 44 | #include <common/namespace.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
| 46 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 47 | #include <types/compression.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 48 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 49 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 50 | #include <types/peers.h> |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 51 | #include <types/mailers.h> |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 52 | #include <types/dns.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 54 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 55 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 57 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 59 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 60 | #include <proto/dumpstats.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 61 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 62 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 63 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 64 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 65 | #include <proto/lb_fwlc.h> |
| 66 | #include <proto/lb_fwrr.h> |
| 67 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 68 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 69 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 70 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 71 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 72 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 73 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 74 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 75 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 76 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 77 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 79 | #include <proto/stream.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 80 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 81 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 82 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 83 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 84 | #ifdef USE_OPENSSL |
| 85 | #include <types/ssl_sock.h> |
| 86 | #include <proto/ssl_sock.h> |
| 87 | #include <proto/shctx.h> |
| 88 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 89 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 90 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 91 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 92 | * |
| 93 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 94 | */ |
| 95 | const char sslv3_client_hello_pkt[] = { |
| 96 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 97 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 98 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 99 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 100 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 101 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 102 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 103 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 104 | "\x00" /* Session ID length : empty (no session ID) */ |
| 105 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 106 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 107 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 108 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 109 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 110 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 111 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 112 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 113 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 114 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 115 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 116 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 117 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 118 | }; |
| 119 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 120 | /* various keyword modifiers */ |
| 121 | enum kw_mod { |
| 122 | KWM_STD = 0, /* normal */ |
| 123 | KWM_NO, /* "no" prefixed before the keyword */ |
| 124 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 125 | }; |
| 126 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 127 | /* permit to store configuration section */ |
| 128 | struct cfg_section { |
| 129 | struct list list; |
| 130 | char *section_name; |
| 131 | int (*section_parser)(const char *, int, char **, int); |
| 132 | }; |
| 133 | |
| 134 | /* Used to chain configuration sections definitions. This list |
| 135 | * stores struct cfg_section |
| 136 | */ |
| 137 | struct list sections = LIST_HEAD_INIT(sections); |
| 138 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 139 | /* some of the most common options which are also the easiest to handle */ |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 140 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 141 | const char *name; |
| 142 | unsigned int val; |
| 143 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 144 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 145 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | /* proxy->options */ |
| 149 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 150 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 151 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 152 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 153 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 154 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 155 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 156 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 157 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 158 | { "http-buffer-request", PR_O_WREQ_BODY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 159 | { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 160 | { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 161 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 162 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 163 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 164 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 165 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 167 | #else |
| 168 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 169 | #endif |
| 170 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 171 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 172 | }; |
| 173 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 174 | /* proxy->options2 */ |
| 175 | static const struct cfg_opt cfg_opts2[] = |
| 176 | { |
| 177 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 178 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 179 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 180 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 181 | #else |
| 182 | { "splice-request", 0, 0, 0, 0 }, |
| 183 | { "splice-response", 0, 0, 0, 0 }, |
| 184 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 185 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 186 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 187 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 188 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 189 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 190 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 191 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 192 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 193 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 194 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 195 | { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 196 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 197 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 198 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 199 | { NULL, 0, 0, 0 } |
| 200 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 202 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 203 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 204 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 205 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 206 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 207 | /* List head of all known configuration keywords */ |
| 208 | static struct cfg_kw_list cfg_keywords = { |
| 209 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 210 | }; |
| 211 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 212 | /* |
| 213 | * converts <str> to a list of listeners which are dynamically allocated. |
| 214 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 215 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 216 | * - <port> is a numerical port from 1 to 65535 ; |
| 217 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 218 | * This can be repeated as many times as necessary, separated by a coma. |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 219 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 220 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 221 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 223 | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 224 | { |
| 225 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 226 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 227 | int port, end; |
| 228 | |
| 229 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 231 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 232 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 233 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 234 | |
| 235 | str = next; |
| 236 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 237 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | *next++ = 0; |
| 239 | } |
| 240 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 241 | ss2 = str2sa_range(str, &port, &end, err, |
| 242 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix); |
| 243 | if (!ss2) |
| 244 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 245 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 246 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 247 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 248 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 249 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 251 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 252 | if (!port || !end) { |
| 253 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 254 | goto fail; |
| 255 | } |
| 256 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 257 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 258 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 259 | goto fail; |
| 260 | } |
| 261 | |
| 262 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 263 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 264 | goto fail; |
| 265 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 267 | 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 Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 286 | /* OK the address looks correct */ |
| 287 | ss = *ss2; |
| 288 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 289 | for (; port <= end; port++) { |
| 290 | l = (struct listener *)calloc(1, sizeof(struct listener)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 291 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 292 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 293 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 294 | l->frontend = curproxy; |
| 295 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 296 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 297 | l->fd = fd; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 298 | l->addr = ss; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 299 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 300 | l->state = LI_INIT; |
| 301 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 302 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 303 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 304 | tcpv4_add_listener(l); |
| 305 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 306 | else if (ss.ss_family == AF_INET6) { |
| 307 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 308 | tcpv6_add_listener(l); |
| 309 | } |
| 310 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 311 | uxst_add_listener(l); |
| 312 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 313 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 314 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 315 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 316 | } /* end for(port) */ |
| 317 | } /* end while(next) */ |
| 318 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 319 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 320 | fail: |
| 321 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 322 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 323 | } |
| 324 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 325 | /* |
| 326 | * Report a fatal Alert when there is too much arguments |
| 327 | * The index is the current keyword in args |
| 328 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 329 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 330 | */ |
| 331 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 332 | { |
| 333 | char *kw = NULL; |
| 334 | int i; |
| 335 | |
| 336 | if (!*args[index + maxarg + 1]) |
| 337 | return 0; |
| 338 | |
| 339 | memprintf(&kw, "%s", args[0]); |
| 340 | for (i = 1; i <= index; i++) { |
| 341 | memprintf(&kw, "%s %s", kw, args[i]); |
| 342 | } |
| 343 | |
| 344 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 345 | free(kw); |
| 346 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 347 | return 1; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * same as alertif_too_many_args_idx with a 0 index |
| 352 | */ |
| 353 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 354 | { |
| 355 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 356 | } |
| 357 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 358 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 359 | * Return 1 if the warning has been emitted, otherwise 0. |
| 360 | */ |
| 361 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 362 | { |
| 363 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 364 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 365 | file, line, arg); |
| 366 | return 1; |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 371 | /* Report a warning if a rule is placed after a 'block' rule. |
| 372 | * Return 1 if the warning has been emitted, otherwise 0. |
| 373 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 374 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 375 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 376 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 377 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 378 | file, line, arg); |
| 379 | return 1; |
| 380 | } |
| 381 | return 0; |
| 382 | } |
| 383 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 384 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 385 | * Return 1 if the warning has been emitted, otherwise 0. |
| 386 | */ |
| 387 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 388 | { |
| 389 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 390 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 391 | file, line, arg); |
| 392 | return 1; |
| 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 397 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 398 | * Return 1 if the warning has been emitted, otherwise 0. |
| 399 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 400 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 401 | { |
| 402 | if (proxy->req_exp) { |
| 403 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 404 | file, line, arg); |
| 405 | return 1; |
| 406 | } |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /* Report a warning if a rule is placed after a reqadd rule. |
| 411 | * Return 1 if the warning has been emitted, otherwise 0. |
| 412 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 413 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 414 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 415 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 416 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 417 | file, line, arg); |
| 418 | return 1; |
| 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* Report a warning if a rule is placed after a redirect rule. |
| 424 | * Return 1 if the warning has been emitted, otherwise 0. |
| 425 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 426 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 427 | { |
| 428 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 429 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 430 | file, line, arg); |
| 431 | return 1; |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 437 | * Return 1 if the warning has been emitted, otherwise 0. |
| 438 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 439 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 440 | { |
| 441 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 442 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 443 | file, line, arg); |
| 444 | return 1; |
| 445 | } |
| 446 | return 0; |
| 447 | } |
| 448 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 449 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 450 | * Return 1 if the warning has been emitted, otherwise 0. |
| 451 | */ |
| 452 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 453 | { |
| 454 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 455 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 456 | file, line, arg); |
| 457 | return 1; |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 462 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 463 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 464 | { |
| 465 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 466 | warnif_rule_after_block(proxy, file, line, arg) || |
| 467 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 468 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 469 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 470 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 471 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 472 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 473 | } |
| 474 | |
| 475 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 476 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 477 | { |
| 478 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 479 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 480 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 481 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 482 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 483 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 484 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 485 | } |
| 486 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 487 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 488 | int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 489 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 490 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 491 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 492 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 493 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 494 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 495 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* report a warning if an http-request rule is dangerously placed */ |
| 499 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 500 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 501 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 502 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 503 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 504 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 505 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 509 | int warnif_misplaced_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 510 | { |
| 511 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 512 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 513 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 514 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 518 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 519 | { |
| 520 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 521 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 522 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 523 | } |
| 524 | |
| 525 | /* report a warning if a redirect rule is dangerously placed */ |
| 526 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 527 | { |
| 528 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 529 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 532 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 533 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 534 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 535 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 536 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 537 | static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 538 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 539 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 540 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 541 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 542 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 543 | return 0; |
| 544 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 545 | acl = acl_cond_conflicts(cond, where); |
| 546 | if (acl) { |
| 547 | if (acl->name && *acl->name) |
| 548 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 549 | file, line, acl->name, sample_ckp_names(where)); |
| 550 | else |
| 551 | Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 552 | file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 553 | return ERR_WARN; |
| 554 | } |
| 555 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 556 | return 0; |
| 557 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 558 | if (acl->name && *acl->name) |
| 559 | Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 560 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 561 | else |
| 562 | Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 563 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 564 | return ERR_WARN; |
| 565 | } |
| 566 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 567 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 568 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 569 | * any combination of : |
| 570 | * - ERR_ABORT: must abort ASAP |
| 571 | * - ERR_FATAL: we can continue parsing but not start the service |
| 572 | * - ERR_WARN: a warning has been emitted |
| 573 | * - ERR_ALERT: an alert has been emitted |
| 574 | * Only the two first ones can stop processing, the two others are just |
| 575 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 576 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 577 | int cfg_parse_global(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 578 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 579 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 580 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 581 | |
| 582 | if (!strcmp(args[0], "global")) { /* new section */ |
| 583 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 584 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 585 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 586 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 587 | else if (!strcmp(args[0], "ca-base")) { |
| 588 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 589 | if(alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 590 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 591 | if (global.ca_base != NULL) { |
| 592 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 593 | err_code |= ERR_ALERT; |
| 594 | goto out; |
| 595 | } |
| 596 | if (*(args[1]) == 0) { |
| 597 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 599 | goto out; |
| 600 | } |
| 601 | global.ca_base = strdup(args[1]); |
| 602 | #else |
| 603 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 605 | goto out; |
| 606 | #endif |
| 607 | } |
| 608 | else if (!strcmp(args[0], "crt-base")) { |
| 609 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 610 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 611 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 612 | if (global.crt_base != NULL) { |
| 613 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 614 | err_code |= ERR_ALERT; |
| 615 | goto out; |
| 616 | } |
| 617 | if (*(args[1]) == 0) { |
| 618 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 620 | goto out; |
| 621 | } |
| 622 | global.crt_base = strdup(args[1]); |
| 623 | #else |
| 624 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 626 | goto out; |
| 627 | #endif |
| 628 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 629 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 630 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 631 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 632 | global.mode |= MODE_DAEMON; |
| 633 | } |
| 634 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 635 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 636 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 637 | global.mode |= MODE_DEBUG; |
| 638 | } |
| 639 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 640 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 641 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 642 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 643 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 644 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 645 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 646 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 647 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 648 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 649 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 650 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 651 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 652 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 653 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 654 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 655 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 656 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 657 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 658 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 659 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 660 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 661 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 662 | global.tune.options &= ~GTUNE_USE_GAI; |
| 663 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 664 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 665 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 666 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 667 | global.mode |= MODE_QUIET; |
| 668 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 669 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 670 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 671 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 672 | if (global.tune.maxpollevents != 0) { |
| 673 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 674 | err_code |= ERR_ALERT; |
| 675 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 676 | } |
| 677 | if (*(args[1]) == 0) { |
| 678 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 680 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 681 | } |
| 682 | global.tune.maxpollevents = atol(args[1]); |
| 683 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 684 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 685 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 686 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 687 | if (global.tune.maxaccept != 0) { |
| 688 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 689 | err_code |= ERR_ALERT; |
| 690 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 691 | } |
| 692 | if (*(args[1]) == 0) { |
| 693 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 695 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 696 | } |
| 697 | global.tune.maxaccept = atol(args[1]); |
| 698 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 699 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 700 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 701 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 702 | if (*(args[1]) == 0) { |
| 703 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 705 | goto out; |
| 706 | } |
| 707 | global.tune.chksize = atol(args[1]); |
| 708 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 709 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 710 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 711 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 712 | goto out; |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 713 | global.tune.sslprivatecache = 1; |
| 714 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 715 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 716 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 717 | goto out; |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 718 | if (*(args[1]) == 0) { |
| 719 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 721 | goto out; |
| 722 | } |
| 723 | global.tune.sslcachesize = atol(args[1]); |
| 724 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 725 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 726 | unsigned int ssllifetime; |
| 727 | const char *res; |
| 728 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 729 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 730 | goto out; |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 731 | if (*(args[1]) == 0) { |
| 732 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 734 | goto out; |
| 735 | } |
| 736 | |
| 737 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 738 | if (res) { |
| 739 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 740 | file, linenum, *res, args[0]); |
| 741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 742 | goto out; |
| 743 | } |
| 744 | |
| 745 | global.tune.ssllifetime = ssllifetime; |
| 746 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 747 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 748 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 749 | goto out; |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 750 | 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.ssl_max_record = atol(args[1]); |
| 756 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 757 | #ifndef OPENSSL_NO_DH |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 758 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 759 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 760 | goto out; |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 761 | if (*(args[1]) == 0) { |
| 762 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 764 | goto out; |
| 765 | } |
| 766 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 767 | if (global.tune.ssl_default_dh_param < 1024) { |
| 768 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 770 | goto out; |
| 771 | } |
| 772 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 773 | #endif |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 774 | else if (!strcmp(args[0], "tune.ssl.ssl-ctx-cache-size")) { |
| 775 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 776 | goto out; |
| 777 | if (*(args[1]) == 0) { |
| 778 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 780 | goto out; |
| 781 | } |
| 782 | global.tune.ssl_ctx_cache = atoi(args[1]); |
| 783 | if (global.tune.ssl_ctx_cache < 0) { |
| 784 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 785 | file, linenum, args[0]); |
| 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | goto out; |
| 788 | } |
| 789 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 790 | #endif |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 791 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 792 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 793 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 794 | if (*(args[1]) == 0) { |
| 795 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 797 | goto out; |
| 798 | } |
| 799 | global.tune.buf_limit = atol(args[1]); |
| 800 | if (global.tune.buf_limit) { |
| 801 | if (global.tune.buf_limit < 3) |
| 802 | global.tune.buf_limit = 3; |
| 803 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 804 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 805 | } |
| 806 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 807 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 808 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 809 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 810 | if (*(args[1]) == 0) { |
| 811 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 813 | goto out; |
| 814 | } |
| 815 | global.tune.reserved_bufs = atol(args[1]); |
| 816 | if (global.tune.reserved_bufs < 2) |
| 817 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 818 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 819 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 820 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 821 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 822 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 823 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 824 | if (*(args[1]) == 0) { |
| 825 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 827 | goto out; |
| 828 | } |
| 829 | global.tune.bufsize = atol(args[1]); |
| 830 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 831 | global.tune.maxrewrite = global.tune.bufsize / 2; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 832 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 833 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 834 | } |
| 835 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 836 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 837 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 838 | if (*(args[1]) == 0) { |
| 839 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 841 | goto out; |
| 842 | } |
| 843 | global.tune.maxrewrite = atol(args[1]); |
| 844 | if (global.tune.maxrewrite >= global.tune.bufsize / 2) |
| 845 | global.tune.maxrewrite = global.tune.bufsize / 2; |
| 846 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 847 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 848 | unsigned int idle; |
| 849 | const char *res; |
| 850 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 851 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 852 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 853 | if (*(args[1]) == 0) { |
| 854 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 856 | goto out; |
| 857 | } |
| 858 | |
| 859 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 860 | if (res) { |
| 861 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 862 | file, linenum, *res, args[0]); |
| 863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 864 | goto out; |
| 865 | } |
| 866 | |
| 867 | if (idle > 65535) { |
| 868 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 870 | goto out; |
| 871 | } |
| 872 | global.tune.idle_timer = idle; |
| 873 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 874 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 875 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 876 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 877 | if (global.tune.client_rcvbuf != 0) { |
| 878 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 879 | err_code |= ERR_ALERT; |
| 880 | goto out; |
| 881 | } |
| 882 | if (*(args[1]) == 0) { |
| 883 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 884 | err_code |= ERR_ALERT | ERR_FATAL; |
| 885 | goto out; |
| 886 | } |
| 887 | global.tune.client_rcvbuf = atol(args[1]); |
| 888 | } |
| 889 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 890 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 891 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 892 | if (global.tune.server_rcvbuf != 0) { |
| 893 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 894 | err_code |= ERR_ALERT; |
| 895 | goto out; |
| 896 | } |
| 897 | if (*(args[1]) == 0) { |
| 898 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 900 | goto out; |
| 901 | } |
| 902 | global.tune.server_rcvbuf = atol(args[1]); |
| 903 | } |
| 904 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 905 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 906 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 907 | if (global.tune.client_sndbuf != 0) { |
| 908 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 909 | err_code |= ERR_ALERT; |
| 910 | goto out; |
| 911 | } |
| 912 | if (*(args[1]) == 0) { |
| 913 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
| 917 | global.tune.client_sndbuf = atol(args[1]); |
| 918 | } |
| 919 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 920 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 921 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 922 | if (global.tune.server_sndbuf != 0) { |
| 923 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 924 | err_code |= ERR_ALERT; |
| 925 | goto out; |
| 926 | } |
| 927 | if (*(args[1]) == 0) { |
| 928 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 930 | goto out; |
| 931 | } |
| 932 | global.tune.server_sndbuf = atol(args[1]); |
| 933 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 934 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 935 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 936 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 937 | if (*(args[1]) == 0) { |
| 938 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 940 | goto out; |
| 941 | } |
| 942 | global.tune.pipesize = atol(args[1]); |
| 943 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 944 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 945 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 946 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 947 | if (*(args[1]) == 0) { |
| 948 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 950 | goto out; |
| 951 | } |
| 952 | global.tune.cookie_len = atol(args[1]) + 1; |
| 953 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 954 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 955 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 956 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 957 | if (*(args[1]) == 0) { |
| 958 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 959 | err_code |= ERR_ALERT | ERR_FATAL; |
| 960 | goto out; |
| 961 | } |
| 962 | global.tune.max_http_hdr = atol(args[1]); |
| 963 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 964 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 965 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 966 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 967 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 968 | if (*args[1]) { |
| 969 | global.tune.zlibmemlevel = atoi(args[1]); |
| 970 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 971 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 972 | file, linenum, args[0]); |
| 973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 974 | goto out; |
| 975 | } |
| 976 | } else { |
| 977 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 978 | file, linenum, args[0]); |
| 979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 980 | goto out; |
| 981 | } |
| 982 | #else |
| 983 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 985 | goto out; |
| 986 | #endif |
| 987 | } |
| 988 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 989 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 990 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 991 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 992 | if (*args[1]) { |
| 993 | global.tune.zlibwindowsize = atoi(args[1]); |
| 994 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 995 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 996 | file, linenum, args[0]); |
| 997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 998 | goto out; |
| 999 | } |
| 1000 | } else { |
| 1001 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1002 | file, linenum, args[0]); |
| 1003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1004 | goto out; |
| 1005 | } |
| 1006 | #else |
| 1007 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto out; |
| 1010 | #endif |
| 1011 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1012 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1013 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1014 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1015 | if (*args[1]) { |
| 1016 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1017 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 1018 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1019 | file, linenum, args[0]); |
| 1020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1021 | goto out; |
| 1022 | } |
| 1023 | } else { |
| 1024 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1025 | file, linenum, args[0]); |
| 1026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1027 | goto out; |
| 1028 | } |
| 1029 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1030 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1031 | if (*args[1]) { |
| 1032 | global.tune.pattern_cache = atoi(args[1]); |
| 1033 | if (global.tune.pattern_cache < 0) { |
| 1034 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1035 | file, linenum, args[0]); |
| 1036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1037 | goto out; |
| 1038 | } |
| 1039 | } else { |
| 1040 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1041 | file, linenum, args[0]); |
| 1042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1043 | goto out; |
| 1044 | } |
| 1045 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1046 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1047 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1048 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1049 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1050 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1051 | err_code |= ERR_ALERT; |
| 1052 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1053 | } |
| 1054 | if (*(args[1]) == 0) { |
| 1055 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1057 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1058 | } |
| 1059 | global.uid = atol(args[1]); |
| 1060 | } |
| 1061 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1062 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1063 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1064 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1065 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1066 | err_code |= ERR_ALERT; |
| 1067 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1068 | } |
| 1069 | if (*(args[1]) == 0) { |
| 1070 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1073 | } |
| 1074 | global.gid = atol(args[1]); |
| 1075 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1076 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1077 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1078 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1079 | global.external_check = 1; |
| 1080 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1081 | /* user/group name handling */ |
| 1082 | else if (!strcmp(args[0], "user")) { |
| 1083 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1084 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1085 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1086 | if (global.uid != 0) { |
| 1087 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1088 | err_code |= ERR_ALERT; |
| 1089 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1090 | } |
| 1091 | errno = 0; |
| 1092 | ha_user = getpwnam(args[1]); |
| 1093 | if (ha_user != NULL) { |
| 1094 | global.uid = (int)ha_user->pw_uid; |
| 1095 | } |
| 1096 | else { |
| 1097 | Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1098 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | else if (!strcmp(args[0], "group")) { |
| 1102 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1103 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1104 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1105 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1106 | Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1107 | err_code |= ERR_ALERT; |
| 1108 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1109 | } |
| 1110 | errno = 0; |
| 1111 | ha_group = getgrnam(args[1]); |
| 1112 | if (ha_group != NULL) { |
| 1113 | global.gid = (int)ha_group->gr_gid; |
| 1114 | } |
| 1115 | else { |
| 1116 | Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1117 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1121 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1122 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1124 | if (*(args[1]) == 0) { |
| 1125 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1128 | } |
| 1129 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1130 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1131 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1132 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1134 | goto out; |
| 1135 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1136 | } |
| 1137 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1138 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1139 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1140 | if (global.maxconn != 0) { |
| 1141 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1142 | err_code |= ERR_ALERT; |
| 1143 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1144 | } |
| 1145 | if (*(args[1]) == 0) { |
| 1146 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1148 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1149 | } |
| 1150 | global.maxconn = atol(args[1]); |
| 1151 | #ifdef SYSTEM_MAXCONN |
| 1152 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1153 | 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); |
| 1154 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1155 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1156 | } |
| 1157 | #endif /* SYSTEM_MAXCONN */ |
| 1158 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1159 | else if (!strcmp(args[0], "maxsslconn")) { |
| 1160 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1161 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1162 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1163 | if (*(args[1]) == 0) { |
| 1164 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1166 | goto out; |
| 1167 | } |
| 1168 | global.maxsslconn = atol(args[1]); |
| 1169 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1170 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1172 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1173 | #endif |
| 1174 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1175 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 1176 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1177 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1178 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1179 | if (*(args[1]) == 0) { |
| 1180 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1182 | goto out; |
| 1183 | } |
| 1184 | free(global.listen_default_ciphers); |
| 1185 | global.listen_default_ciphers = strdup(args[1]); |
| 1186 | #else |
| 1187 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1189 | goto out; |
| 1190 | #endif |
| 1191 | } |
| 1192 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1193 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1194 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1195 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1196 | if (*(args[1]) == 0) { |
| 1197 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1199 | goto out; |
| 1200 | } |
| 1201 | free(global.connect_default_ciphers); |
| 1202 | global.connect_default_ciphers = strdup(args[1]); |
| 1203 | #else |
| 1204 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1206 | goto out; |
| 1207 | #endif |
| 1208 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 1209 | #ifdef USE_OPENSSL |
| 1210 | #ifndef OPENSSL_NO_DH |
| 1211 | else if (!strcmp(args[0], "ssl-dh-param-file")) { |
| 1212 | if (*(args[1]) == 0) { |
| 1213 | Alert("parsing [%s:%d] : '%s' expects a file path as an argument.\n", file, linenum, args[0]); |
| 1214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1215 | goto out; |
| 1216 | } |
| 1217 | if (ssl_sock_load_global_dh_param_from_file(args[1])) { |
| 1218 | Alert("parsing [%s:%d] : '%s': unable to load DH parameters from file <%s>.\n", file, linenum, args[0], args[1]); |
| 1219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1220 | goto out; |
| 1221 | } |
| 1222 | } |
| 1223 | #endif |
| 1224 | #endif |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1225 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1226 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1227 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1228 | if (*(args[1]) == 0) { |
| 1229 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1231 | goto out; |
| 1232 | } |
| 1233 | if (strcmp(args[1],"none") == 0) |
| 1234 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1235 | else if (strcmp(args[1],"required") == 0) |
| 1236 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1237 | else { |
| 1238 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1240 | goto out; |
| 1241 | } |
| 1242 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1243 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1244 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1245 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1246 | if (global.cps_lim != 0) { |
| 1247 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1248 | err_code |= ERR_ALERT; |
| 1249 | goto out; |
| 1250 | } |
| 1251 | if (*(args[1]) == 0) { |
| 1252 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1254 | goto out; |
| 1255 | } |
| 1256 | global.cps_lim = atol(args[1]); |
| 1257 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1258 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1259 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1260 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1261 | if (global.sps_lim != 0) { |
| 1262 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1263 | err_code |= ERR_ALERT; |
| 1264 | goto out; |
| 1265 | } |
| 1266 | if (*(args[1]) == 0) { |
| 1267 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1269 | goto out; |
| 1270 | } |
| 1271 | global.sps_lim = atol(args[1]); |
| 1272 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1273 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1274 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1275 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1276 | if (global.ssl_lim != 0) { |
| 1277 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1278 | err_code |= ERR_ALERT; |
| 1279 | goto out; |
| 1280 | } |
| 1281 | if (*(args[1]) == 0) { |
| 1282 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1284 | goto out; |
| 1285 | } |
| 1286 | global.ssl_lim = atol(args[1]); |
| 1287 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1288 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1289 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1290 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1291 | if (*(args[1]) == 0) { |
| 1292 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1294 | goto out; |
| 1295 | } |
| 1296 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1297 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1298 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1299 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1300 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1301 | if (global.maxpipes != 0) { |
| 1302 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1303 | err_code |= ERR_ALERT; |
| 1304 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1305 | } |
| 1306 | if (*(args[1]) == 0) { |
| 1307 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1309 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1310 | } |
| 1311 | global.maxpipes = atol(args[1]); |
| 1312 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1313 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1314 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1315 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1316 | if (*(args[1]) == 0) { |
| 1317 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1319 | goto out; |
| 1320 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1321 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1322 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1323 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1324 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1325 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1326 | if (*(args[1]) == 0) { |
| 1327 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1332 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1333 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1335 | goto out; |
| 1336 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1337 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1338 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1339 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1340 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1341 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1342 | if (global.rlimit_nofile != 0) { |
| 1343 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1344 | err_code |= ERR_ALERT; |
| 1345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1346 | } |
| 1347 | if (*(args[1]) == 0) { |
| 1348 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1350 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1351 | } |
| 1352 | global.rlimit_nofile = atol(args[1]); |
| 1353 | } |
| 1354 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1355 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1356 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1357 | if (global.chroot != NULL) { |
| 1358 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1359 | err_code |= ERR_ALERT; |
| 1360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1361 | } |
| 1362 | if (*(args[1]) == 0) { |
| 1363 | Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1364 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1365 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1366 | } |
| 1367 | global.chroot = strdup(args[1]); |
| 1368 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1369 | else if (!strcmp(args[0], "description")) { |
| 1370 | int i, len=0; |
| 1371 | char *d; |
| 1372 | |
| 1373 | if (!*args[1]) { |
| 1374 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1375 | file, linenum, args[0]); |
| 1376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1377 | goto out; |
| 1378 | } |
| 1379 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1380 | for (i = 1; *args[i]; i++) |
| 1381 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1382 | |
| 1383 | if (global.desc) |
| 1384 | free(global.desc); |
| 1385 | |
| 1386 | global.desc = d = (char *)calloc(1, len); |
| 1387 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1388 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1389 | for (i = 2; *args[i]; i++) |
| 1390 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1391 | } |
| 1392 | else if (!strcmp(args[0], "node")) { |
| 1393 | int i; |
| 1394 | char c; |
| 1395 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1396 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1397 | goto out; |
| 1398 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1399 | for (i=0; args[1][i]; i++) { |
| 1400 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1401 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1402 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | if (!i || args[1][i]) { |
| 1407 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1408 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1409 | file, linenum, args[0]); |
| 1410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1411 | goto out; |
| 1412 | } |
| 1413 | |
| 1414 | if (global.node) |
| 1415 | free(global.node); |
| 1416 | |
| 1417 | global.node = strdup(args[1]); |
| 1418 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1419 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1420 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1421 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1422 | if (global.pidfile != NULL) { |
| 1423 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1424 | err_code |= ERR_ALERT; |
| 1425 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1426 | } |
| 1427 | if (*(args[1]) == 0) { |
| 1428 | Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1431 | } |
| 1432 | global.pidfile = strdup(args[1]); |
| 1433 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1434 | else if (!strcmp(args[0], "unix-bind")) { |
| 1435 | int cur_arg = 1; |
| 1436 | while (*(args[cur_arg])) { |
| 1437 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1438 | if (global.unix_bind.prefix != NULL) { |
| 1439 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1440 | err_code |= ERR_ALERT; |
| 1441 | cur_arg += 2; |
| 1442 | continue; |
| 1443 | } |
| 1444 | |
| 1445 | if (*(args[cur_arg+1]) == 0) { |
| 1446 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1448 | goto out; |
| 1449 | } |
| 1450 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1451 | cur_arg += 2; |
| 1452 | continue; |
| 1453 | } |
| 1454 | |
| 1455 | if (!strcmp(args[cur_arg], "mode")) { |
| 1456 | |
| 1457 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1458 | cur_arg += 2; |
| 1459 | continue; |
| 1460 | } |
| 1461 | |
| 1462 | if (!strcmp(args[cur_arg], "uid")) { |
| 1463 | |
| 1464 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1465 | cur_arg += 2; |
| 1466 | continue; |
| 1467 | } |
| 1468 | |
| 1469 | if (!strcmp(args[cur_arg], "gid")) { |
| 1470 | |
| 1471 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1472 | cur_arg += 2; |
| 1473 | continue; |
| 1474 | } |
| 1475 | |
| 1476 | if (!strcmp(args[cur_arg], "user")) { |
| 1477 | struct passwd *user; |
| 1478 | |
| 1479 | user = getpwnam(args[cur_arg + 1]); |
| 1480 | if (!user) { |
| 1481 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1482 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1484 | goto out; |
| 1485 | } |
| 1486 | |
| 1487 | global.unix_bind.ux.uid = user->pw_uid; |
| 1488 | cur_arg += 2; |
| 1489 | continue; |
| 1490 | } |
| 1491 | |
| 1492 | if (!strcmp(args[cur_arg], "group")) { |
| 1493 | struct group *group; |
| 1494 | |
| 1495 | group = getgrnam(args[cur_arg + 1]); |
| 1496 | if (!group) { |
| 1497 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1498 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1500 | goto out; |
| 1501 | } |
| 1502 | |
| 1503 | global.unix_bind.ux.gid = group->gr_gid; |
| 1504 | cur_arg += 2; |
| 1505 | continue; |
| 1506 | } |
| 1507 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1508 | Alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1509 | file, linenum, args[0]); |
| 1510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1511 | goto out; |
| 1512 | } |
| 1513 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1514 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1515 | /* delete previous herited or defined syslog servers */ |
| 1516 | struct logsrv *back; |
| 1517 | struct logsrv *tmp; |
| 1518 | |
| 1519 | if (*(args[1]) != 0) { |
| 1520 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
| 1525 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1526 | LIST_DEL(&tmp->list); |
| 1527 | free(tmp); |
| 1528 | } |
| 1529 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1530 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1531 | struct sockaddr_storage *sk; |
| 1532 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1533 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1534 | int arg = 0; |
| 1535 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1536 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1537 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1538 | goto out; |
| 1539 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1540 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1541 | Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1544 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1545 | |
| 1546 | logsrv = calloc(1, sizeof(struct logsrv)); |
| 1547 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1548 | /* just after the address, a length may be specified */ |
| 1549 | if (strcmp(args[arg+2], "len") == 0) { |
| 1550 | len = atoi(args[arg+3]); |
| 1551 | if (len < 80 || len > 65535) { |
| 1552 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1553 | file, linenum, args[arg+3]); |
| 1554 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1555 | goto out; |
| 1556 | } |
| 1557 | logsrv->maxlen = len; |
| 1558 | |
| 1559 | /* skip these two args */ |
| 1560 | arg += 2; |
| 1561 | } |
| 1562 | else |
| 1563 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1564 | |
| 1565 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1566 | global.max_syslog_len = logsrv->maxlen; |
| 1567 | logline = realloc(logline, global.max_syslog_len + 1); |
| 1568 | } |
| 1569 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1570 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 1571 | goto out; |
| 1572 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1573 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1574 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1575 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1576 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1577 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1578 | } |
| 1579 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1580 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1581 | if (*(args[arg+3])) { |
| 1582 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1583 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1584 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1586 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1590 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1591 | if (*(args[arg+4])) { |
| 1592 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1593 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1594 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1595 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1596 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1600 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1601 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1602 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1603 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1604 | free(logsrv); |
| 1605 | goto out; |
| 1606 | } |
| 1607 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1608 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1609 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1610 | if (port1 != port2) { |
| 1611 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1612 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1613 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1614 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1615 | goto out; |
| 1616 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1617 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1618 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1619 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1620 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1621 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1622 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1623 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1624 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1625 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1626 | char *name; |
| 1627 | int len; |
| 1628 | |
| 1629 | if (global.log_send_hostname != NULL) { |
| 1630 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1631 | err_code |= ERR_ALERT; |
| 1632 | goto out; |
| 1633 | } |
| 1634 | |
| 1635 | if (*(args[1])) |
| 1636 | name = args[1]; |
| 1637 | else |
| 1638 | name = hostname; |
| 1639 | |
| 1640 | len = strlen(name); |
| 1641 | |
| 1642 | /* We'll add a space after the name to respect the log format */ |
| 1643 | free(global.log_send_hostname); |
| 1644 | global.log_send_hostname = malloc(len + 2); |
| 1645 | snprintf(global.log_send_hostname, len + 2, "%s ", name); |
| 1646 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1647 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1648 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1649 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1650 | if (*(args[1]) == 0) { |
| 1651 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1653 | goto out; |
| 1654 | } |
| 1655 | free(global.log_tag); |
| 1656 | global.log_tag = strdup(args[1]); |
| 1657 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1658 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1659 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1660 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1661 | if (global.spread_checks != 0) { |
| 1662 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1663 | err_code |= ERR_ALERT; |
| 1664 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1665 | } |
| 1666 | if (*(args[1]) == 0) { |
| 1667 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1669 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1670 | } |
| 1671 | global.spread_checks = atol(args[1]); |
| 1672 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1673 | Alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1674 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1675 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1676 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1677 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1678 | const char *err; |
| 1679 | unsigned int val; |
| 1680 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1681 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1682 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1683 | if (*(args[1]) == 0) { |
| 1684 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1686 | goto out; |
| 1687 | } |
| 1688 | |
| 1689 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1690 | if (err) { |
| 1691 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1693 | } |
| 1694 | global.max_spread_checks = val; |
| 1695 | if (global.max_spread_checks < 0) { |
| 1696 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1698 | } |
| 1699 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1700 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1701 | #ifdef USE_CPU_AFFINITY |
| 1702 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1703 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1704 | unsigned long cpus = 0; |
| 1705 | |
| 1706 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1707 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1708 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1709 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1710 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1711 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1712 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1713 | proc = atol(args[1]); |
| 1714 | if (proc >= 1 && proc <= LONGBITS) |
| 1715 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1719 | 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", |
| 1720 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1722 | goto out; |
| 1723 | } |
| 1724 | |
| 1725 | cur_arg = 2; |
| 1726 | while (*args[cur_arg]) { |
| 1727 | unsigned int low, high; |
| 1728 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1729 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1730 | char *dash = strchr(args[cur_arg], '-'); |
| 1731 | |
| 1732 | low = high = str2uic(args[cur_arg]); |
| 1733 | if (dash) |
| 1734 | high = str2uic(dash + 1); |
| 1735 | |
| 1736 | if (high < low) { |
| 1737 | unsigned int swap = low; |
| 1738 | low = high; |
| 1739 | high = swap; |
| 1740 | } |
| 1741 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1742 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1743 | Alert("parsing [%s:%d]: %s supports CPU numbers from 0 to %d.\n", |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1744 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1746 | goto out; |
| 1747 | } |
| 1748 | |
| 1749 | while (low <= high) |
| 1750 | cpus |= 1UL << low++; |
| 1751 | } |
| 1752 | else { |
| 1753 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1754 | file, linenum, args[0], args[cur_arg]); |
| 1755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1756 | goto out; |
| 1757 | } |
| 1758 | cur_arg++; |
| 1759 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1760 | for (i = 0; i < LONGBITS; i++) |
| 1761 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1762 | global.cpu_map[i] = cpus; |
| 1763 | #else |
| 1764 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1766 | goto out; |
| 1767 | #endif |
| 1768 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1769 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1770 | struct cfg_kw_list *kwl; |
| 1771 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1772 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1773 | |
| 1774 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1775 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1776 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1777 | continue; |
| 1778 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1779 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1780 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1781 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1782 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1783 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1784 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1785 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1786 | err_code |= ERR_WARN; |
| 1787 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1788 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1789 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1794 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1796 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1797 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1798 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1799 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1800 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1801 | } |
| 1802 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1803 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1804 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1805 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1806 | defproxy.mode = PR_MODE_TCP; |
| 1807 | defproxy.state = PR_STNEW; |
| 1808 | defproxy.maxconn = cfg_maxpconn; |
| 1809 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1810 | defproxy.redispatch_after = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1811 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1812 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1813 | defproxy.defsrv.check.fastinter = 0; |
| 1814 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1815 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1816 | defproxy.defsrv.agent.fastinter = 0; |
| 1817 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1818 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1819 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1820 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1821 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1822 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1823 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1824 | defproxy.defsrv.maxqueue = 0; |
| 1825 | defproxy.defsrv.minconn = 0; |
| 1826 | defproxy.defsrv.maxconn = 0; |
| 1827 | defproxy.defsrv.slowstart = 0; |
| 1828 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1829 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1830 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1831 | |
| 1832 | defproxy.email_alert.level = LOG_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1833 | } |
| 1834 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1835 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1836 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1837 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1838 | * ERR_FATAL in case of error. |
| 1839 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1840 | static int create_cond_regex_rule(const char *file, int line, |
| 1841 | struct proxy *px, int dir, int action, int flags, |
| 1842 | const char *cmd, const char *reg, const char *repl, |
| 1843 | const char **cond_start) |
| 1844 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1845 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1846 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1847 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1848 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1849 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1850 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1851 | int cs; |
| 1852 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1853 | |
| 1854 | if (px == &defproxy) { |
| 1855 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1856 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1857 | goto err; |
| 1858 | } |
| 1859 | |
| 1860 | if (*reg == 0) { |
| 1861 | Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1862 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1863 | goto err; |
| 1864 | } |
| 1865 | |
| 1866 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1867 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1868 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1869 | if (cond_start && |
| 1870 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1871 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1872 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1873 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1874 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1875 | goto err; |
| 1876 | } |
| 1877 | } |
| 1878 | else if (cond_start && **cond_start) { |
| 1879 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1880 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1881 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1882 | goto err; |
| 1883 | } |
| 1884 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1885 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1886 | (dir == SMP_OPT_DIR_REQ) ? |
| 1887 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1888 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1889 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1890 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1891 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1892 | if (!preg) { |
| 1893 | Alert("parsing [%s:%d] : '%s' : not enough memory to build regex.\n", file, line, cmd); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1894 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1895 | goto err; |
| 1896 | } |
| 1897 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1898 | cs = !(flags & REG_ICASE); |
| 1899 | cap = !(flags & REG_NOSUB); |
| 1900 | error = NULL; |
| 1901 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1902 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1903 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1904 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1905 | goto err; |
| 1906 | } |
| 1907 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1908 | err = chain_regex((dir == SMP_OPT_DIR_REQ) ? &px->req_exp : &px->rsp_exp, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1909 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1910 | if (repl && err) { |
| 1911 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1912 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1913 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1914 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1917 | if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1918 | ret_code |= ERR_WARN; |
| 1919 | |
| 1920 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1921 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1922 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1923 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1924 | err: |
| 1925 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1926 | free(errmsg); |
| 1927 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1930 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1931 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1932 | * Returns the error code, 0 if OK, or any combination of : |
| 1933 | * - ERR_ABORT: must abort ASAP |
| 1934 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1935 | * - ERR_WARN: a warning has been emitted |
| 1936 | * - ERR_ALERT: an alert has been emitted |
| 1937 | * Only the two first ones can stop processing, the two others are just |
| 1938 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1939 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1940 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1941 | { |
| 1942 | static struct peers *curpeers = NULL; |
| 1943 | struct peer *newpeer = NULL; |
| 1944 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1945 | struct bind_conf *bind_conf; |
| 1946 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1947 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1948 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1949 | |
| 1950 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1951 | if (!*args[1]) { |
| 1952 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1953 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1954 | goto out; |
| 1955 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1956 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1957 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1958 | goto out; |
| 1959 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1960 | err = invalid_char(args[1]); |
| 1961 | if (err) { |
| 1962 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1963 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1964 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1965 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1969 | /* |
| 1970 | * If there are two proxies with the same name only following |
| 1971 | * combinations are allowed: |
| 1972 | */ |
| 1973 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1974 | Alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1975 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1976 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | if ((curpeers = (struct peers *)calloc(1, sizeof(struct peers))) == NULL) { |
| 1981 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1982 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1983 | goto out; |
| 1984 | } |
| 1985 | |
| 1986 | curpeers->next = peers; |
| 1987 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1988 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1989 | curpeers->conf.line = linenum; |
| 1990 | curpeers->last_change = now.tv_sec; |
| 1991 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1992 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1993 | } |
| 1994 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1995 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1996 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1997 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1998 | |
| 1999 | if (!*args[2]) { |
| 2000 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2001 | file, linenum, args[0]); |
| 2002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2003 | goto out; |
| 2004 | } |
| 2005 | |
| 2006 | err = invalid_char(args[1]); |
| 2007 | if (err) { |
| 2008 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2009 | file, linenum, *err, args[1]); |
| 2010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2011 | goto out; |
| 2012 | } |
| 2013 | |
| 2014 | if ((newpeer = (struct peer *)calloc(1, sizeof(struct peer))) == NULL) { |
| 2015 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2016 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2017 | goto out; |
| 2018 | } |
| 2019 | |
| 2020 | /* the peers are linked backwards first */ |
| 2021 | curpeers->count++; |
| 2022 | newpeer->next = curpeers->remote; |
| 2023 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2024 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2025 | newpeer->conf.line = linenum; |
| 2026 | |
| 2027 | newpeer->last_change = now.tv_sec; |
| 2028 | newpeer->id = strdup(args[1]); |
| 2029 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2030 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2031 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2032 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2034 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2035 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2036 | |
| 2037 | proto = protocol_by_family(sk->ss_family); |
| 2038 | if (!proto || !proto->connect) { |
| 2039 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2040 | file, linenum, args[0], args[1]); |
| 2041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2042 | goto out; |
| 2043 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2044 | |
| 2045 | if (port1 != port2) { |
| 2046 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2047 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2049 | goto out; |
| 2050 | } |
| 2051 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2052 | if (!port1) { |
| 2053 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2054 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2056 | goto out; |
| 2057 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2058 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2059 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2060 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 2061 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2062 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2063 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2064 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2065 | /* Current is local peer, it define a frontend */ |
| 2066 | newpeer->local = 1; |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 2067 | peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2068 | |
| 2069 | if (!curpeers->peers_fe) { |
| 2070 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2071 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2072 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2073 | goto out; |
| 2074 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2075 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2076 | init_new_proxy(curpeers->peers_fe); |
| 2077 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2078 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2079 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2080 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2081 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2082 | |
| 2083 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 2084 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2085 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2086 | if (errmsg && *errmsg) { |
| 2087 | indent_msg(&errmsg, 2); |
| 2088 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2089 | } |
| 2090 | else |
| 2091 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2092 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2093 | err_code |= ERR_FATAL; |
| 2094 | goto out; |
| 2095 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2096 | |
| 2097 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2098 | l->maxaccept = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2099 | l->maxconn = ((struct proxy *)curpeers->peers_fe)->maxconn; |
| 2100 | l->backlog = ((struct proxy *)curpeers->peers_fe)->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2101 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2102 | l->handler = process_stream; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2103 | l->analysers |= ((struct proxy *)curpeers->peers_fe)->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 2104 | l->default_target = ((struct proxy *)curpeers->peers_fe)->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2105 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2106 | global.maxsock += l->maxconn; |
| 2107 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2108 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2109 | else { |
| 2110 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2111 | file, linenum, args[0], args[1], |
| 2112 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2113 | err_code |= ERR_FATAL; |
| 2114 | goto out; |
| 2115 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2116 | } |
| 2117 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2118 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2119 | curpeers->state = PR_STSTOPPED; |
| 2120 | } |
| 2121 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2122 | curpeers->state = PR_STNEW; |
| 2123 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2124 | else if (*args[0] != 0) { |
| 2125 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2127 | goto out; |
| 2128 | } |
| 2129 | |
| 2130 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2131 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2132 | return err_code; |
| 2133 | } |
| 2134 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2135 | /* |
| 2136 | * Parse a <resolvers> section. |
| 2137 | * Returns the error code, 0 if OK, or any combination of : |
| 2138 | * - ERR_ABORT: must abort ASAP |
| 2139 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2140 | * - ERR_WARN: a warning has been emitted |
| 2141 | * - ERR_ALERT: an alert has been emitted |
| 2142 | * Only the two first ones can stop processing, the two others are just |
| 2143 | * indicators. |
| 2144 | */ |
| 2145 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2146 | { |
| 2147 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2148 | struct dns_nameserver *newnameserver = NULL; |
| 2149 | const char *err; |
| 2150 | int err_code = 0; |
| 2151 | char *errmsg = NULL; |
| 2152 | |
| 2153 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2154 | if (!*args[1]) { |
| 2155 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2156 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2157 | goto out; |
| 2158 | } |
| 2159 | |
| 2160 | err = invalid_char(args[1]); |
| 2161 | if (err) { |
| 2162 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2163 | file, linenum, *err, args[0], args[1]); |
| 2164 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2165 | goto out; |
| 2166 | } |
| 2167 | |
| 2168 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2169 | /* Error if two resolvers owns the same name */ |
| 2170 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2171 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2172 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2173 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | if ((curr_resolvers = (struct dns_resolvers *)calloc(1, sizeof(struct dns_resolvers))) == NULL) { |
| 2178 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2179 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2180 | goto out; |
| 2181 | } |
| 2182 | |
| 2183 | /* default values */ |
| 2184 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2185 | curr_resolvers->conf.file = strdup(file); |
| 2186 | curr_resolvers->conf.line = linenum; |
| 2187 | curr_resolvers->id = strdup(args[1]); |
| 2188 | curr_resolvers->query_ids = EB_ROOT; |
| 2189 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2190 | curr_resolvers->hold.valid = 10000; |
| 2191 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2192 | curr_resolvers->resolve_retries = 3; |
| 2193 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2194 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2195 | } |
| 2196 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2197 | struct sockaddr_storage *sk; |
| 2198 | int port1, port2; |
| 2199 | struct protocol *proto; |
| 2200 | |
| 2201 | if (!*args[2]) { |
| 2202 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2203 | file, linenum, args[0]); |
| 2204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2205 | goto out; |
| 2206 | } |
| 2207 | |
| 2208 | err = invalid_char(args[1]); |
| 2209 | if (err) { |
| 2210 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2211 | file, linenum, *err, args[1]); |
| 2212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2213 | goto out; |
| 2214 | } |
| 2215 | |
| 2216 | if ((newnameserver = (struct dns_nameserver *)calloc(1, sizeof(struct dns_nameserver))) == NULL) { |
| 2217 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2218 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2219 | goto out; |
| 2220 | } |
| 2221 | |
| 2222 | /* the nameservers are linked backward first */ |
| 2223 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2224 | curr_resolvers->count_nameservers++; |
| 2225 | newnameserver->resolvers = curr_resolvers; |
| 2226 | newnameserver->conf.file = strdup(file); |
| 2227 | newnameserver->conf.line = linenum; |
| 2228 | newnameserver->id = strdup(args[1]); |
| 2229 | |
| 2230 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
| 2231 | if (!sk) { |
| 2232 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2234 | goto out; |
| 2235 | } |
| 2236 | |
| 2237 | proto = protocol_by_family(sk->ss_family); |
| 2238 | if (!proto || !proto->connect) { |
| 2239 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2240 | file, linenum, args[0], args[1]); |
| 2241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2242 | goto out; |
| 2243 | } |
| 2244 | |
| 2245 | if (port1 != port2) { |
| 2246 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2247 | file, linenum, args[0], args[1], args[2]); |
| 2248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2249 | goto out; |
| 2250 | } |
| 2251 | |
| 2252 | newnameserver->addr = *sk; |
| 2253 | } |
| 2254 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2255 | const char *res; |
| 2256 | unsigned int time; |
| 2257 | |
| 2258 | if (!*args[2]) { |
| 2259 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2260 | file, linenum, args[0]); |
| 2261 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2263 | goto out; |
| 2264 | } |
| 2265 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2266 | if (res) { |
| 2267 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2268 | file, linenum, *res, args[0]); |
| 2269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2270 | goto out; |
| 2271 | } |
| 2272 | if (strcmp(args[1], "valid") == 0) |
| 2273 | curr_resolvers->hold.valid = time; |
| 2274 | else { |
| 2275 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects 'valid'\n", |
| 2276 | file, linenum, args[0], args[1]); |
| 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
| 2281 | } |
| 2282 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2283 | if (!*args[1]) { |
| 2284 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2285 | file, linenum, args[0]); |
| 2286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2287 | goto out; |
| 2288 | } |
| 2289 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2290 | } |
| 2291 | else if (strcmp(args[0], "timeout") == 0) { |
| 2292 | const char *res; |
| 2293 | unsigned int timeout_retry; |
| 2294 | |
| 2295 | if (!*args[2]) { |
| 2296 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2297 | file, linenum, args[0]); |
| 2298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2299 | goto out; |
| 2300 | } |
| 2301 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2302 | if (res) { |
| 2303 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2304 | file, linenum, *res, args[0]); |
| 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | curr_resolvers->timeout.retry = timeout_retry; |
| 2309 | } /* neither "nameserver" nor "resolvers" */ |
| 2310 | else if (*args[0] != 0) { |
| 2311 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2313 | goto out; |
| 2314 | } |
| 2315 | |
| 2316 | out: |
| 2317 | free(errmsg); |
| 2318 | return err_code; |
| 2319 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2320 | |
| 2321 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2322 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2323 | * Returns the error code, 0 if OK, or any combination of : |
| 2324 | * - ERR_ABORT: must abort ASAP |
| 2325 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2326 | * - ERR_WARN: a warning has been emitted |
| 2327 | * - ERR_ALERT: an alert has been emitted |
| 2328 | * Only the two first ones can stop processing, the two others are just |
| 2329 | * indicators. |
| 2330 | */ |
| 2331 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2332 | { |
| 2333 | static struct mailers *curmailers = NULL; |
| 2334 | struct mailer *newmailer = NULL; |
| 2335 | const char *err; |
| 2336 | int err_code = 0; |
| 2337 | char *errmsg = NULL; |
| 2338 | |
| 2339 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2340 | if (!*args[1]) { |
| 2341 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2342 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2343 | goto out; |
| 2344 | } |
| 2345 | |
| 2346 | err = invalid_char(args[1]); |
| 2347 | if (err) { |
| 2348 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2349 | file, linenum, *err, args[0], args[1]); |
| 2350 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2351 | goto out; |
| 2352 | } |
| 2353 | |
| 2354 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2355 | /* |
| 2356 | * If there are two proxies with the same name only following |
| 2357 | * combinations are allowed: |
| 2358 | */ |
| 2359 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2360 | Alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2361 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2362 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | if ((curmailers = (struct mailers *)calloc(1, sizeof(struct mailers))) == NULL) { |
| 2367 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2368 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
| 2372 | curmailers->next = mailers; |
| 2373 | mailers = curmailers; |
| 2374 | curmailers->conf.file = strdup(file); |
| 2375 | curmailers->conf.line = linenum; |
| 2376 | curmailers->id = strdup(args[1]); |
| 2377 | } |
| 2378 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2379 | struct sockaddr_storage *sk; |
| 2380 | int port1, port2; |
| 2381 | struct protocol *proto; |
| 2382 | |
| 2383 | if (!*args[2]) { |
| 2384 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2385 | file, linenum, args[0]); |
| 2386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2387 | goto out; |
| 2388 | } |
| 2389 | |
| 2390 | err = invalid_char(args[1]); |
| 2391 | if (err) { |
| 2392 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2393 | file, linenum, *err, args[1]); |
| 2394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2395 | goto out; |
| 2396 | } |
| 2397 | |
| 2398 | if ((newmailer = (struct mailer *)calloc(1, sizeof(struct mailer))) == NULL) { |
| 2399 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2400 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2401 | goto out; |
| 2402 | } |
| 2403 | |
| 2404 | /* the mailers are linked backwards first */ |
| 2405 | curmailers->count++; |
| 2406 | newmailer->next = curmailers->mailer_list; |
| 2407 | curmailers->mailer_list = newmailer; |
| 2408 | newmailer->mailers = curmailers; |
| 2409 | newmailer->conf.file = strdup(file); |
| 2410 | newmailer->conf.line = linenum; |
| 2411 | |
| 2412 | newmailer->id = strdup(args[1]); |
| 2413 | |
| 2414 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL); |
| 2415 | if (!sk) { |
| 2416 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2418 | goto out; |
| 2419 | } |
| 2420 | |
| 2421 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2422 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2423 | Alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n", |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2424 | file, linenum, args[0], args[1]); |
| 2425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2426 | goto out; |
| 2427 | } |
| 2428 | |
| 2429 | if (port1 != port2) { |
| 2430 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2431 | file, linenum, args[0], args[1], args[2]); |
| 2432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2433 | goto out; |
| 2434 | } |
| 2435 | |
| 2436 | if (!port1) { |
| 2437 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2438 | file, linenum, args[0], args[1], args[2]); |
| 2439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2440 | goto out; |
| 2441 | } |
| 2442 | |
| 2443 | newmailer->addr = *sk; |
| 2444 | newmailer->proto = proto; |
| 2445 | newmailer->xprt = &raw_sock; |
| 2446 | newmailer->sock_init_arg = NULL; |
| 2447 | } /* neither "mailer" nor "mailers" */ |
| 2448 | else if (*args[0] != 0) { |
| 2449 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2451 | goto out; |
| 2452 | } |
| 2453 | |
| 2454 | out: |
| 2455 | free(errmsg); |
| 2456 | return err_code; |
| 2457 | } |
| 2458 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2459 | static void free_email_alert(struct proxy *p) |
| 2460 | { |
| 2461 | free(p->email_alert.mailers.name); |
| 2462 | p->email_alert.mailers.name = NULL; |
| 2463 | free(p->email_alert.from); |
| 2464 | p->email_alert.from = NULL; |
| 2465 | free(p->email_alert.to); |
| 2466 | p->email_alert.to = NULL; |
| 2467 | free(p->email_alert.myhostname); |
| 2468 | p->email_alert.myhostname = NULL; |
| 2469 | } |
| 2470 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2471 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2472 | { |
| 2473 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2474 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2475 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2476 | int rc; |
| 2477 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2478 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2479 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2480 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2481 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2482 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2483 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2484 | if (!strcmp(args[0], "listen")) |
| 2485 | rc = PR_CAP_LISTEN; |
| 2486 | else if (!strcmp(args[0], "frontend")) |
| 2487 | rc = PR_CAP_FE | PR_CAP_RS; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2488 | else if (!strcmp(args[0], "backend")) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2489 | rc = PR_CAP_BE | PR_CAP_RS; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2490 | else |
| 2491 | rc = PR_CAP_NONE; |
| 2492 | |
| 2493 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2494 | if (!*args[1]) { |
| 2495 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 2496 | " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 2497 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2498 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2499 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2500 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2501 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2502 | err = invalid_char(args[1]); |
| 2503 | if (err) { |
| 2504 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2505 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2506 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2509 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2510 | if (curproxy) { |
| 2511 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2512 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2513 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2514 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2515 | } |
| 2516 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2517 | if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 2518 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2519 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2521 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2522 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2523 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2524 | curproxy->next = proxy; |
| 2525 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2526 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2527 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2528 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2529 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2530 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2531 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2532 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2533 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2534 | if (curproxy->cap & PR_CAP_FE) |
| 2535 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2540 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2541 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2542 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2543 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2544 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2545 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2546 | curproxy->no_options = defproxy.no_options; |
| 2547 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2548 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2549 | curproxy->except_net = defproxy.except_net; |
| 2550 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2551 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2552 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2553 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2554 | if (defproxy.fwdfor_hdr_len) { |
| 2555 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2556 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2557 | } |
| 2558 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2559 | if (defproxy.orgto_hdr_len) { |
| 2560 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2561 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2562 | } |
| 2563 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2564 | if (defproxy.server_id_hdr_len) { |
| 2565 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2566 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2567 | } |
| 2568 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2569 | if (curproxy->cap & PR_CAP_FE) { |
| 2570 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2571 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2572 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2573 | |
| 2574 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2575 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2576 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2577 | |
| 2578 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2579 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2580 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2581 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2582 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2583 | curproxy->fullconn = defproxy.fullconn; |
| 2584 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2585 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2586 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2587 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2588 | if (defproxy.check_req) { |
| 2589 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2590 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2591 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2592 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2593 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2594 | if (defproxy.expect_str) { |
| 2595 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2596 | if (defproxy.expect_regex) { |
| 2597 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2598 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2599 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2600 | } |
| 2601 | } |
| 2602 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2603 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2604 | if (defproxy.cookie_name) |
| 2605 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2606 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2607 | if (defproxy.cookie_domain) |
| 2608 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2609 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2610 | if (defproxy.cookie_maxidle) |
| 2611 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2612 | |
| 2613 | if (defproxy.cookie_maxlife) |
| 2614 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2615 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2616 | if (defproxy.rdp_cookie_name) |
| 2617 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2618 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2619 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2620 | if (defproxy.url_param_name) |
| 2621 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2622 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2623 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2624 | if (defproxy.hh_name) |
| 2625 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2626 | curproxy->hh_len = defproxy.hh_len; |
| 2627 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2628 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2629 | if (defproxy.conn_src.iface_name) |
| 2630 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2631 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2632 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 2633 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2634 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2635 | #endif |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2636 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2637 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2638 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2639 | if (defproxy.capture_name) |
| 2640 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2641 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2642 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2643 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2644 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2645 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2646 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2647 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2648 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2649 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2650 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2651 | curproxy->mon_net = defproxy.mon_net; |
| 2652 | curproxy->mon_mask = defproxy.mon_mask; |
| 2653 | if (defproxy.monitor_uri) |
| 2654 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2655 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2656 | if (defproxy.defbe.name) |
| 2657 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2658 | |
| 2659 | /* get either a pointer to the logformat string or a copy of it */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2660 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2661 | if (curproxy->conf.logformat_string && |
| 2662 | curproxy->conf.logformat_string != default_http_log_format && |
| 2663 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2664 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2665 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2666 | |
| 2667 | if (defproxy.conf.lfs_file) { |
| 2668 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2669 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2670 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2674 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2675 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2676 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2677 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2678 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2679 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2680 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2681 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2682 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2683 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2684 | } |
| 2685 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2686 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2687 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2688 | |
| 2689 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2690 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2691 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2692 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2693 | LIST_INIT(&node->list); |
| 2694 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2695 | } |
| 2696 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2697 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2698 | if (curproxy->conf.uniqueid_format_string) |
| 2699 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2700 | |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2701 | if (defproxy.log_tag) |
| 2702 | curproxy->log_tag = strdup(defproxy.log_tag); |
| 2703 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2704 | if (defproxy.conf.uif_file) { |
| 2705 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2706 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2707 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2708 | |
| 2709 | /* copy default header unique id */ |
| 2710 | if (defproxy.header_unique_id) |
| 2711 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2712 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2713 | /* default compression options */ |
| 2714 | if (defproxy.comp != NULL) { |
| 2715 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2716 | curproxy->comp->algos = defproxy.comp->algos; |
| 2717 | curproxy->comp->types = defproxy.comp->types; |
| 2718 | } |
| 2719 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2720 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2721 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2722 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2723 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2724 | if (defproxy.check_path) |
| 2725 | curproxy->check_path = strdup(defproxy.check_path); |
| 2726 | if (defproxy.check_command) |
| 2727 | curproxy->check_command = strdup(defproxy.check_command); |
| 2728 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2729 | if (defproxy.email_alert.mailers.name) |
| 2730 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 2731 | if (defproxy.email_alert.from) |
| 2732 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 2733 | if (defproxy.email_alert.to) |
| 2734 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 2735 | if (defproxy.email_alert.myhostname) |
| 2736 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2737 | curproxy->email_alert.level = defproxy.email_alert.level; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2738 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2739 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2740 | } |
| 2741 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2742 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2743 | /* FIXME-20070101: we should do this too at the end of the |
| 2744 | * config parsing to free all default values. |
| 2745 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2746 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2747 | err_code |= ERR_ABORT; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2751 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2752 | free(defproxy.check_command); |
| 2753 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2754 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2755 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2756 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2757 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2758 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2759 | free(defproxy.capture_name); |
| 2760 | free(defproxy.monitor_uri); |
| 2761 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2762 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2763 | free(defproxy.fwdfor_hdr_name); |
| 2764 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2765 | free(defproxy.orgto_hdr_name); |
| 2766 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2767 | free(defproxy.server_id_hdr_name); |
| 2768 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2769 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2770 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2771 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2772 | free(defproxy.expect_regex); |
| 2773 | defproxy.expect_regex = NULL; |
| 2774 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2775 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2776 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2777 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2778 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2779 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2780 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2781 | free(defproxy.conf.uniqueid_format_string); |
| 2782 | free(defproxy.conf.lfs_file); |
| 2783 | free(defproxy.conf.uif_file); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2784 | free(defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2785 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2786 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2787 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2788 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2789 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2790 | /* we cannot free uri_auth because it might already be used */ |
| 2791 | init_default_instance(); |
| 2792 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2793 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2794 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2795 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2796 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2797 | } |
| 2798 | else if (curproxy == NULL) { |
| 2799 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2801 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2802 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2803 | |
| 2804 | /* update the current file and line being parsed */ |
| 2805 | curproxy->conf.args.file = curproxy->conf.file; |
| 2806 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2807 | |
| 2808 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2809 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2810 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2811 | if (err_code & ERR_FATAL) |
| 2812 | goto out; |
| 2813 | } |
| 2814 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2815 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2816 | int cur_arg; |
| 2817 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2818 | if (curproxy == &defproxy) { |
| 2819 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2820 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2821 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2822 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2823 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2824 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2825 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2826 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2827 | Alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2830 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2831 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2832 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2833 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2834 | |
| 2835 | /* use default settings for unix sockets */ |
| 2836 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2837 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2838 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2839 | |
| 2840 | /* NOTE: the following line might create several listeners if there |
| 2841 | * are comma-separated IPs or port ranges. So all further processing |
| 2842 | * will have to be applied to all listeners created after last_listen. |
| 2843 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2844 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2845 | if (errmsg && *errmsg) { |
| 2846 | indent_msg(&errmsg, 2); |
| 2847 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2848 | } |
| 2849 | else |
| 2850 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2851 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
| 2854 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2855 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2856 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2857 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2858 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2859 | } |
| 2860 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2861 | cur_arg = 2; |
| 2862 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2863 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2864 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2865 | char *err; |
| 2866 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2867 | kw = bind_find_kw(args[cur_arg]); |
| 2868 | if (kw) { |
| 2869 | char *err = NULL; |
| 2870 | int code; |
| 2871 | |
| 2872 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2873 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2874 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2875 | cur_arg += 1 + kw->skip ; |
| 2876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2880 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2881 | err_code |= code; |
| 2882 | |
| 2883 | if (code) { |
| 2884 | if (err && *err) { |
| 2885 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2886 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2887 | } |
| 2888 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2889 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2890 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2891 | if (code & ERR_FATAL) { |
| 2892 | free(err); |
| 2893 | cur_arg += 1 + kw->skip; |
| 2894 | goto out; |
| 2895 | } |
| 2896 | } |
| 2897 | free(err); |
| 2898 | cur_arg += 1 + kw->skip; |
| 2899 | continue; |
| 2900 | } |
| 2901 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2902 | err = NULL; |
| 2903 | if (!bind_dumped) { |
| 2904 | bind_dump_kws(&err); |
| 2905 | indent_msg(&err, 4); |
| 2906 | bind_dumped = 1; |
| 2907 | } |
| 2908 | |
| 2909 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2910 | file, linenum, args[0], args[1], args[cur_arg], |
| 2911 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2912 | free(err); |
| 2913 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2915 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2916 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2917 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2918 | } |
| 2919 | else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 2920 | if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2921 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2922 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2924 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2925 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2926 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2927 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2928 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2929 | /* flush useless bits */ |
| 2930 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2931 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2932 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2933 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2934 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2935 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2936 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 2937 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2938 | goto out; |
| 2939 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2940 | if (!*args[1]) { |
| 2941 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2942 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2944 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2947 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2948 | curproxy->monitor_uri_len = strlen(args[1]); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2949 | curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2950 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2951 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2952 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2953 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2954 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2955 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 2956 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2957 | goto out; |
| 2958 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2959 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 2960 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 2961 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 2962 | else { |
| 2963 | Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2965 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2966 | } |
| 2967 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2968 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2969 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2970 | |
| 2971 | if (curproxy == &defproxy) { |
| 2972 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 2973 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2975 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2976 | } |
| 2977 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 2978 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2979 | goto out; |
| 2980 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2981 | if (!*args[1]) { |
| 2982 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 2983 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2985 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2989 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 2990 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2991 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2992 | if (curproxy->uuid <= 0) { |
| 2993 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2994 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2996 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2999 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3000 | if (node) { |
| 3001 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3002 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3003 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3004 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3006 | goto out; |
| 3007 | } |
| 3008 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3009 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3010 | else if (!strcmp(args[0], "description")) { |
| 3011 | int i, len=0; |
| 3012 | char *d; |
| 3013 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3014 | if (curproxy == &defproxy) { |
| 3015 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3016 | file, linenum, args[0]); |
| 3017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3018 | goto out; |
| 3019 | } |
| 3020 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3021 | if (!*args[1]) { |
| 3022 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3023 | file, linenum, args[0]); |
| 3024 | return -1; |
| 3025 | } |
| 3026 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3027 | for (i = 1; *args[i]; i++) |
| 3028 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3029 | |
| 3030 | d = (char *)calloc(1, len); |
| 3031 | curproxy->desc = d; |
| 3032 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3033 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3034 | for (i = 2; *args[i]; i++) |
| 3035 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3036 | |
| 3037 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3038 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3039 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3040 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3041 | curproxy->state = PR_STSTOPPED; |
| 3042 | } |
| 3043 | else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3044 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3045 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3046 | curproxy->state = PR_STNEW; |
| 3047 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3048 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3049 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3050 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3051 | |
| 3052 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3053 | unsigned int low, high; |
| 3054 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3055 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3056 | set = 0; |
| 3057 | break; |
| 3058 | } |
| 3059 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3060 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3061 | } |
| 3062 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3063 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3064 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3065 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3066 | char *dash = strchr(args[cur_arg], '-'); |
| 3067 | |
| 3068 | low = high = str2uic(args[cur_arg]); |
| 3069 | if (dash) |
| 3070 | high = str2uic(dash + 1); |
| 3071 | |
| 3072 | if (high < low) { |
| 3073 | unsigned int swap = low; |
| 3074 | low = high; |
| 3075 | high = swap; |
| 3076 | } |
| 3077 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3078 | if (low < 1 || high > LONGBITS) { |
| 3079 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3080 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3082 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3083 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3084 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3085 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3086 | } |
| 3087 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3088 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3089 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3091 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3092 | } |
| 3093 | cur_arg++; |
| 3094 | } |
| 3095 | curproxy->bind_proc = set; |
| 3096 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3097 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3098 | if (curproxy == &defproxy) { |
| 3099 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3102 | } |
| 3103 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3104 | err = invalid_char(args[1]); |
| 3105 | if (err) { |
| 3106 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3107 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3108 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3111 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3112 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3113 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3115 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3116 | } |
| 3117 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3118 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3119 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3120 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3121 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3122 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3123 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3124 | if (*(args[1]) == 0) { |
| 3125 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3126 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3128 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3129 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3130 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3131 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3132 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3133 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3134 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3135 | curproxy->cookie_name = strdup(args[1]); |
| 3136 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3137 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3138 | cur_arg = 2; |
| 3139 | while (*(args[cur_arg])) { |
| 3140 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3141 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3142 | } |
| 3143 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3144 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3145 | } |
| 3146 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3147 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3148 | } |
| 3149 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3150 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3151 | } |
| 3152 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3153 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3154 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3155 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3156 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3157 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3158 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3159 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3160 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3161 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3162 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3163 | } |
| 3164 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3165 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3166 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3167 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3168 | if (!*args[cur_arg + 1]) { |
| 3169 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3170 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3172 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3173 | } |
| 3174 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3175 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3176 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3177 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3178 | " dots nor does not start with a dot." |
| 3179 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3180 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3181 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3185 | if (err) { |
| 3186 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3187 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3189 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3190 | } |
| 3191 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3192 | if (!curproxy->cookie_domain) { |
| 3193 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3194 | } else { |
| 3195 | /* one domain was already specified, add another one by |
| 3196 | * building the string which will be returned along with |
| 3197 | * the cookie. |
| 3198 | */ |
| 3199 | char *new_ptr; |
| 3200 | int new_len = strlen(curproxy->cookie_domain) + |
| 3201 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3202 | new_ptr = malloc(new_len); |
| 3203 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3204 | free(curproxy->cookie_domain); |
| 3205 | curproxy->cookie_domain = new_ptr; |
| 3206 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3207 | cur_arg++; |
| 3208 | } |
| 3209 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3210 | unsigned int maxidle; |
| 3211 | const char *res; |
| 3212 | |
| 3213 | if (!*args[cur_arg + 1]) { |
| 3214 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3215 | file, linenum, args[cur_arg]); |
| 3216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3217 | goto out; |
| 3218 | } |
| 3219 | |
| 3220 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3221 | if (res) { |
| 3222 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3223 | file, linenum, *res, args[cur_arg]); |
| 3224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3225 | goto out; |
| 3226 | } |
| 3227 | curproxy->cookie_maxidle = maxidle; |
| 3228 | cur_arg++; |
| 3229 | } |
| 3230 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3231 | unsigned int maxlife; |
| 3232 | const char *res; |
| 3233 | |
| 3234 | if (!*args[cur_arg + 1]) { |
| 3235 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3236 | file, linenum, args[cur_arg]); |
| 3237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3238 | goto out; |
| 3239 | } |
| 3240 | |
| 3241 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3242 | if (res) { |
| 3243 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3244 | file, linenum, *res, args[cur_arg]); |
| 3245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3246 | goto out; |
| 3247 | } |
| 3248 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3249 | cur_arg++; |
| 3250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3251 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3252 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3253 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3255 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3256 | } |
| 3257 | cur_arg++; |
| 3258 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3259 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3260 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3261 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3262 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3263 | } |
| 3264 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3265 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3266 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3267 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3269 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3270 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3271 | if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) { |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3272 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3273 | file, linenum); |
| 3274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3275 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3276 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3277 | else if (!strcmp(args[0], "email-alert")) { |
| 3278 | if (*(args[1]) == 0) { |
| 3279 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3280 | file, linenum, args[0]); |
| 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
| 3283 | } |
| 3284 | |
| 3285 | if (!strcmp(args[1], "from")) { |
| 3286 | if (*(args[1]) == 0) { |
| 3287 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3288 | file, linenum, args[1]); |
| 3289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3290 | goto out; |
| 3291 | } |
| 3292 | free(curproxy->email_alert.from); |
| 3293 | curproxy->email_alert.from = strdup(args[2]); |
| 3294 | } |
| 3295 | else if (!strcmp(args[1], "mailers")) { |
| 3296 | if (*(args[1]) == 0) { |
| 3297 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3298 | file, linenum, args[1]); |
| 3299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3300 | goto out; |
| 3301 | } |
| 3302 | free(curproxy->email_alert.mailers.name); |
| 3303 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3304 | } |
| 3305 | else if (!strcmp(args[1], "myhostname")) { |
| 3306 | if (*(args[1]) == 0) { |
| 3307 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3308 | file, linenum, args[1]); |
| 3309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3310 | goto out; |
| 3311 | } |
| 3312 | free(curproxy->email_alert.myhostname); |
| 3313 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3314 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3315 | else if (!strcmp(args[1], "level")) { |
| 3316 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3317 | if (curproxy->email_alert.level < 0) { |
| 3318 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3319 | file, linenum, args[1], args[2]); |
| 3320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3321 | goto out; |
| 3322 | } |
| 3323 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3324 | else if (!strcmp(args[1], "to")) { |
| 3325 | if (*(args[1]) == 0) { |
| 3326 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3327 | file, linenum, args[1]); |
| 3328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3329 | goto out; |
| 3330 | } |
| 3331 | free(curproxy->email_alert.to); |
| 3332 | curproxy->email_alert.to = strdup(args[2]); |
| 3333 | } |
| 3334 | else { |
| 3335 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3336 | file, linenum, args[1]); |
| 3337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3338 | goto out; |
| 3339 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3340 | /* Indicate that the email_alert is at least partially configured */ |
| 3341 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3342 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3343 | else if (!strcmp(args[0], "external-check")) { |
| 3344 | if (*(args[1]) == 0) { |
| 3345 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3346 | file, linenum, args[0]); |
| 3347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3348 | goto out; |
| 3349 | } |
| 3350 | |
| 3351 | if (!strcmp(args[1], "command")) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3352 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3353 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3354 | if (*(args[1]) == 0) { |
| 3355 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3356 | file, linenum, args[1]); |
| 3357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3358 | goto out; |
| 3359 | } |
| 3360 | free(curproxy->check_command); |
| 3361 | curproxy->check_command = strdup(args[2]); |
| 3362 | } |
| 3363 | else if (!strcmp(args[1], "path")) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3364 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3365 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3366 | if (*(args[1]) == 0) { |
| 3367 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3368 | file, linenum, args[1]); |
| 3369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3370 | goto out; |
| 3371 | } |
| 3372 | free(curproxy->check_path); |
| 3373 | curproxy->check_path = strdup(args[2]); |
| 3374 | } |
| 3375 | else { |
| 3376 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3377 | file, linenum, args[1]); |
| 3378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3379 | goto out; |
| 3380 | } |
| 3381 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3382 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3383 | if (*(args[1]) == 0) { |
| 3384 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3385 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3387 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3391 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3392 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3393 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3394 | const char *beg, *end; |
| 3395 | |
| 3396 | beg = args[1] + 11; |
| 3397 | end = strchr(beg, ')'); |
| 3398 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3399 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3400 | goto out; |
| 3401 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3402 | if (!end || end == beg) { |
| 3403 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3404 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3406 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | free(curproxy->rdp_cookie_name); |
| 3410 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3411 | curproxy->rdp_cookie_len = end-beg; |
| 3412 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3413 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3414 | free(curproxy->rdp_cookie_name); |
| 3415 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3416 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3417 | } |
| 3418 | else { /* syntax */ |
| 3419 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3420 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3422 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3423 | } |
| 3424 | } |
| 3425 | else { |
| 3426 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3427 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3429 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3430 | } |
| 3431 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3432 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 3433 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | |
Cyril Bonté | 3b7a369 | 2010-01-10 17:01:47 +0100 | [diff] [blame] | 3435 | if (curproxy == &defproxy) { |
| 3436 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3438 | goto out; |
| 3439 | } |
| 3440 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3441 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3442 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3443 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3444 | if (*(args[5]) == 0) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 3445 | Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout> [options*].\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3446 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3449 | } |
| 3450 | have_appsession = 1; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3451 | free(curproxy->appsession_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3452 | curproxy->appsession_name = strdup(args[1]); |
| 3453 | curproxy->appsession_name_len = strlen(curproxy->appsession_name); |
| 3454 | curproxy->appsession_len = atoi(args[3]); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3455 | err = parse_time_err(args[5], &val, TIME_UNIT_MS); |
| 3456 | if (err) { |
| 3457 | Alert("parsing [%s:%d] : unexpected character '%c' in %s timeout.\n", |
| 3458 | file, linenum, *err, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3460 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 3461 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 3462 | curproxy->timeout.appsession = val; |
Willy Tarreau | ee99136 | 2007-05-14 14:37:50 +0200 | [diff] [blame] | 3463 | |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 3464 | if (appsession_hash_init(&(curproxy->htbl_proxy), destroy) == 0) { |
| 3465 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3466 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3467 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3468 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 3469 | |
| 3470 | cur_arg = 6; |
| 3471 | curproxy->options2 &= ~PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 3472 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 3473 | curproxy->options2 |= PR_O2_AS_M_PP; |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 3474 | while (*(args[cur_arg])) { |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 3475 | if (!strcmp(args[cur_arg], "request-learn")) { |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 3476 | curproxy->options2 |= PR_O2_AS_REQL; |
Cyril Bonté | b21570a | 2009-11-29 20:04:48 +0100 | [diff] [blame] | 3477 | } else if (!strcmp(args[cur_arg], "prefix")) { |
| 3478 | curproxy->options2 |= PR_O2_AS_PFX; |
| 3479 | } else if (!strcmp(args[cur_arg], "mode")) { |
| 3480 | if (!*args[cur_arg + 1]) { |
| 3481 | Alert("parsing [%s:%d] : '%s': missing argument for '%s'.\n", |
| 3482 | file, linenum, args[0], args[cur_arg]); |
| 3483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3484 | goto out; |
| 3485 | } |
| 3486 | |
| 3487 | cur_arg++; |
| 3488 | if (!strcmp(args[cur_arg], "query-string")) { |
| 3489 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 3490 | curproxy->options2 |= PR_O2_AS_M_QS; |
| 3491 | } else if (!strcmp(args[cur_arg], "path-parameters")) { |
| 3492 | curproxy->options2 &= ~PR_O2_AS_M_ANY; |
| 3493 | curproxy->options2 |= PR_O2_AS_M_PP; |
| 3494 | } else { |
| 3495 | Alert("parsing [%s:%d] : unknown mode '%s'\n", file, linenum, args[cur_arg]); |
| 3496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3497 | goto out; |
| 3498 | } |
| 3499 | } |
Cyril Bonté | bf47aeb | 2009-10-15 00:15:40 +0200 | [diff] [blame] | 3500 | cur_arg++; |
| 3501 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3502 | } /* Url App Session */ |
| 3503 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3504 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3505 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3506 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3507 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3508 | if (curproxy == &defproxy) { |
| 3509 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3511 | goto out; |
| 3512 | } |
| 3513 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3514 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3515 | goto out; |
| 3516 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3517 | if (*(args[4]) == 0) { |
| 3518 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3519 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3521 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3522 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3523 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3524 | curproxy->capture_name = strdup(args[2]); |
| 3525 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3526 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3527 | curproxy->to_log |= LW_COOKIE; |
| 3528 | } |
| 3529 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3530 | struct cap_hdr *hdr; |
| 3531 | |
| 3532 | if (curproxy == &defproxy) { |
| 3533 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3535 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3536 | } |
| 3537 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3538 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3539 | goto out; |
| 3540 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3541 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3542 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3543 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3545 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 3549 | hdr->next = curproxy->req_cap; |
| 3550 | hdr->name = strdup(args[3]); |
| 3551 | hdr->namelen = strlen(args[3]); |
| 3552 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3553 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3554 | hdr->index = curproxy->nb_req_cap++; |
| 3555 | curproxy->req_cap = hdr; |
| 3556 | curproxy->to_log |= LW_REQHDR; |
| 3557 | } |
| 3558 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3559 | struct cap_hdr *hdr; |
| 3560 | |
| 3561 | if (curproxy == &defproxy) { |
| 3562 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3564 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3565 | } |
| 3566 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3567 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3568 | goto out; |
| 3569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3570 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3571 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3572 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3574 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3575 | } |
| 3576 | hdr = calloc(sizeof(struct cap_hdr), 1); |
| 3577 | hdr->next = curproxy->rsp_cap; |
| 3578 | hdr->name = strdup(args[3]); |
| 3579 | hdr->namelen = strlen(args[3]); |
| 3580 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3581 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3582 | hdr->index = curproxy->nb_rsp_cap++; |
| 3583 | curproxy->rsp_cap = hdr; |
| 3584 | curproxy->to_log |= LW_RSPHDR; |
| 3585 | } |
| 3586 | else { |
| 3587 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3588 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3590 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3591 | } |
| 3592 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3593 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3594 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3595 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3596 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3597 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3598 | goto out; |
| 3599 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3600 | if (*(args[1]) == 0) { |
| 3601 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3602 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3605 | } |
| 3606 | curproxy->conn_retries = atol(args[1]); |
| 3607 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3608 | else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */ |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3609 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3610 | |
| 3611 | if (curproxy == &defproxy) { |
| 3612 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3614 | goto out; |
| 3615 | } |
| 3616 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3617 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 3618 | !LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->cond && |
| 3619 | (LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_ALLOW || |
| 3620 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_DENY || |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3621 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_REDIR || |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3622 | LIST_PREV(&curproxy->http_req_rules, struct http_req_rule *, list)->action == HTTP_REQ_ACT_AUTH)) { |
| 3623 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3624 | file, linenum, args[0]); |
| 3625 | err_code |= ERR_WARN; |
| 3626 | } |
| 3627 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3628 | rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3629 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3630 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3631 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3632 | goto out; |
| 3633 | } |
| 3634 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3635 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3636 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3637 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3638 | file, linenum); |
| 3639 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3640 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3641 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3642 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
| 3643 | struct http_res_rule *rule; |
| 3644 | |
| 3645 | if (curproxy == &defproxy) { |
| 3646 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3648 | goto out; |
| 3649 | } |
| 3650 | |
| 3651 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 3652 | !LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->cond && |
| 3653 | (LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_ALLOW || |
| 3654 | LIST_PREV(&curproxy->http_res_rules, struct http_res_rule *, list)->action == HTTP_RES_ACT_DENY)) { |
| 3655 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3656 | file, linenum, args[0]); |
| 3657 | err_code |= ERR_WARN; |
| 3658 | } |
| 3659 | |
| 3660 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3661 | |
| 3662 | if (!rule) { |
| 3663 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3664 | goto out; |
| 3665 | } |
| 3666 | |
| 3667 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3668 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3669 | file, linenum); |
| 3670 | |
| 3671 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3672 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3673 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3674 | /* set the header name and length into the proxy structure */ |
| 3675 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3676 | err_code |= ERR_WARN; |
| 3677 | |
| 3678 | if (!*args[1]) { |
| 3679 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3680 | file, linenum, args[0]); |
| 3681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3682 | goto out; |
| 3683 | } |
| 3684 | |
| 3685 | /* set the desired header name */ |
| 3686 | free(curproxy->server_id_hdr_name); |
| 3687 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3688 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3689 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3690 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3691 | struct http_req_rule *rule; |
| 3692 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3693 | if (curproxy == &defproxy) { |
| 3694 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3696 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3697 | } |
| 3698 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3699 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3700 | * be processed before all http-request rules, we put them into their own list |
| 3701 | * and will insert them at the end. |
| 3702 | */ |
| 3703 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3704 | if (!rule) { |
| 3705 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3706 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3707 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3708 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3709 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3710 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3711 | file, linenum); |
| 3712 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3713 | |
| 3714 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3715 | 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]); |
| 3716 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3717 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3718 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3719 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3720 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3721 | if (curproxy == &defproxy) { |
| 3722 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3727 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) { |
Willy Tarreau | 4baae24 | 2012-12-27 12:00:31 +0100 | [diff] [blame] | 3728 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3729 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3731 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3732 | } |
| 3733 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3734 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3735 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3736 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3737 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3738 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3739 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3740 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3741 | struct switching_rule *rule; |
| 3742 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3743 | if (curproxy == &defproxy) { |
| 3744 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3746 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3747 | } |
| 3748 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3749 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3751 | |
| 3752 | if (*(args[1]) == 0) { |
| 3753 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3755 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3756 | } |
| 3757 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3758 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3759 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3760 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3761 | file, linenum, errmsg); |
| 3762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3763 | goto out; |
| 3764 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3765 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3766 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | rule = (struct switching_rule *)calloc(1, sizeof(*rule)); |
| 3770 | rule->cond = cond; |
| 3771 | rule->be.name = strdup(args[1]); |
| 3772 | LIST_INIT(&rule->list); |
| 3773 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3774 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3775 | else if (strcmp(args[0], "use-server") == 0) { |
| 3776 | struct server_rule *rule; |
| 3777 | |
| 3778 | if (curproxy == &defproxy) { |
| 3779 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3781 | goto out; |
| 3782 | } |
| 3783 | |
| 3784 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3785 | err_code |= ERR_WARN; |
| 3786 | |
| 3787 | if (*(args[1]) == 0) { |
| 3788 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3790 | goto out; |
| 3791 | } |
| 3792 | |
| 3793 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3794 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3795 | file, linenum, args[0]); |
| 3796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3797 | goto out; |
| 3798 | } |
| 3799 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3800 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3801 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3802 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
| 3805 | } |
| 3806 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3807 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3808 | |
| 3809 | rule = (struct server_rule *)calloc(1, sizeof(*rule)); |
| 3810 | rule->cond = cond; |
| 3811 | rule->srv.name = strdup(args[1]); |
| 3812 | LIST_INIT(&rule->list); |
| 3813 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3814 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3815 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3816 | else if ((!strcmp(args[0], "force-persist")) || |
| 3817 | (!strcmp(args[0], "ignore-persist"))) { |
| 3818 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3819 | |
| 3820 | if (curproxy == &defproxy) { |
| 3821 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3823 | goto out; |
| 3824 | } |
| 3825 | |
| 3826 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3827 | err_code |= ERR_WARN; |
| 3828 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3829 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3830 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3831 | file, linenum, args[0]); |
| 3832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3833 | goto out; |
| 3834 | } |
| 3835 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3836 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3837 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3838 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3840 | goto out; |
| 3841 | } |
| 3842 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3843 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3844 | * where force-persist is applied. |
| 3845 | */ |
| 3846 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3847 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3848 | rule = (struct persist_rule *)calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3849 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3850 | if (!strcmp(args[0], "force-persist")) { |
| 3851 | rule->type = PERSIST_TYPE_FORCE; |
| 3852 | } else { |
| 3853 | rule->type = PERSIST_TYPE_IGNORE; |
| 3854 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3855 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3856 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3857 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3858 | else if (!strcmp(args[0], "stick-table")) { |
| 3859 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3860 | struct proxy *other; |
| 3861 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 3862 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3863 | if (other) { |
| 3864 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 3865 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 3866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3867 | goto out; |
| 3868 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3869 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3870 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3871 | curproxy->table.type = (unsigned int)-1; |
| 3872 | while (*args[myidx]) { |
| 3873 | const char *err; |
| 3874 | |
| 3875 | if (strcmp(args[myidx], "size") == 0) { |
| 3876 | myidx++; |
| 3877 | if (!*(args[myidx])) { |
| 3878 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3879 | file, linenum, args[myidx-1]); |
| 3880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3881 | goto out; |
| 3882 | } |
| 3883 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3884 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3885 | file, linenum, *err, args[myidx-1]); |
| 3886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3887 | goto out; |
| 3888 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3889 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3890 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3891 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3892 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3893 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3894 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3895 | file, linenum, args[myidx-1]); |
| 3896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3897 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3898 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3899 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3900 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3901 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3902 | myidx++; |
| 3903 | if (!*(args[myidx])) { |
| 3904 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3905 | file, linenum, args[myidx-1]); |
| 3906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3907 | goto out; |
| 3908 | } |
| 3909 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3910 | if (err) { |
| 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 | } |
| 3916 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3917 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3918 | } |
| 3919 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3920 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3921 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3922 | } |
| 3923 | else if (strcmp(args[myidx], "type") == 0) { |
| 3924 | myidx++; |
| 3925 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3926 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3927 | file, linenum, args[myidx]); |
| 3928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3929 | goto out; |
| 3930 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3931 | /* myidx already points to next arg */ |
| 3932 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3933 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3934 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3935 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3936 | |
| 3937 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3938 | nw = args[myidx]; |
| 3939 | while (*nw) { |
| 3940 | /* the "store" keyword supports a comma-separated list */ |
| 3941 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3942 | sa = NULL; /* store arg */ |
| 3943 | while (*nw && *nw != ',') { |
| 3944 | if (*nw == '(') { |
| 3945 | *nw = 0; |
| 3946 | sa = ++nw; |
| 3947 | while (*nw != ')') { |
| 3948 | if (!*nw) { |
| 3949 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3950 | file, linenum, args[0], cw); |
| 3951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3952 | goto out; |
| 3953 | } |
| 3954 | nw++; |
| 3955 | } |
| 3956 | *nw = '\0'; |
| 3957 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3958 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3959 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3960 | if (*nw) |
| 3961 | *nw++ = '\0'; |
| 3962 | type = stktable_get_data_type(cw); |
| 3963 | if (type < 0) { |
| 3964 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3965 | file, linenum, args[0], cw); |
| 3966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3967 | goto out; |
| 3968 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3969 | |
| 3970 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 3971 | switch (err) { |
| 3972 | case PE_NONE: break; |
| 3973 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3974 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 3975 | file, linenum, args[0], cw); |
| 3976 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3977 | break; |
| 3978 | |
| 3979 | case PE_ARG_MISSING: |
| 3980 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 3981 | file, linenum, args[0], cw); |
| 3982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3983 | goto out; |
| 3984 | |
| 3985 | case PE_ARG_NOT_USED: |
| 3986 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 3987 | file, linenum, args[0], cw); |
| 3988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3989 | goto out; |
| 3990 | |
| 3991 | default: |
| 3992 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 3993 | file, linenum, args[0], cw); |
| 3994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3995 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3996 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3997 | } |
| 3998 | myidx++; |
| 3999 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4000 | else { |
| 4001 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4002 | file, linenum, args[myidx]); |
| 4003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4004 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4005 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | if (!curproxy->table.size) { |
| 4009 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4010 | file, linenum); |
| 4011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4012 | goto out; |
| 4013 | } |
| 4014 | |
| 4015 | if (curproxy->table.type == (unsigned int)-1) { |
| 4016 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4017 | file, linenum); |
| 4018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4019 | goto out; |
| 4020 | } |
| 4021 | } |
| 4022 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4023 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4024 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4025 | int myidx = 0; |
| 4026 | const char *name = NULL; |
| 4027 | int flags; |
| 4028 | |
| 4029 | if (curproxy == &defproxy) { |
| 4030 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4032 | goto out; |
| 4033 | } |
| 4034 | |
| 4035 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4036 | err_code |= ERR_WARN; |
| 4037 | goto out; |
| 4038 | } |
| 4039 | |
| 4040 | myidx++; |
| 4041 | if ((strcmp(args[myidx], "store") == 0) || |
| 4042 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4043 | myidx++; |
| 4044 | flags = STK_IS_STORE; |
| 4045 | } |
| 4046 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4047 | myidx++; |
| 4048 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4049 | } |
| 4050 | else if (strcmp(args[myidx], "match") == 0) { |
| 4051 | myidx++; |
| 4052 | flags = STK_IS_MATCH; |
| 4053 | } |
| 4054 | else if (strcmp(args[myidx], "on") == 0) { |
| 4055 | myidx++; |
| 4056 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4057 | } |
| 4058 | else { |
| 4059 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
| 4062 | } |
| 4063 | |
| 4064 | if (*(args[myidx]) == 0) { |
| 4065 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4067 | goto out; |
| 4068 | } |
| 4069 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4070 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4071 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4072 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4073 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4075 | goto out; |
| 4076 | } |
| 4077 | |
| 4078 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4079 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4080 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4081 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4083 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4084 | goto out; |
| 4085 | } |
| 4086 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4087 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4088 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4089 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4091 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4092 | goto out; |
| 4093 | } |
| 4094 | } |
| 4095 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4096 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 4097 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4098 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4099 | if (strcmp(args[myidx], "table") == 0) { |
| 4100 | myidx++; |
| 4101 | name = args[myidx++]; |
| 4102 | } |
| 4103 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4104 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4105 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4106 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4107 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4108 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4109 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4110 | goto out; |
| 4111 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4112 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4113 | else if (*(args[myidx])) { |
| 4114 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4115 | file, linenum, args[0], args[myidx]); |
| 4116 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4117 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4118 | goto out; |
| 4119 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4120 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4121 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4122 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4123 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 4124 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4125 | rule = (struct sticking_rule *)calloc(1, sizeof(*rule)); |
| 4126 | rule->cond = cond; |
| 4127 | rule->expr = expr; |
| 4128 | rule->flags = flags; |
| 4129 | rule->table.name = name ? strdup(name) : NULL; |
| 4130 | LIST_INIT(&rule->list); |
| 4131 | if (flags & STK_ON_RSP) |
| 4132 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4133 | else |
| 4134 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4135 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4136 | else if (!strcmp(args[0], "stats")) { |
| 4137 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4138 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4139 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4140 | if (!*args[1]) { |
| 4141 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4142 | } else if (!strcmp(args[1], "admin")) { |
| 4143 | struct stats_admin_rule *rule; |
| 4144 | |
| 4145 | if (curproxy == &defproxy) { |
| 4146 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4148 | goto out; |
| 4149 | } |
| 4150 | |
| 4151 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4152 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4153 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4154 | goto out; |
| 4155 | } |
| 4156 | |
| 4157 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4158 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4159 | file, linenum, args[0], args[1]); |
| 4160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4161 | goto out; |
| 4162 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4163 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4164 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4165 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4167 | goto out; |
| 4168 | } |
| 4169 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4170 | err_code |= warnif_cond_conflicts(cond, |
| 4171 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4172 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4173 | |
| 4174 | rule = (struct stats_admin_rule *)calloc(1, sizeof(*rule)); |
| 4175 | rule->cond = cond; |
| 4176 | LIST_INIT(&rule->list); |
| 4177 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4178 | } else if (!strcmp(args[1], "uri")) { |
| 4179 | if (*(args[2]) == 0) { |
| 4180 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4182 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4183 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4184 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4185 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4187 | } |
| 4188 | } else if (!strcmp(args[1], "realm")) { |
| 4189 | if (*(args[2]) == 0) { |
| 4190 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4192 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4193 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4194 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4195 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4196 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4197 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4198 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4199 | unsigned interval; |
| 4200 | |
| 4201 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4202 | if (err) { |
| 4203 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4204 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4206 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4207 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4208 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4209 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4210 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4211 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4212 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4213 | struct http_req_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4214 | |
| 4215 | if (curproxy == &defproxy) { |
| 4216 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4218 | goto out; |
| 4219 | } |
| 4220 | |
| 4221 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4222 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4223 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4224 | goto out; |
| 4225 | } |
| 4226 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4227 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 4228 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct http_req_rule *, list)->cond) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4229 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4230 | file, linenum, args[0]); |
| 4231 | err_code |= ERR_WARN; |
| 4232 | } |
| 4233 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4234 | rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4235 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4236 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4237 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4238 | goto out; |
| 4239 | } |
| 4240 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4241 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4242 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4243 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4244 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4245 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4246 | } else if (!strcmp(args[1], "auth")) { |
| 4247 | if (*(args[2]) == 0) { |
| 4248 | Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4251 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4252 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4253 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4255 | } |
| 4256 | } else if (!strcmp(args[1], "scope")) { |
| 4257 | if (*(args[2]) == 0) { |
| 4258 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4260 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4261 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4262 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4263 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4264 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4265 | } |
| 4266 | } else if (!strcmp(args[1], "enable")) { |
| 4267 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4268 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4269 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4270 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4271 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4272 | } else if (!strcmp(args[1], "hide-version")) { |
| 4273 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4274 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4275 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4276 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4277 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4278 | } else if (!strcmp(args[1], "show-legends")) { |
| 4279 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4280 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4281 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4282 | goto out; |
| 4283 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4284 | } else if (!strcmp(args[1], "show-node")) { |
| 4285 | |
| 4286 | if (*args[2]) { |
| 4287 | int i; |
| 4288 | char c; |
| 4289 | |
| 4290 | for (i=0; args[2][i]; i++) { |
| 4291 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4292 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4293 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4294 | break; |
| 4295 | } |
| 4296 | |
| 4297 | if (!i || args[2][i]) { |
| 4298 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4299 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4300 | file, linenum, args[0], args[1]); |
| 4301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4302 | goto out; |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4307 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4308 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4309 | goto out; |
| 4310 | } |
| 4311 | } else if (!strcmp(args[1], "show-desc")) { |
| 4312 | char *desc = NULL; |
| 4313 | |
| 4314 | if (*args[2]) { |
| 4315 | int i, len=0; |
| 4316 | char *d; |
| 4317 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4318 | for (i = 2; *args[i]; i++) |
| 4319 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4320 | |
| 4321 | desc = d = (char *)calloc(1, len); |
| 4322 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4323 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4324 | for (i = 3; *args[i]; i++) |
| 4325 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | if (!*args[2] && !global.desc) |
| 4329 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4330 | file, linenum, args[1]); |
| 4331 | else { |
| 4332 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4333 | free(desc); |
| 4334 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4335 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4336 | goto out; |
| 4337 | } |
| 4338 | free(desc); |
| 4339 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4340 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4341 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4342 | 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 Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4343 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4349 | int optnum; |
| 4350 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4351 | if (*(args[1]) == '\0') { |
| 4352 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4353 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4355 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4356 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4357 | |
| 4358 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4359 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4360 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4361 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4362 | file, linenum, cfg_opts[optnum].name); |
| 4363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4364 | goto out; |
| 4365 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4366 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4367 | goto out; |
| 4368 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4369 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4370 | err_code |= ERR_WARN; |
| 4371 | goto out; |
| 4372 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4373 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4374 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4375 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4376 | |
| 4377 | switch (kwm) { |
| 4378 | case KWM_STD: |
| 4379 | curproxy->options |= cfg_opts[optnum].val; |
| 4380 | break; |
| 4381 | case KWM_NO: |
| 4382 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4383 | break; |
| 4384 | case KWM_DEF: /* already cleared */ |
| 4385 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4386 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4387 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4388 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4392 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4393 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4394 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4395 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4396 | file, linenum, cfg_opts2[optnum].name); |
| 4397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4398 | goto out; |
| 4399 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4400 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4401 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4402 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4403 | err_code |= ERR_WARN; |
| 4404 | goto out; |
| 4405 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4406 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4407 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4408 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4409 | |
| 4410 | switch (kwm) { |
| 4411 | case KWM_STD: |
| 4412 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4413 | break; |
| 4414 | case KWM_NO: |
| 4415 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4416 | break; |
| 4417 | case KWM_DEF: /* already cleared */ |
| 4418 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4419 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4420 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4421 | } |
| 4422 | } |
| 4423 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4424 | /* HTTP options override each other. They can be cancelled using |
| 4425 | * "no option xxx" which only switches to default mode if the mode |
| 4426 | * was this one (useful for cancelling options set in defaults |
| 4427 | * sections). |
| 4428 | */ |
| 4429 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4430 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4431 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4432 | if (kwm == KWM_STD) { |
| 4433 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4434 | curproxy->options |= PR_O_HTTP_PCL; |
| 4435 | goto out; |
| 4436 | } |
| 4437 | else if (kwm == KWM_NO) { |
| 4438 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4439 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4440 | goto out; |
| 4441 | } |
| 4442 | } |
| 4443 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4444 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4445 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4446 | if (kwm == KWM_STD) { |
| 4447 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4448 | curproxy->options |= PR_O_HTTP_FCL; |
| 4449 | goto out; |
| 4450 | } |
| 4451 | else if (kwm == KWM_NO) { |
| 4452 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4453 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4454 | goto out; |
| 4455 | } |
| 4456 | } |
| 4457 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4458 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4459 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4460 | if (kwm == KWM_STD) { |
| 4461 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4462 | curproxy->options |= PR_O_HTTP_SCL; |
| 4463 | goto out; |
| 4464 | } |
| 4465 | else if (kwm == KWM_NO) { |
| 4466 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4467 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4468 | goto out; |
| 4469 | } |
| 4470 | } |
| 4471 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4472 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4473 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4474 | if (kwm == KWM_STD) { |
| 4475 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4476 | curproxy->options |= PR_O_HTTP_KAL; |
| 4477 | goto out; |
| 4478 | } |
| 4479 | else if (kwm == KWM_NO) { |
| 4480 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4481 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4482 | goto out; |
| 4483 | } |
| 4484 | } |
| 4485 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4486 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4487 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4488 | if (kwm == KWM_STD) { |
| 4489 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4490 | curproxy->options |= PR_O_HTTP_TUN; |
| 4491 | goto out; |
| 4492 | } |
| 4493 | else if (kwm == KWM_NO) { |
| 4494 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4495 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4496 | goto out; |
| 4497 | } |
| 4498 | } |
| 4499 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4500 | /* Redispatch can take an integer argument that control when the |
| 4501 | * resispatch occurs. All values are relative to the retries option. |
| 4502 | * This can be cancelled using "no option xxx". |
| 4503 | */ |
| 4504 | if (strcmp(args[1], "redispatch") == 0) { |
| 4505 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4506 | err_code |= ERR_WARN; |
| 4507 | goto out; |
| 4508 | } |
| 4509 | |
| 4510 | curproxy->no_options &= ~PR_O_REDISP; |
| 4511 | curproxy->options &= ~PR_O_REDISP; |
| 4512 | |
| 4513 | switch (kwm) { |
| 4514 | case KWM_STD: |
| 4515 | curproxy->options |= PR_O_REDISP; |
| 4516 | curproxy->redispatch_after = -1; |
| 4517 | if(*args[2]) { |
| 4518 | curproxy->redispatch_after = atol(args[2]); |
| 4519 | } |
| 4520 | break; |
| 4521 | case KWM_NO: |
| 4522 | curproxy->no_options |= PR_O_REDISP; |
| 4523 | curproxy->redispatch_after = 0; |
| 4524 | break; |
| 4525 | case KWM_DEF: /* already cleared */ |
| 4526 | break; |
| 4527 | } |
| 4528 | goto out; |
| 4529 | } |
| 4530 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4531 | if (kwm != KWM_STD) { |
| 4532 | Alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4533 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4535 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4538 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4539 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4540 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4541 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4542 | if (*(args[2]) != '\0') { |
| 4543 | if (!strcmp(args[2], "clf")) { |
| 4544 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4545 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4546 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4547 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4549 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4550 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4551 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4552 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4553 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4554 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4555 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4556 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4557 | free(curproxy->conf.logformat_string); |
| 4558 | curproxy->conf.logformat_string = logformat; |
| 4559 | |
| 4560 | free(curproxy->conf.lfs_file); |
| 4561 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4562 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4563 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4564 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4565 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4566 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4567 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4568 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4569 | free(curproxy->conf.logformat_string); |
| 4570 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4571 | |
| 4572 | free(curproxy->conf.lfs_file); |
| 4573 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4574 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4575 | |
| 4576 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4577 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4578 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4579 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4580 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4581 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4582 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4583 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4584 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4585 | goto out; |
| 4586 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4587 | if (curproxy->cap & PR_CAP_FE) |
| 4588 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4589 | if (curproxy->cap & PR_CAP_BE) |
| 4590 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4591 | } |
| 4592 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4593 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4594 | err_code |= ERR_WARN; |
| 4595 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4596 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4597 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4598 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4599 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4600 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4601 | if (!*args[2]) { /* no argument */ |
| 4602 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4603 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4604 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4605 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4606 | curproxy->check_req = (char *)malloc(reqlen); |
| 4607 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4608 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4609 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4610 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4611 | if (*args[4]) |
| 4612 | reqlen += strlen(args[4]); |
| 4613 | else |
| 4614 | reqlen += strlen("HTTP/1.0"); |
| 4615 | |
| 4616 | curproxy->check_req = (char *)malloc(reqlen); |
| 4617 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4618 | "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4619 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4620 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4621 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4622 | } |
| 4623 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4624 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4625 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4626 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4627 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4628 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4629 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4630 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4631 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4632 | |
| 4633 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4634 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4635 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4636 | else if (!strcmp(args[1], "smtpchk")) { |
| 4637 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4638 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4639 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4640 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4641 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4642 | |
| 4643 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4644 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4645 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4646 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4647 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4648 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
| 4649 | curproxy->check_req = (char *)malloc(reqlen); |
| 4650 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4651 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4652 | } else { |
| 4653 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4654 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4655 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4656 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4657 | } |
| 4658 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4659 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4660 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4661 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4662 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4663 | /* use PostgreSQL request to check servers' health */ |
| 4664 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4665 | err_code |= ERR_WARN; |
| 4666 | |
| 4667 | free(curproxy->check_req); |
| 4668 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4669 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4670 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4671 | |
| 4672 | if (*(args[2])) { |
| 4673 | int cur_arg = 2; |
| 4674 | |
| 4675 | while (*(args[cur_arg])) { |
| 4676 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4677 | char * packet; |
| 4678 | uint32_t packet_len; |
| 4679 | uint32_t pv; |
| 4680 | |
| 4681 | /* suboption header - needs additional argument for it */ |
| 4682 | if (*(args[cur_arg+1]) == 0) { |
| 4683 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4684 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4686 | goto out; |
| 4687 | } |
| 4688 | |
| 4689 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4690 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4691 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4692 | |
| 4693 | packet = (char*) calloc(1, packet_len); |
| 4694 | |
| 4695 | memcpy(packet + 4, &pv, 4); |
| 4696 | |
| 4697 | /* copy "user" */ |
| 4698 | memcpy(packet + 8, "user", 4); |
| 4699 | |
| 4700 | /* copy username */ |
| 4701 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4702 | |
| 4703 | free(curproxy->check_req); |
| 4704 | curproxy->check_req = packet; |
| 4705 | curproxy->check_len = packet_len; |
| 4706 | |
| 4707 | packet_len = htonl(packet_len); |
| 4708 | memcpy(packet, &packet_len, 4); |
| 4709 | cur_arg += 2; |
| 4710 | } else { |
| 4711 | /* unknown suboption - catchall */ |
| 4712 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4713 | file, linenum, args[0], args[1]); |
| 4714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4715 | goto out; |
| 4716 | } |
| 4717 | } /* end while loop */ |
| 4718 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4719 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4720 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4723 | else if (!strcmp(args[1], "redis-check")) { |
| 4724 | /* use REDIS PING request to check servers' health */ |
| 4725 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4726 | err_code |= ERR_WARN; |
| 4727 | |
| 4728 | free(curproxy->check_req); |
| 4729 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4730 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4731 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4732 | |
| 4733 | curproxy->check_req = (char *) malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4734 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4735 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4736 | |
| 4737 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4738 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4739 | } |
| 4740 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4741 | else if (!strcmp(args[1], "mysql-check")) { |
| 4742 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4743 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4744 | err_code |= ERR_WARN; |
| 4745 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4746 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4747 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4748 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4749 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4750 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4751 | /* This is an example of a MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte. |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4752 | * const char mysql40_client_auth_pkt[] = { |
| 4753 | * "\x0e\x00\x00" // packet length |
| 4754 | * "\x01" // packet number |
| 4755 | * "\x00\x00" // client capabilities |
| 4756 | * "\x00\x00\x01" // max packet |
| 4757 | * "haproxy\x00" // username (null terminated string) |
| 4758 | * "\x00" // filler (always 0x00) |
| 4759 | * "\x01\x00\x00" // packet length |
| 4760 | * "\x00" // packet number |
| 4761 | * "\x01" // COM_QUIT command |
| 4762 | * }; |
| 4763 | */ |
| 4764 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4765 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4766 | * const char mysql41_client_auth_pkt[] = { |
| 4767 | * "\x0e\x00\x00\" // packet length |
| 4768 | * "\x01" // packet number |
| 4769 | * "\x00\x00\x00\x00" // client capabilities |
| 4770 | * "\x00\x00\x00\x01" // max packet |
| 4771 | * "\x21" // character set (UTF-8) |
| 4772 | * char[23] // All zeroes |
| 4773 | * "haproxy\x00" // username (null terminated string) |
| 4774 | * "\x00" // filler (always 0x00) |
| 4775 | * "\x01\x00\x00" // packet length |
| 4776 | * "\x00" // packet number |
| 4777 | * "\x01" // COM_QUIT command |
| 4778 | * }; |
| 4779 | */ |
| 4780 | |
| 4781 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4782 | if (*(args[2])) { |
| 4783 | int cur_arg = 2; |
| 4784 | |
| 4785 | while (*(args[cur_arg])) { |
| 4786 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4787 | char *mysqluser; |
| 4788 | int packetlen, reqlen, userlen; |
| 4789 | |
| 4790 | /* suboption header - needs additional argument for it */ |
| 4791 | if (*(args[cur_arg+1]) == 0) { |
| 4792 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4793 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4794 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4795 | goto out; |
| 4796 | } |
| 4797 | mysqluser = args[cur_arg + 1]; |
| 4798 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4799 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4800 | if (*(args[cur_arg+2])) { |
| 4801 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4802 | packetlen = userlen + 7 + 27; |
| 4803 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4804 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4805 | free(curproxy->check_req); |
| 4806 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4807 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4808 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4809 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4810 | ((unsigned char) packetlen & 0xff), |
| 4811 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4812 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4813 | |
| 4814 | curproxy->check_req[3] = 1; |
| 4815 | curproxy->check_req[5] = 130; |
| 4816 | curproxy->check_req[11] = 1; |
| 4817 | curproxy->check_req[12] = 33; |
| 4818 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4819 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4820 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4821 | cur_arg += 3; |
| 4822 | } else { |
| 4823 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4825 | goto out; |
| 4826 | } |
| 4827 | } else { |
| 4828 | packetlen = userlen + 7; |
| 4829 | reqlen = packetlen + 9; |
| 4830 | |
| 4831 | free(curproxy->check_req); |
| 4832 | curproxy->check_req = (char *)calloc(1, reqlen); |
| 4833 | curproxy->check_len = reqlen; |
| 4834 | |
| 4835 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4836 | ((unsigned char) packetlen & 0xff), |
| 4837 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4838 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4839 | |
| 4840 | curproxy->check_req[3] = 1; |
| 4841 | curproxy->check_req[5] = 128; |
| 4842 | curproxy->check_req[8] = 1; |
| 4843 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4844 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4845 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4846 | cur_arg += 2; |
| 4847 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4848 | } else { |
| 4849 | /* unknown suboption - catchall */ |
| 4850 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4851 | file, linenum, args[0], args[1]); |
| 4852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4853 | goto out; |
| 4854 | } |
| 4855 | } /* end while loop */ |
| 4856 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4857 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4858 | else if (!strcmp(args[1], "ldap-check")) { |
| 4859 | /* use LDAP request to check servers' health */ |
| 4860 | free(curproxy->check_req); |
| 4861 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4862 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4863 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4864 | |
| 4865 | curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4866 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4867 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4868 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4869 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4870 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4871 | else if (!strcmp(args[1], "tcp-check")) { |
| 4872 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4873 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4874 | err_code |= ERR_WARN; |
| 4875 | |
| 4876 | free(curproxy->check_req); |
| 4877 | curproxy->check_req = NULL; |
| 4878 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4879 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4880 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4881 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4882 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4883 | else if (!strcmp(args[1], "external-check")) { |
| 4884 | /* excute an external command to check servers' health */ |
| 4885 | free(curproxy->check_req); |
| 4886 | curproxy->check_req = NULL; |
| 4887 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4888 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4889 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4890 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4891 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4892 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4893 | int cur_arg; |
| 4894 | |
| 4895 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4896 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4897 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4898 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4899 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4900 | |
| 4901 | free(curproxy->fwdfor_hdr_name); |
| 4902 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4903 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4904 | |
| 4905 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4906 | cur_arg = 2; |
| 4907 | while (*(args[cur_arg])) { |
| 4908 | if (!strcmp(args[cur_arg], "except")) { |
| 4909 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4910 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4911 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4912 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4914 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4915 | } |
| 4916 | /* flush useless bits */ |
| 4917 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4918 | cur_arg += 2; |
| 4919 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4920 | /* suboption header - needs additional argument for it */ |
| 4921 | if (*(args[cur_arg+1]) == 0) { |
| 4922 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4923 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4925 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4926 | } |
| 4927 | free(curproxy->fwdfor_hdr_name); |
| 4928 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4929 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4930 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4931 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4932 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4933 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4934 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4935 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4936 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4937 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4939 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4940 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4941 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4942 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4943 | else if (!strcmp(args[1], "originalto")) { |
| 4944 | int cur_arg; |
| 4945 | |
| 4946 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 4947 | * set default options (ie: bitfield, header name, etc) |
| 4948 | */ |
| 4949 | |
| 4950 | curproxy->options |= PR_O_ORGTO; |
| 4951 | |
| 4952 | free(curproxy->orgto_hdr_name); |
| 4953 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 4954 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 4955 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4956 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4957 | cur_arg = 2; |
| 4958 | while (*(args[cur_arg])) { |
| 4959 | if (!strcmp(args[cur_arg], "except")) { |
| 4960 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4961 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4962 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4963 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4965 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4966 | } |
| 4967 | /* flush useless bits */ |
| 4968 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 4969 | cur_arg += 2; |
| 4970 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4971 | /* suboption header - needs additional argument for it */ |
| 4972 | if (*(args[cur_arg+1]) == 0) { |
| 4973 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4974 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4976 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4977 | } |
| 4978 | free(curproxy->orgto_hdr_name); |
| 4979 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 4980 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 4981 | cur_arg += 2; |
| 4982 | } else { |
| 4983 | /* unknown suboption - catchall */ |
| 4984 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 4985 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4987 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 4988 | } |
| 4989 | } /* end while loop */ |
| 4990 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4991 | else { |
| 4992 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4994 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4995 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4996 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4997 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 4998 | else if (!strcmp(args[0], "default_backend")) { |
| 4999 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5000 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5001 | |
| 5002 | if (*(args[1]) == 0) { |
| 5003 | Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5005 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5006 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5007 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5008 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5009 | |
| 5010 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5011 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5012 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5013 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5014 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5015 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5016 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5017 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5018 | Warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n", |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 5019 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5020 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5021 | /* enable reconnections to dispatch */ |
| 5022 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5023 | |
| 5024 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5025 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5026 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5027 | else if (!strcmp(args[0], "http-reuse")) { |
| 5028 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5029 | err_code |= ERR_WARN; |
| 5030 | |
| 5031 | if (strcmp(args[1], "never") == 0) { |
| 5032 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5033 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5034 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5035 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5036 | goto out; |
| 5037 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5038 | else if (strcmp(args[1], "safe") == 0) { |
| 5039 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5040 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5041 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5042 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5043 | goto out; |
| 5044 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5045 | else if (strcmp(args[1], "always") == 0) { |
| 5046 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5047 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5048 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5049 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5050 | goto out; |
| 5051 | } |
| 5052 | else { |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5053 | Alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'always'.\n", file, linenum, args[0]); |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5055 | goto out; |
| 5056 | } |
| 5057 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5058 | else if (!strcmp(args[0], "http-check")) { |
| 5059 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5060 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5061 | |
| 5062 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5063 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5064 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5065 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5066 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5067 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5068 | else if (strcmp(args[1], "send-state") == 0) { |
| 5069 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5070 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5071 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5072 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5073 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5074 | else if (strcmp(args[1], "expect") == 0) { |
| 5075 | const char *ptr_arg; |
| 5076 | int cur_arg; |
| 5077 | |
| 5078 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5079 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5081 | goto out; |
| 5082 | } |
| 5083 | |
| 5084 | cur_arg = 2; |
| 5085 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5086 | while (*(ptr_arg = args[cur_arg])) { |
| 5087 | while (*ptr_arg == '!') { |
| 5088 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5089 | ptr_arg++; |
| 5090 | } |
| 5091 | if (*ptr_arg) |
| 5092 | break; |
| 5093 | cur_arg++; |
| 5094 | } |
| 5095 | /* now ptr_arg points to the beginning of a word past any possible |
| 5096 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5097 | */ |
| 5098 | if (strcmp(ptr_arg, "status") == 0) { |
| 5099 | if (!*(args[cur_arg + 1])) { |
| 5100 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5101 | file, linenum, args[0], args[1], ptr_arg); |
| 5102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5103 | goto out; |
| 5104 | } |
| 5105 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5106 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5107 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5108 | } |
| 5109 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5110 | if (!*(args[cur_arg + 1])) { |
| 5111 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5112 | file, linenum, args[0], args[1], ptr_arg); |
| 5113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5114 | goto out; |
| 5115 | } |
| 5116 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5117 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5118 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5119 | } |
| 5120 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5121 | if (!*(args[cur_arg + 1])) { |
| 5122 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5123 | file, linenum, args[0], args[1], ptr_arg); |
| 5124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5125 | goto out; |
| 5126 | } |
| 5127 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5128 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5129 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5130 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5131 | free(curproxy->expect_regex); |
| 5132 | curproxy->expect_regex = NULL; |
| 5133 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5134 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5135 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5136 | error = NULL; |
| 5137 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5138 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5139 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5140 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5142 | goto out; |
| 5143 | } |
| 5144 | } |
| 5145 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5146 | if (!*(args[cur_arg + 1])) { |
| 5147 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5148 | file, linenum, args[0], args[1], ptr_arg); |
| 5149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5150 | goto out; |
| 5151 | } |
| 5152 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5153 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5154 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5155 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5156 | free(curproxy->expect_regex); |
| 5157 | curproxy->expect_regex = NULL; |
| 5158 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5159 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5160 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5161 | error = NULL; |
| 5162 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5163 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5164 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5165 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5167 | goto out; |
| 5168 | } |
| 5169 | } |
| 5170 | else { |
| 5171 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5172 | file, linenum, args[0], args[1], ptr_arg); |
| 5173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5174 | goto out; |
| 5175 | } |
| 5176 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5177 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5178 | Alert("parsing [%s:%d] : '%s' only supports 'disable-on-404', 'send-state', 'expect'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5180 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5181 | } |
| 5182 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5183 | else if (!strcmp(args[0], "tcp-check")) { |
| 5184 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5185 | err_code |= ERR_WARN; |
| 5186 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5187 | if (strcmp(args[1], "comment") == 0) { |
| 5188 | int cur_arg; |
| 5189 | struct tcpcheck_rule *tcpcheck; |
| 5190 | |
| 5191 | cur_arg = 1; |
| 5192 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5193 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5194 | |
| 5195 | if (!*args[cur_arg + 1]) { |
| 5196 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5197 | file, linenum, args[cur_arg]); |
| 5198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5199 | goto out; |
| 5200 | } |
| 5201 | |
| 5202 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5203 | |
| 5204 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5205 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5206 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5207 | } |
| 5208 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5209 | const char *ptr_arg; |
| 5210 | int cur_arg; |
| 5211 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5212 | |
| 5213 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5214 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5215 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5216 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5217 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5218 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5219 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5220 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5221 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5222 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5223 | file, linenum); |
| 5224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5225 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | cur_arg = 2; |
| 5229 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5230 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5231 | |
| 5232 | /* parsing each parameters to fill up the rule */ |
| 5233 | while (*(ptr_arg = args[cur_arg])) { |
| 5234 | /* tcp port */ |
| 5235 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5236 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5237 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5238 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5239 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5241 | goto out; |
| 5242 | } |
| 5243 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5244 | cur_arg += 2; |
| 5245 | } |
| 5246 | /* send proxy protocol */ |
| 5247 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5248 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5249 | cur_arg++; |
| 5250 | } |
| 5251 | #ifdef USE_OPENSSL |
| 5252 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5253 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5254 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5255 | cur_arg++; |
| 5256 | } |
| 5257 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5258 | /* comment for this tcpcheck line */ |
| 5259 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5260 | if (!*args[cur_arg + 1]) { |
| 5261 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5262 | file, linenum, args[cur_arg]); |
| 5263 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5264 | goto out; |
| 5265 | } |
| 5266 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5267 | cur_arg += 2; |
| 5268 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5269 | else { |
| 5270 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5271 | Alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or 'ssl' but got '%s' as argument.\n", |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5272 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5273 | Alert("parsing [%s:%d] : '%s %s' expects 'comment', 'port', 'send-proxy' or but got '%s' as argument.\n", |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5274 | #endif /* USE_OPENSSL */ |
| 5275 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5277 | goto out; |
| 5278 | } |
| 5279 | |
| 5280 | } |
| 5281 | |
| 5282 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5283 | } |
| 5284 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5285 | if (! *(args[2]) ) { |
| 5286 | /* SEND string expected */ |
| 5287 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5288 | file, linenum, args[0], args[1], args[2]); |
| 5289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5290 | goto out; |
| 5291 | } else { |
| 5292 | struct tcpcheck_rule *tcpcheck; |
| 5293 | |
| 5294 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5295 | |
| 5296 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5297 | tcpcheck->string_len = strlen(args[2]); |
| 5298 | tcpcheck->string = strdup(args[2]); |
| 5299 | tcpcheck->expect_regex = NULL; |
| 5300 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5301 | /* comment for this tcpcheck line */ |
| 5302 | if (strcmp(args[3], "comment") == 0) { |
| 5303 | if (!*args[4]) { |
| 5304 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5305 | file, linenum, args[3]); |
| 5306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5307 | goto out; |
| 5308 | } |
| 5309 | tcpcheck->comment = strdup(args[4]); |
| 5310 | } |
| 5311 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5312 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5313 | } |
| 5314 | } |
| 5315 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5316 | if (! *(args[2]) ) { |
| 5317 | /* SEND binary string expected */ |
| 5318 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5319 | file, linenum, args[0], args[1], args[2]); |
| 5320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5321 | goto out; |
| 5322 | } else { |
| 5323 | struct tcpcheck_rule *tcpcheck; |
| 5324 | char *err = NULL; |
| 5325 | |
| 5326 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5327 | |
| 5328 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5329 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5330 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5331 | file, linenum, args[0], args[1], args[2], err); |
| 5332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5333 | goto out; |
| 5334 | } |
| 5335 | tcpcheck->expect_regex = NULL; |
| 5336 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5337 | /* comment for this tcpcheck line */ |
| 5338 | if (strcmp(args[3], "comment") == 0) { |
| 5339 | if (!*args[4]) { |
| 5340 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5341 | file, linenum, args[3]); |
| 5342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5343 | goto out; |
| 5344 | } |
| 5345 | tcpcheck->comment = strdup(args[4]); |
| 5346 | } |
| 5347 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5348 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5349 | } |
| 5350 | } |
| 5351 | else if (strcmp(args[1], "expect") == 0) { |
| 5352 | const char *ptr_arg; |
| 5353 | int cur_arg; |
| 5354 | int inverse = 0; |
| 5355 | |
| 5356 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5357 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5359 | goto out; |
| 5360 | } |
| 5361 | |
| 5362 | cur_arg = 2; |
| 5363 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5364 | while (*(ptr_arg = args[cur_arg])) { |
| 5365 | while (*ptr_arg == '!') { |
| 5366 | inverse = !inverse; |
| 5367 | ptr_arg++; |
| 5368 | } |
| 5369 | if (*ptr_arg) |
| 5370 | break; |
| 5371 | cur_arg++; |
| 5372 | } |
| 5373 | /* now ptr_arg points to the beginning of a word past any possible |
| 5374 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5375 | */ |
| 5376 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5377 | struct tcpcheck_rule *tcpcheck; |
| 5378 | char *err = NULL; |
| 5379 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5380 | if (!*(args[cur_arg + 1])) { |
| 5381 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5382 | file, linenum, args[0], args[1], ptr_arg); |
| 5383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5384 | goto out; |
| 5385 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5386 | |
| 5387 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5388 | |
| 5389 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5390 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5391 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5392 | file, linenum, args[0], args[1], args[2], err); |
| 5393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5394 | goto out; |
| 5395 | } |
| 5396 | tcpcheck->expect_regex = NULL; |
| 5397 | tcpcheck->inverse = inverse; |
| 5398 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5399 | /* tcpcheck comment */ |
| 5400 | cur_arg += 2; |
| 5401 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5402 | if (!*args[cur_arg + 1]) { |
| 5403 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5404 | file, linenum, args[cur_arg + 1]); |
| 5405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5406 | goto out; |
| 5407 | } |
| 5408 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5409 | } |
| 5410 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5411 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5412 | } |
| 5413 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5414 | struct tcpcheck_rule *tcpcheck; |
| 5415 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5416 | if (!*(args[cur_arg + 1])) { |
| 5417 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5418 | file, linenum, args[0], args[1], ptr_arg); |
| 5419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5420 | goto out; |
| 5421 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5422 | |
| 5423 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5424 | |
| 5425 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5426 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5427 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5428 | tcpcheck->expect_regex = NULL; |
| 5429 | tcpcheck->inverse = inverse; |
| 5430 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5431 | /* tcpcheck comment */ |
| 5432 | cur_arg += 2; |
| 5433 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5434 | if (!*args[cur_arg + 1]) { |
| 5435 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5436 | file, linenum, args[cur_arg + 1]); |
| 5437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5438 | goto out; |
| 5439 | } |
| 5440 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5441 | } |
| 5442 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5443 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5444 | } |
| 5445 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5446 | struct tcpcheck_rule *tcpcheck; |
| 5447 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5448 | if (!*(args[cur_arg + 1])) { |
| 5449 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5450 | file, linenum, args[0], args[1], ptr_arg); |
| 5451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5452 | goto out; |
| 5453 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5454 | |
| 5455 | tcpcheck = (struct tcpcheck_rule *)calloc(1, sizeof(*tcpcheck)); |
| 5456 | |
| 5457 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5458 | tcpcheck->string_len = 0; |
| 5459 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5460 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5461 | error = NULL; |
| 5462 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5463 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5464 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5465 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5467 | goto out; |
| 5468 | } |
| 5469 | tcpcheck->inverse = inverse; |
| 5470 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5471 | /* tcpcheck comment */ |
| 5472 | cur_arg += 2; |
| 5473 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5474 | if (!*args[cur_arg + 1]) { |
| 5475 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5476 | file, linenum, args[cur_arg + 1]); |
| 5477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5478 | goto out; |
| 5479 | } |
| 5480 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5481 | } |
| 5482 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5483 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5484 | } |
| 5485 | else { |
| 5486 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5487 | file, linenum, args[0], args[1], ptr_arg); |
| 5488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5489 | goto out; |
| 5490 | } |
| 5491 | } |
| 5492 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5493 | Alert("parsing [%s:%d] : '%s' only supports 'comment', 'connect', 'send' or 'expect'.\n", file, linenum, args[0]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5495 | goto out; |
| 5496 | } |
| 5497 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5498 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5499 | if (curproxy == &defproxy) { |
| 5500 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5502 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5503 | } |
| 5504 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5505 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5506 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5507 | |
| 5508 | if (strcmp(args[1], "fail") == 0) { |
| 5509 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5510 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5511 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5512 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5514 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5515 | } |
| 5516 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5517 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5518 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5519 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5521 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5522 | } |
| 5523 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5524 | } |
| 5525 | else { |
| 5526 | Alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5528 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5529 | } |
| 5530 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5531 | #ifdef TPROXY |
| 5532 | else if (!strcmp(args[0], "transparent")) { |
| 5533 | /* enable transparent proxy connections */ |
| 5534 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5535 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5537 | } |
| 5538 | #endif |
| 5539 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5540 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5541 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5542 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5543 | if (*(args[1]) == 0) { |
| 5544 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5546 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5547 | } |
| 5548 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5549 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5551 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5552 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5553 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5554 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5555 | |
| 5556 | if (*(args[1]) == 0) { |
| 5557 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5559 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5560 | } |
| 5561 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5562 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5563 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5564 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5565 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5566 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5567 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5568 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5569 | if (*(args[1]) == 0) { |
| 5570 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5572 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5573 | } |
| 5574 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5575 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5576 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5577 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5578 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5579 | if (*(args[1]) == 0) { |
| 5580 | Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5582 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5583 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5584 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5585 | if (err) { |
| 5586 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5587 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5588 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5589 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5590 | } |
| 5591 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5592 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5593 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5594 | } |
| 5595 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5596 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5597 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5598 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5599 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5600 | if (curproxy == &defproxy) { |
| 5601 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5603 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5604 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5605 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5606 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5607 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5608 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5609 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5610 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5611 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5612 | goto out; |
| 5613 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5614 | |
| 5615 | proto = protocol_by_family(sk->ss_family); |
| 5616 | if (!proto || !proto->connect) { |
| 5617 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5618 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5620 | goto out; |
| 5621 | } |
| 5622 | |
| 5623 | if (port1 != port2) { |
| 5624 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5625 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5628 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5629 | |
| 5630 | if (!port1) { |
| 5631 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5632 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5634 | goto out; |
| 5635 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5636 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5637 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5638 | goto out; |
| 5639 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5640 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5641 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5642 | } |
| 5643 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5644 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5645 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5646 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5647 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5648 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5650 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5651 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5652 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5653 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5654 | /** |
| 5655 | * The syntax for hash-type config element is |
| 5656 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5657 | * |
| 5658 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5659 | */ |
| 5660 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5661 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5662 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5663 | err_code |= ERR_WARN; |
| 5664 | |
| 5665 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5666 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5667 | } |
| 5668 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5669 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5670 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5671 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5672 | 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]); |
| 5673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5674 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5675 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5676 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5677 | Alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5679 | goto out; |
| 5680 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5681 | |
| 5682 | /* set the hash function to use */ |
| 5683 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5684 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5685 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5686 | |
| 5687 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5688 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5689 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5690 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5691 | /* set the hash function */ |
| 5692 | if (!strcmp(args[2], "sdbm")) { |
| 5693 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5694 | } |
| 5695 | else if (!strcmp(args[2], "djb2")) { |
| 5696 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5697 | } |
| 5698 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5699 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5700 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5701 | else if (!strcmp(args[2], "crc32")) { |
| 5702 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5703 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5704 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5705 | Alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5707 | goto out; |
| 5708 | } |
| 5709 | |
| 5710 | /* set the hash modifier */ |
| 5711 | if (!strcmp(args[3], "avalanche")) { |
| 5712 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5713 | } |
| 5714 | else if (*args[3]) { |
| 5715 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5717 | goto out; |
| 5718 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5719 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5720 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5721 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5722 | if (!*(args[1])) { |
| 5723 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5725 | goto out; |
| 5726 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5727 | if (*(args[2])) { |
| 5728 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5730 | goto out; |
| 5731 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5732 | free(curproxy->conf.uniqueid_format_string); |
| 5733 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5734 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5735 | free(curproxy->conf.uif_file); |
| 5736 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5737 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5738 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5739 | |
| 5740 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5741 | if (!*(args[1])) { |
| 5742 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5744 | goto out; |
| 5745 | } |
| 5746 | free(curproxy->header_unique_id); |
| 5747 | curproxy->header_unique_id = strdup(args[1]); |
| 5748 | } |
| 5749 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5750 | else if (strcmp(args[0], "log-format") == 0) { |
| 5751 | if (!*(args[1])) { |
| 5752 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5754 | goto out; |
| 5755 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5756 | if (*(args[2])) { |
| 5757 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5759 | goto out; |
| 5760 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 5761 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5762 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 5763 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 5764 | curproxy->conf.logformat_string != clf_http_log_format) |
| 5765 | free(curproxy->conf.logformat_string); |
| 5766 | curproxy->conf.logformat_string = strdup(args[1]); |
| 5767 | |
| 5768 | free(curproxy->conf.lfs_file); |
| 5769 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 5770 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5771 | |
| 5772 | /* get a chance to improve log-format error reporting by |
| 5773 | * reporting the correct line-number when possible. |
| 5774 | */ |
| 5775 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5776 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 5777 | file, linenum, curproxy->id); |
| 5778 | err_code |= ERR_WARN; |
| 5779 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5780 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 5781 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 5782 | if (*(args[1]) == 0) { |
| 5783 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 5784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5785 | goto out; |
| 5786 | } |
| 5787 | free(curproxy->log_tag); |
| 5788 | curproxy->log_tag = strdup(args[1]); |
| 5789 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5790 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 5791 | /* delete previous herited or defined syslog servers */ |
| 5792 | struct logsrv *back; |
| 5793 | |
| 5794 | if (*(args[1]) != 0) { |
| 5795 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 5796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5797 | goto out; |
| 5798 | } |
| 5799 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5800 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 5801 | LIST_DEL(&tmplogsrv->list); |
| 5802 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5803 | } |
| 5804 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5805 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5806 | struct logsrv *logsrv; |
| 5807 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5808 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5809 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5810 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5811 | struct logsrv *node = malloc(sizeof(struct logsrv)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5812 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5813 | LIST_INIT(&node->list); |
| 5814 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 5815 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5816 | } |
| 5817 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5818 | struct sockaddr_storage *sk; |
| 5819 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5820 | int arg = 0; |
| 5821 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5822 | |
| 5823 | logsrv = calloc(1, sizeof(struct logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5824 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5825 | /* just after the address, a length may be specified */ |
| 5826 | if (strcmp(args[arg+2], "len") == 0) { |
| 5827 | len = atoi(args[arg+3]); |
| 5828 | if (len < 80 || len > 65535) { |
| 5829 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 5830 | file, linenum, args[arg+3]); |
| 5831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5832 | goto out; |
| 5833 | } |
| 5834 | logsrv->maxlen = len; |
| 5835 | |
| 5836 | /* skip these two args */ |
| 5837 | arg += 2; |
| 5838 | } |
| 5839 | else |
| 5840 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 5841 | |
| 5842 | if (logsrv->maxlen > global.max_syslog_len) { |
| 5843 | global.max_syslog_len = logsrv->maxlen; |
| 5844 | logline = realloc(logline, global.max_syslog_len + 1); |
| 5845 | } |
| 5846 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5847 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 5848 | goto out; |
| 5849 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5850 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5851 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5852 | Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5854 | goto out; |
| 5855 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5856 | } |
| 5857 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5858 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5859 | if (*(args[arg+3])) { |
| 5860 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5861 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5862 | Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5864 | goto out; |
| 5865 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5869 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5870 | if (*(args[arg+4])) { |
| 5871 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 5872 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5873 | Alert("parsing [%s:%d] : unknown optional minimum log level '%s'\n", file, linenum, args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5874 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5875 | goto out; |
| 5876 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 5877 | } |
| 5878 | } |
| 5879 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5880 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5881 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5882 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5883 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5884 | goto out; |
| 5885 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5886 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5887 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5888 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5889 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5890 | if (port1 != port2) { |
| 5891 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5892 | file, linenum, args[0], args[1]); |
| 5893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5894 | goto out; |
| 5895 | } |
| 5896 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5897 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5898 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5899 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5900 | |
| 5901 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5902 | } |
| 5903 | else { |
| 5904 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 5905 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5907 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */ |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5911 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5912 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5913 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5914 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5915 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5916 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5917 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5918 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5919 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5920 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 5921 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5923 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5924 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5925 | |
| 5926 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5927 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5928 | free(curproxy->conn_src.iface_name); |
| 5929 | curproxy->conn_src.iface_name = NULL; |
| 5930 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 5931 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5932 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5933 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5934 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5935 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5936 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5937 | goto out; |
| 5938 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 5939 | |
| 5940 | proto = protocol_by_family(sk->ss_family); |
| 5941 | if (!proto || !proto->connect) { |
| 5942 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5943 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5945 | goto out; |
| 5946 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5947 | |
| 5948 | if (port1 != port2) { |
| 5949 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 5950 | file, linenum, args[0], args[1]); |
| 5951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5952 | goto out; |
| 5953 | } |
| 5954 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5955 | curproxy->conn_src.source_addr = *sk; |
| 5956 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5957 | |
| 5958 | cur_arg = 2; |
| 5959 | while (*(args[cur_arg])) { |
| 5960 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 5961 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
| 5962 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | 9cf8d3f | 2014-05-09 22:56:10 +0200 | [diff] [blame] | 5963 | if (!is_inet_addr(&curproxy->conn_src.source_addr)) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5964 | Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n", |
| 5965 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5967 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5968 | } |
| 5969 | #endif |
| 5970 | if (!*args[cur_arg + 1]) { |
| 5971 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 5972 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5974 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5975 | } |
| 5976 | |
| 5977 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5978 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5979 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 5980 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5981 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5982 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 5983 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 5984 | char *name, *end; |
| 5985 | |
| 5986 | name = args[cur_arg+1] + 7; |
| 5987 | while (isspace(*name)) |
| 5988 | name++; |
| 5989 | |
| 5990 | end = name; |
| 5991 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 5992 | end++; |
| 5993 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 5994 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 5995 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 5996 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 5997 | curproxy->conn_src.bind_hdr_len = end - name; |
| 5998 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 5999 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6000 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6001 | |
| 6002 | /* now look for an occurrence number */ |
| 6003 | while (isspace(*end)) |
| 6004 | end++; |
| 6005 | if (*end == ',') { |
| 6006 | end++; |
| 6007 | name = end; |
| 6008 | if (*end == '-') |
| 6009 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6010 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6011 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6012 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6015 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6016 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6017 | " occurrences values smaller than %d.\n", |
| 6018 | file, linenum, MAX_HDR_HISTORY); |
| 6019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6020 | goto out; |
| 6021 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6022 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6023 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6024 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6025 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6026 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6027 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6028 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6029 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6030 | goto out; |
| 6031 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6032 | |
| 6033 | proto = protocol_by_family(sk->ss_family); |
| 6034 | if (!proto || !proto->connect) { |
| 6035 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6036 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6038 | goto out; |
| 6039 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6040 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6041 | if (port1 != port2) { |
| 6042 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6043 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6045 | goto out; |
| 6046 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6047 | curproxy->conn_src.tproxy_addr = *sk; |
| 6048 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6049 | } |
| 6050 | global.last_checks |= LSTCHK_NETADM; |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 6051 | #if !defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6052 | global.last_checks |= LSTCHK_CTTPROXY; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6053 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6054 | #else /* no TPROXY support */ |
| 6055 | Alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6056 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6058 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6059 | #endif |
| 6060 | cur_arg += 2; |
| 6061 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6062 | } |
| 6063 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6064 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6065 | #ifdef SO_BINDTODEVICE |
| 6066 | if (!*args[cur_arg + 1]) { |
| 6067 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6068 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6070 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6071 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6072 | free(curproxy->conn_src.iface_name); |
| 6073 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6074 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6075 | global.last_checks |= LSTCHK_NETADM; |
| 6076 | #else |
| 6077 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6078 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6080 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6081 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6082 | cur_arg += 2; |
| 6083 | continue; |
| 6084 | } |
| 6085 | Alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
Willy Tarreau | 3631d41 | 2012-09-25 16:31:00 +0200 | [diff] [blame] | 6086 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6088 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6089 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6090 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6091 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6092 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6093 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6095 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6096 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6097 | else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6098 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6099 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6100 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6103 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6104 | |
| 6105 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6106 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6107 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6108 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6110 | } |
| 6111 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6112 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6113 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6114 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6115 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6116 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6117 | } |
| 6118 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6119 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6120 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6121 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6122 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6124 | } |
| 6125 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6126 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6127 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6128 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6129 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6130 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6131 | } |
| 6132 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6133 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6134 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6135 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6136 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6137 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6138 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6139 | else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6140 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6141 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6142 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6143 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6144 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6145 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6146 | else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6147 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6148 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6149 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6151 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6152 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6153 | |
| 6154 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6155 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6156 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6157 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6158 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6159 | } |
| 6160 | else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6161 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6162 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6163 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6164 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6165 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6166 | } |
| 6167 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6168 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6169 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6170 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6171 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6172 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6173 | } |
| 6174 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6175 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6176 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6177 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6178 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6179 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6180 | } |
| 6181 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6182 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6183 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6184 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6185 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6187 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6188 | else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6189 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6190 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6191 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6192 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6193 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6194 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6195 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6196 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6197 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6198 | if (curproxy == &defproxy) { |
| 6199 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6202 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6203 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6204 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6205 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6206 | if (*(args[1]) == 0) { |
| 6207 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6209 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6210 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6211 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6212 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6213 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6214 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6215 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6217 | goto out; |
| 6218 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6219 | err_code |= warnif_cond_conflicts(cond, |
| 6220 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6221 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6222 | } |
| 6223 | else if (*args[2]) { |
| 6224 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6225 | file, linenum, args[0], args[2]); |
| 6226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6227 | goto out; |
| 6228 | } |
| 6229 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6230 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6231 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6232 | wl->s = strdup(args[1]); |
| 6233 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6234 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6235 | } |
| 6236 | else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6237 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6238 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6239 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6242 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6243 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6244 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6245 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6246 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6247 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6249 | } |
| 6250 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6251 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6252 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6253 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6254 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6255 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6256 | } |
| 6257 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6258 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6259 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6260 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6261 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6262 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6263 | } |
| 6264 | else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6265 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6266 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6267 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6269 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6270 | } |
| 6271 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6272 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6273 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6274 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6275 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6276 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6277 | } |
| 6278 | else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6279 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6280 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6281 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6282 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6284 | } |
| 6285 | else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6286 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6287 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6288 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6289 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6290 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6291 | } |
| 6292 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6293 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6294 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6295 | if (curproxy == &defproxy) { |
| 6296 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6298 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6299 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6300 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6301 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6302 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6303 | if (*(args[1]) == 0) { |
| 6304 | Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6306 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6307 | } |
| 6308 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6309 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6310 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6311 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6312 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6314 | goto out; |
| 6315 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6316 | err_code |= warnif_cond_conflicts(cond, |
| 6317 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6318 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6319 | } |
| 6320 | else if (*args[2]) { |
| 6321 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6322 | file, linenum, args[0], args[2]); |
| 6323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6324 | goto out; |
| 6325 | } |
| 6326 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6327 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6328 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6329 | wl->s = strdup(args[1]); |
| 6330 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6331 | } |
| 6332 | else if (!strcmp(args[0], "errorloc") || |
| 6333 | !strcmp(args[0], "errorloc302") || |
| 6334 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6335 | int errnum, errlen; |
| 6336 | char *err; |
| 6337 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6338 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6339 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6340 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6341 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6342 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6344 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | errnum = atol(args[1]); |
| 6348 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6349 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6350 | err = malloc(errlen); |
| 6351 | errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_303, args[2]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6352 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6353 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6354 | err = malloc(errlen); |
| 6355 | errlen = snprintf(err, errlen, "%s%s\r\n\r\n", HTTP_302, args[2]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6356 | } |
| 6357 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6358 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6359 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6360 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6361 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6362 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6363 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6364 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6365 | |
| 6366 | if (rc >= HTTP_ERR_SIZE) { |
| 6367 | Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n", |
| 6368 | file, linenum, errnum); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6369 | free(err); |
| 6370 | } |
| 6371 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6372 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6373 | int errnum, errlen, fd; |
| 6374 | char *err; |
| 6375 | struct stat stat; |
| 6376 | |
| 6377 | if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6378 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6379 | |
| 6380 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6381 | Alert("parsing [%s:%d] : <%s> expects <status_code> and <file> as arguments.\n", file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6383 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | fd = open(args[2], O_RDONLY); |
| 6387 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6388 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6389 | file, linenum, args[2], args[1]); |
| 6390 | if (fd >= 0) |
| 6391 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6393 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6394 | } |
| 6395 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6396 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6397 | errlen = stat.st_size; |
| 6398 | } else { |
| 6399 | Warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6400 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6401 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6402 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6406 | errnum = read(fd, err, errlen); |
| 6407 | if (errnum != errlen) { |
| 6408 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6409 | file, linenum, args[2], args[1]); |
| 6410 | close(fd); |
| 6411 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6413 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6414 | } |
| 6415 | close(fd); |
| 6416 | |
| 6417 | errnum = atol(args[1]); |
| 6418 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6419 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6420 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6421 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6422 | break; |
| 6423 | } |
| 6424 | } |
| 6425 | |
| 6426 | if (rc >= HTTP_ERR_SIZE) { |
| 6427 | Warning("parsing [%s:%d] : status code %d not handled, error customization will be ignored.\n", |
| 6428 | file, linenum, errnum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6429 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6430 | free(err); |
| 6431 | } |
| 6432 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6433 | else if (!strcmp(args[0], "compression")) { |
| 6434 | struct comp *comp; |
| 6435 | if (curproxy->comp == NULL) { |
| 6436 | comp = calloc(1, sizeof(struct comp)); |
| 6437 | curproxy->comp = comp; |
| 6438 | } else { |
| 6439 | comp = curproxy->comp; |
| 6440 | } |
| 6441 | |
| 6442 | if (!strcmp(args[1], "algo")) { |
| 6443 | int cur_arg; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 6444 | struct comp_ctx *ctx; |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 6445 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6446 | cur_arg = 2; |
| 6447 | if (!*args[cur_arg]) { |
| 6448 | Alert("parsing [%s:%d] : '%s' expects <algorithm>\n", |
| 6449 | file, linenum, args[0]); |
| 6450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6451 | goto out; |
| 6452 | } |
| 6453 | while (*(args[cur_arg])) { |
| 6454 | if (comp_append_algo(comp, args[cur_arg]) < 0) { |
| 6455 | Alert("parsing [%s:%d] : '%s' : '%s' is not a supported algorithm.\n", |
| 6456 | file, linenum, args[0], args[cur_arg]); |
| 6457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6458 | goto out; |
| 6459 | } |
William Lallemand | 552df67 | 2012-11-07 13:21:47 +0100 | [diff] [blame] | 6460 | if (curproxy->comp->algos->init(&ctx, 9) == 0) { |
| 6461 | curproxy->comp->algos->end(&ctx); |
| 6462 | } else { |
| 6463 | Alert("parsing [%s:%d] : '%s' : Can't init '%s' algorithm.\n", |
| 6464 | file, linenum, args[0], args[cur_arg]); |
| 6465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6466 | goto out; |
| 6467 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6468 | cur_arg ++; |
| 6469 | continue; |
| 6470 | } |
| 6471 | } |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 6472 | else if (!strcmp(args[1], "offload")) { |
| 6473 | comp->offload = 1; |
| 6474 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6475 | else if (!strcmp(args[1], "type")) { |
| 6476 | int cur_arg; |
| 6477 | cur_arg = 2; |
| 6478 | if (!*args[cur_arg]) { |
| 6479 | Alert("parsing [%s:%d] : '%s' expects <type>\n", |
| 6480 | file, linenum, args[0]); |
| 6481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6482 | goto out; |
| 6483 | } |
| 6484 | while (*(args[cur_arg])) { |
| 6485 | comp_append_type(comp, args[cur_arg]); |
| 6486 | cur_arg ++; |
| 6487 | continue; |
| 6488 | } |
| 6489 | } |
| 6490 | else { |
Willy Tarreau | 70737d1 | 2012-10-27 00:34:28 +0200 | [diff] [blame] | 6491 | Alert("parsing [%s:%d] : '%s' expects 'algo', 'type' or 'offload'\n", |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6492 | file, linenum, args[0]); |
| 6493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6494 | goto out; |
| 6495 | } |
| 6496 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6497 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6498 | struct cfg_kw_list *kwl; |
| 6499 | int index; |
| 6500 | |
| 6501 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6502 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6503 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6504 | continue; |
| 6505 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6506 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6507 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg); |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6508 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6509 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6511 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6512 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6513 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6514 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6515 | err_code |= ERR_WARN; |
| 6516 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6517 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6518 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6519 | } |
| 6520 | } |
| 6521 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6522 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6523 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6525 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6526 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6527 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6528 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6529 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6530 | } |
| 6531 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6532 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6533 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6534 | { |
| 6535 | #ifdef CONFIG_HAP_NS |
| 6536 | const char *err; |
| 6537 | const char *item = args[0]; |
| 6538 | |
| 6539 | if (!strcmp(item, "namespace_list")) { |
| 6540 | return 0; |
| 6541 | } |
| 6542 | else if (!strcmp(item, "namespace")) { |
| 6543 | size_t idx = 1; |
| 6544 | const char *current; |
| 6545 | while (*(current = args[idx++])) { |
| 6546 | err = invalid_char(current); |
| 6547 | if (err) { |
| 6548 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6549 | file, linenum, *err, item, current); |
| 6550 | return ERR_ALERT | ERR_FATAL; |
| 6551 | } |
| 6552 | |
| 6553 | if (netns_store_lookup(current, strlen(current))) { |
| 6554 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6555 | file, linenum, current); |
| 6556 | return ERR_ALERT | ERR_FATAL; |
| 6557 | } |
| 6558 | if (!netns_store_insert(current)) { |
| 6559 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6560 | file, linenum, current); |
| 6561 | return ERR_ALERT | ERR_FATAL; |
| 6562 | } |
| 6563 | } |
| 6564 | } |
| 6565 | |
| 6566 | return 0; |
| 6567 | #else |
| 6568 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6569 | file, linenum); |
| 6570 | return ERR_ALERT | ERR_FATAL; |
| 6571 | #endif |
| 6572 | } |
| 6573 | |
| 6574 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6575 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6576 | { |
| 6577 | |
| 6578 | int err_code = 0; |
| 6579 | const char *err; |
| 6580 | |
| 6581 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6582 | struct userlist *newul; |
| 6583 | |
| 6584 | if (!*args[1]) { |
| 6585 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6586 | file, linenum, args[0]); |
| 6587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6588 | goto out; |
| 6589 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6590 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6591 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6592 | |
| 6593 | err = invalid_char(args[1]); |
| 6594 | if (err) { |
| 6595 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6596 | file, linenum, *err, args[0], args[1]); |
| 6597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6598 | goto out; |
| 6599 | } |
| 6600 | |
| 6601 | for (newul = userlist; newul; newul = newul->next) |
| 6602 | if (!strcmp(newul->name, args[1])) { |
| 6603 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6604 | file, linenum, args[1]); |
| 6605 | err_code |= ERR_WARN; |
| 6606 | goto out; |
| 6607 | } |
| 6608 | |
| 6609 | newul = (struct userlist *)calloc(1, sizeof(struct userlist)); |
| 6610 | if (!newul) { |
| 6611 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6612 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6613 | goto out; |
| 6614 | } |
| 6615 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6616 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6617 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6618 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6619 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6620 | goto out; |
| 6621 | } |
| 6622 | |
| 6623 | newul->next = userlist; |
| 6624 | userlist = newul; |
| 6625 | |
| 6626 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6627 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6628 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6629 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6630 | |
| 6631 | if (!*args[1]) { |
| 6632 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6633 | file, linenum, args[0]); |
| 6634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6635 | goto out; |
| 6636 | } |
| 6637 | |
| 6638 | err = invalid_char(args[1]); |
| 6639 | if (err) { |
| 6640 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6641 | file, linenum, *err, args[0], args[1]); |
| 6642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6643 | goto out; |
| 6644 | } |
| 6645 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6646 | if (!userlist) |
| 6647 | goto out; |
| 6648 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6649 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6650 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6651 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6652 | file, linenum, args[1], userlist->name); |
| 6653 | err_code |= ERR_ALERT; |
| 6654 | goto out; |
| 6655 | } |
| 6656 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6657 | ag = calloc(1, sizeof(*ag)); |
| 6658 | if (!ag) { |
| 6659 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6660 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6661 | goto out; |
| 6662 | } |
| 6663 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6664 | ag->name = strdup(args[1]); |
| 6665 | if (!ag) { |
| 6666 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6667 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6668 | goto out; |
| 6669 | } |
| 6670 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6671 | cur_arg = 2; |
| 6672 | |
| 6673 | while (*args[cur_arg]) { |
| 6674 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6675 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6676 | cur_arg += 2; |
| 6677 | continue; |
| 6678 | } else { |
| 6679 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6680 | file, linenum, args[0]); |
| 6681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6682 | goto out; |
| 6683 | } |
| 6684 | } |
| 6685 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6686 | ag->next = userlist->groups; |
| 6687 | userlist->groups = ag; |
| 6688 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6689 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6690 | struct auth_users *newuser; |
| 6691 | int cur_arg; |
| 6692 | |
| 6693 | if (!*args[1]) { |
| 6694 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6695 | file, linenum, args[0]); |
| 6696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6697 | goto out; |
| 6698 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6699 | if (!userlist) |
| 6700 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6701 | |
| 6702 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6703 | if (!strcmp(newuser->user, args[1])) { |
| 6704 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6705 | file, linenum, args[1], userlist->name); |
| 6706 | err_code |= ERR_ALERT; |
| 6707 | goto out; |
| 6708 | } |
| 6709 | |
| 6710 | newuser = (struct auth_users *)calloc(1, sizeof(struct auth_users)); |
| 6711 | if (!newuser) { |
| 6712 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6713 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6714 | goto out; |
| 6715 | } |
| 6716 | |
| 6717 | newuser->user = strdup(args[1]); |
| 6718 | |
| 6719 | newuser->next = userlist->users; |
| 6720 | userlist->users = newuser; |
| 6721 | |
| 6722 | cur_arg = 2; |
| 6723 | |
| 6724 | while (*args[cur_arg]) { |
| 6725 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6726 | #ifdef CONFIG_HAP_CRYPT |
| 6727 | if (!crypt("", args[cur_arg + 1])) { |
| 6728 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6729 | file, linenum, newuser->user); |
| 6730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6731 | goto out; |
| 6732 | } |
| 6733 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6734 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6735 | file, linenum); |
| 6736 | err_code |= ERR_ALERT; |
| 6737 | #endif |
| 6738 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6739 | cur_arg += 2; |
| 6740 | continue; |
| 6741 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6742 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6743 | newuser->flags |= AU_O_INSECURE; |
| 6744 | cur_arg += 2; |
| 6745 | continue; |
| 6746 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6747 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6748 | cur_arg += 2; |
| 6749 | continue; |
| 6750 | } else { |
| 6751 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6752 | file, linenum, args[0]); |
| 6753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6754 | goto out; |
| 6755 | } |
| 6756 | } |
| 6757 | } else { |
| 6758 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6760 | } |
| 6761 | |
| 6762 | out: |
| 6763 | return err_code; |
| 6764 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6765 | |
| 6766 | /* |
| 6767 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6768 | * Returns the error code, 0 if OK, or any combination of : |
| 6769 | * - ERR_ABORT: must abort ASAP |
| 6770 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6771 | * - ERR_WARN: a warning has been emitted |
| 6772 | * - ERR_ALERT: an alert has been emitted |
| 6773 | * Only the two first ones can stop processing, the two others are just |
| 6774 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6775 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 6776 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6777 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6778 | char *thisline; |
| 6779 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6780 | FILE *f; |
| 6781 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6782 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6783 | struct cfg_section *cs = NULL; |
| 6784 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6785 | int readbytes = 0; |
| 6786 | |
| 6787 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6788 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6789 | return -1; |
| 6790 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6791 | |
| 6792 | /* Register internal sections */ |
| 6793 | if (!cfg_register_section("listen", cfg_parse_listen) || |
| 6794 | !cfg_register_section("frontend", cfg_parse_listen) || |
| 6795 | !cfg_register_section("backend", cfg_parse_listen) || |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6796 | !cfg_register_section("defaults", cfg_parse_listen) || |
| 6797 | !cfg_register_section("global", cfg_parse_global) || |
| 6798 | !cfg_register_section("userlist", cfg_parse_users) || |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6799 | !cfg_register_section("peers", cfg_parse_peers) || |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 6800 | !cfg_register_section("mailers", cfg_parse_mailers) || |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 6801 | !cfg_register_section("namespace_list", cfg_parse_netns) || |
| 6802 | !cfg_register_section("resolvers", cfg_parse_resolvers)) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6803 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6804 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6805 | if ((f=fopen(file,"r")) == NULL) |
| 6806 | return -1; |
| 6807 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6808 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6809 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6810 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6811 | char *end; |
| 6812 | char *args[MAX_LINE_ARGS + 1]; |
| 6813 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6814 | int dquote = 0; /* double quote */ |
| 6815 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6816 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6817 | linenum++; |
| 6818 | |
| 6819 | end = line + strlen(line); |
| 6820 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6821 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6822 | /* Check if we reached the limit and the last char is not \n. |
| 6823 | * Watch out for the last line without the terminating '\n'! |
| 6824 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6825 | char *newline; |
| 6826 | int newlinesize = linesize * 2; |
| 6827 | |
| 6828 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 6829 | if (newline == NULL) { |
| 6830 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 6831 | file, linenum); |
| 6832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6833 | continue; |
| 6834 | } |
| 6835 | |
| 6836 | readbytes = linesize - 1; |
| 6837 | linesize = newlinesize; |
| 6838 | thisline = newline; |
| 6839 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6840 | } |
| 6841 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6842 | readbytes = 0; |
| 6843 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6844 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6845 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6846 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6847 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6848 | arg = 0; |
| 6849 | args[arg] = line; |
| 6850 | |
| 6851 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6852 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 6853 | if (dquote) |
| 6854 | dquote = 0; |
| 6855 | else |
| 6856 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 6857 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6858 | end--; |
| 6859 | } |
| 6860 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 6861 | if (squote) |
| 6862 | squote = 0; |
| 6863 | else |
| 6864 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 6865 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6866 | end--; |
| 6867 | } |
| 6868 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6869 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 6870 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 6871 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6872 | int skip = 0; |
| 6873 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 6874 | *line = line[1]; |
| 6875 | skip = 1; |
| 6876 | } |
| 6877 | else if (line[1] == 'r') { |
| 6878 | *line = '\r'; |
| 6879 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6880 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6881 | else if (line[1] == 'n') { |
| 6882 | *line = '\n'; |
| 6883 | skip = 1; |
| 6884 | } |
| 6885 | else if (line[1] == 't') { |
| 6886 | *line = '\t'; |
| 6887 | skip = 1; |
| 6888 | } |
| 6889 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6890 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6891 | unsigned char hex1, hex2; |
| 6892 | hex1 = toupper(line[2]) - '0'; |
| 6893 | hex2 = toupper(line[3]) - '0'; |
| 6894 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 6895 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 6896 | *line = (hex1<<4) + hex2; |
| 6897 | skip = 3; |
| 6898 | } |
| 6899 | else { |
| 6900 | Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6901 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6902 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6903 | } else if (line[1] == '"') { |
| 6904 | *line = '"'; |
| 6905 | skip = 1; |
| 6906 | } else if (line[1] == '\'') { |
| 6907 | *line = '\''; |
| 6908 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6909 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 6910 | *line = '$'; |
| 6911 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6912 | } |
| 6913 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 6914 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6915 | end -= skip; |
| 6916 | } |
| 6917 | line++; |
| 6918 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6919 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6920 | /* end of string, end of loop */ |
| 6921 | *line = 0; |
| 6922 | break; |
| 6923 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6924 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6925 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6926 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6927 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6928 | line++; |
| 6929 | args[++arg] = line; |
| 6930 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6931 | else if (dquote && *line == '$') { |
| 6932 | /* environment variables are evaluated inside double quotes */ |
| 6933 | char *var_beg; |
| 6934 | char *var_end; |
| 6935 | char save_char; |
| 6936 | char *value; |
| 6937 | int val_len; |
| 6938 | int newlinesize; |
| 6939 | int braces = 0; |
| 6940 | |
| 6941 | var_beg = line + 1; |
| 6942 | var_end = var_beg; |
| 6943 | |
| 6944 | if (*var_beg == '{') { |
| 6945 | var_beg++; |
| 6946 | var_end++; |
| 6947 | braces = 1; |
| 6948 | } |
| 6949 | |
| 6950 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 6951 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 6952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6953 | goto next_line; /* skip current line */ |
| 6954 | } |
| 6955 | |
| 6956 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 6957 | var_end++; |
| 6958 | |
| 6959 | save_char = *var_end; |
| 6960 | *var_end = '\0'; |
| 6961 | value = getenv(var_beg); |
| 6962 | *var_end = save_char; |
| 6963 | val_len = value ? strlen(value) : 0; |
| 6964 | |
| 6965 | if (braces) { |
| 6966 | if (*var_end == '}') { |
| 6967 | var_end++; |
| 6968 | braces = 0; |
| 6969 | } else { |
| 6970 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 6971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6972 | goto next_line; /* skip current line */ |
| 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 6977 | |
| 6978 | /* if not enough space in thisline */ |
| 6979 | if (newlinesize > linesize) { |
| 6980 | char *newline; |
| 6981 | |
| 6982 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 6983 | if (newline == NULL) { |
| 6984 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 6985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6986 | goto next_line; /* slip current line */ |
| 6987 | } |
| 6988 | /* recompute pointers if realloc returns a new pointer */ |
| 6989 | if (newline != thisline) { |
| 6990 | int i; |
| 6991 | int diff; |
| 6992 | |
| 6993 | for (i = 0; i <= arg; i++) { |
| 6994 | diff = args[i] - thisline; |
| 6995 | args[i] = newline + diff; |
| 6996 | } |
| 6997 | |
| 6998 | diff = var_end - thisline; |
| 6999 | var_end = newline + diff; |
| 7000 | diff = end - thisline; |
| 7001 | end = newline + diff; |
| 7002 | diff = line - thisline; |
| 7003 | line = newline + diff; |
| 7004 | thisline = newline; |
| 7005 | } |
| 7006 | linesize = newlinesize; |
| 7007 | } |
| 7008 | |
| 7009 | /* insert value inside the line */ |
| 7010 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7011 | memcpy(line, value, val_len); |
| 7012 | end += val_len - (var_end - line); |
| 7013 | line += val_len; |
| 7014 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7015 | else { |
| 7016 | line++; |
| 7017 | } |
| 7018 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7019 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7020 | if (dquote) { |
| 7021 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7023 | } |
| 7024 | |
| 7025 | if (squote) { |
| 7026 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7028 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7029 | |
| 7030 | /* empty line */ |
| 7031 | if (!**args) |
| 7032 | continue; |
| 7033 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7034 | if (*line) { |
| 7035 | /* we had to stop due to too many args. |
| 7036 | * Let's terminate the string, print the offending part then cut the |
| 7037 | * last arg. |
| 7038 | */ |
| 7039 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7040 | line++; |
| 7041 | *line = '\0'; |
| 7042 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7043 | Alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
Willy Tarreau | 3ccf94e | 2009-12-17 21:12:16 +0100 | [diff] [blame] | 7044 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7046 | args[arg] = line; |
| 7047 | } |
| 7048 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7049 | /* zero out remaining args and ensure that at least one entry |
| 7050 | * is zeroed out. |
| 7051 | */ |
| 7052 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7053 | args[arg] = line; |
| 7054 | } |
| 7055 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7056 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7057 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7058 | char *tmp; |
| 7059 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7060 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7061 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7062 | for (arg=0; *args[arg+1]; arg++) |
| 7063 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7064 | *tmp = '\0'; // fix the next arg to \0 |
| 7065 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7066 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7067 | else if (!strcmp(args[0], "default")) { |
| 7068 | kwm = KWM_DEF; |
| 7069 | for (arg=0; *args[arg+1]; arg++) |
| 7070 | args[arg] = args[arg+1]; // shift args after inversion |
| 7071 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7072 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7073 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7074 | strcmp(args[0], "log") != 0) { |
| 7075 | Alert("parsing [%s:%d]: negation/default currently supported only for options and log.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7076 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7077 | } |
| 7078 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7079 | /* detect section start */ |
| 7080 | list_for_each_entry(ics, §ions, list) { |
| 7081 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7082 | cursection = ics->section_name; |
| 7083 | cs = ics; |
| 7084 | break; |
| 7085 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7086 | } |
| 7087 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7088 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7089 | if (cs) |
| 7090 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7091 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7092 | Alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7093 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7094 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7095 | |
| 7096 | if (err_code & ERR_ABORT) |
| 7097 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7098 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7099 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7100 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7101 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7102 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7103 | } |
| 7104 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7105 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7106 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7107 | * bound to all of its processes. After that, if the target is a "listen" |
| 7108 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7109 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7110 | * checked first to ensure that <to> is already bound to all processes of |
| 7111 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7112 | * path to the destination. |
| 7113 | * |
| 7114 | * It is possible to set <to> to NULL for the first call so that the function |
| 7115 | * takes care of visiting the initial frontend in <from>. |
| 7116 | * |
| 7117 | * It is important to note that the function relies on the fact that all names |
| 7118 | * have already been resolved. |
| 7119 | */ |
| 7120 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7121 | { |
| 7122 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7123 | |
| 7124 | if (to) { |
| 7125 | /* check whether we need to go down */ |
| 7126 | if (from->bind_proc && |
| 7127 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7128 | return; |
| 7129 | |
| 7130 | if (!from->bind_proc && !to->bind_proc) |
| 7131 | return; |
| 7132 | |
| 7133 | to->bind_proc = from->bind_proc ? |
| 7134 | (to->bind_proc | from->bind_proc) : 0; |
| 7135 | |
| 7136 | /* now propagate down */ |
| 7137 | from = to; |
| 7138 | } |
| 7139 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7140 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7141 | return; |
| 7142 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7143 | if (from->state == PR_STSTOPPED) |
| 7144 | return; |
| 7145 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7146 | /* default_backend */ |
| 7147 | if (from->defbe.be) |
| 7148 | propagate_processes(from, from->defbe.be); |
| 7149 | |
| 7150 | /* use_backend */ |
| 7151 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7152 | if (rule->dynamic) |
| 7153 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7154 | to = rule->be.backend; |
| 7155 | propagate_processes(from, to); |
| 7156 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7157 | } |
| 7158 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7159 | /* |
| 7160 | * Returns the error code, 0 if OK, or any combination of : |
| 7161 | * - ERR_ABORT: must abort ASAP |
| 7162 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7163 | * - ERR_WARN: a warning has been emitted |
| 7164 | * - ERR_ALERT: an alert has been emitted |
| 7165 | * Only the two first ones can stop processing, the two others are just |
| 7166 | * indicators. |
| 7167 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7168 | int check_config_validity() |
| 7169 | { |
| 7170 | int cfgerr = 0; |
| 7171 | struct proxy *curproxy = NULL; |
| 7172 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7173 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7174 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7175 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7176 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7177 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7178 | /* |
| 7179 | * Now, check for the integrity of all that we have collected. |
| 7180 | */ |
| 7181 | |
| 7182 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7183 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7184 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7185 | if (!global.tune.max_http_hdr) |
| 7186 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7187 | |
| 7188 | if (!global.tune.cookie_len) |
| 7189 | global.tune.cookie_len = CAPTURE_LEN; |
| 7190 | |
| 7191 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7192 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7193 | /* Post initialisation of the users and groups lists. */ |
| 7194 | err_code = userlist_postinit(); |
| 7195 | if (err_code != ERR_NONE) |
| 7196 | goto out; |
| 7197 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7198 | /* first, we will invert the proxy list order */ |
| 7199 | curproxy = NULL; |
| 7200 | while (proxy) { |
| 7201 | struct proxy *next; |
| 7202 | |
| 7203 | next = proxy->next; |
| 7204 | proxy->next = curproxy; |
| 7205 | curproxy = proxy; |
| 7206 | if (!next) |
| 7207 | break; |
| 7208 | proxy = next; |
| 7209 | } |
| 7210 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7211 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7212 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7213 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7214 | struct sticking_rule *mrule; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7215 | struct tcp_rule *trule; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7216 | struct http_req_rule *hrqrule; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7217 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7218 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7219 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7220 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7221 | /* proxy ID not set, use automatic numbering with first |
| 7222 | * spare entry starting with next_pxid. |
| 7223 | */ |
| 7224 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7225 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7226 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7227 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7228 | next_pxid++; |
| 7229 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7230 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7231 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7232 | /* ensure we don't keep listeners uselessly bound */ |
| 7233 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7234 | free((void *)curproxy->table.peers.name); |
| 7235 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7236 | continue; |
| 7237 | } |
| 7238 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7239 | /* Check multi-process mode compatibility for the current proxy */ |
| 7240 | |
| 7241 | if (curproxy->bind_proc) { |
| 7242 | /* an explicit bind-process was specified, let's check how many |
| 7243 | * processes remain. |
| 7244 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7245 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7246 | |
| 7247 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7248 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7249 | 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); |
| 7250 | curproxy->bind_proc = 1; |
| 7251 | } |
| 7252 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7253 | 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); |
| 7254 | curproxy->bind_proc = 0; |
| 7255 | } |
| 7256 | } |
| 7257 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7258 | /* check and reduce the bind-proc of each listener */ |
| 7259 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7260 | unsigned long mask; |
| 7261 | |
| 7262 | if (!bind_conf->bind_proc) |
| 7263 | continue; |
| 7264 | |
| 7265 | mask = nbits(global.nbproc); |
| 7266 | if (curproxy->bind_proc) |
| 7267 | mask &= curproxy->bind_proc; |
| 7268 | /* mask cannot be null here thanks to the previous checks */ |
| 7269 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7270 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7271 | bind_conf->bind_proc &= mask; |
| 7272 | |
| 7273 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7274 | 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", |
| 7275 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7276 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7277 | } |
| 7278 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7279 | 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", |
| 7280 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7281 | bind_conf->bind_proc = 0; |
| 7282 | } |
| 7283 | } |
| 7284 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7285 | switch (curproxy->mode) { |
| 7286 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7287 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7288 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7289 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7290 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7291 | cfgerr++; |
| 7292 | } |
| 7293 | |
| 7294 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7295 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7296 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7297 | break; |
| 7298 | |
| 7299 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7300 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7301 | break; |
| 7302 | |
| 7303 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7304 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7305 | break; |
| 7306 | } |
| 7307 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7308 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7309 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7310 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7311 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7312 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7313 | cfgerr++; |
| 7314 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7315 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7316 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7317 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7318 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7319 | cfgerr++; |
| 7320 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7321 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7322 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7323 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7324 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7325 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7326 | } |
| 7327 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7328 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH | PR_O_HTTP_PROXY))) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7329 | /* If no LB algo is set in a backend, and we're not in |
| 7330 | * transparent mode, dispatch mode nor proxy mode, we |
| 7331 | * want to use balance roundrobin by default. |
| 7332 | */ |
| 7333 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7334 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7335 | } |
| 7336 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7337 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7338 | if (curproxy->options & PR_O_DISPATCH) |
| 7339 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7340 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7341 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7342 | else if (curproxy->options & PR_O_TRANSP) |
| 7343 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7344 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7345 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7346 | if (curproxy->options & PR_O_DISABLE404) { |
| 7347 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7348 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7349 | err_code |= ERR_WARN; |
| 7350 | curproxy->options &= ~PR_O_DISABLE404; |
| 7351 | } |
| 7352 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7353 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7354 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7355 | err_code |= ERR_WARN; |
| 7356 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7357 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7358 | } |
| 7359 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7360 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7361 | if (!global.external_check) { |
| 7362 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7363 | curproxy->id, "option external-check"); |
| 7364 | cfgerr++; |
| 7365 | } |
| 7366 | if (!curproxy->check_command) { |
| 7367 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7368 | curproxy->id, "option external-check"); |
| 7369 | cfgerr++; |
| 7370 | } |
| 7371 | } |
| 7372 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7373 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7374 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7375 | Warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of " |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7376 | "'email-alert from', 'email-alert level' 'email-alert mailer', " |
| 7377 | "'email-alert hostname', or 'email-alert to' " |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7378 | "requrires each of 'email-alert from', 'email-alert mailer' and 'email-alert' " |
| 7379 | "to be present).\n", |
| 7380 | proxy_type_str(curproxy), curproxy->id); |
| 7381 | err_code |= ERR_WARN; |
| 7382 | free_email_alert(curproxy); |
| 7383 | } |
| 7384 | if (!curproxy->email_alert.myhostname) |
| 7385 | curproxy->email_alert.myhostname = hostname; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7386 | } |
| 7387 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7388 | if (curproxy->check_command) { |
| 7389 | int clear = 0; |
| 7390 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7391 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7392 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7393 | err_code |= ERR_WARN; |
| 7394 | clear = 1; |
| 7395 | } |
| 7396 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
| 7397 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-command path' is not set.\n", |
| 7398 | curproxy->id, "external-check command"); |
| 7399 | cfgerr++; |
| 7400 | } |
| 7401 | if (clear) { |
| 7402 | free(curproxy->check_command); |
| 7403 | curproxy->check_command = NULL; |
| 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | if (curproxy->check_path) { |
| 7408 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7409 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7410 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7411 | err_code |= ERR_WARN; |
| 7412 | free(curproxy->check_path); |
| 7413 | curproxy->check_path = NULL; |
| 7414 | } |
| 7415 | } |
| 7416 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7417 | /* if a default backend was specified, let's find it */ |
| 7418 | if (curproxy->defbe.name) { |
| 7419 | struct proxy *target; |
| 7420 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7421 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7422 | if (!target) { |
| 7423 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7424 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7425 | cfgerr++; |
| 7426 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7427 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7428 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7429 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7430 | } else if (target->mode != curproxy->mode && |
| 7431 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7432 | |
| 7433 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7434 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7435 | curproxy->conf.file, curproxy->conf.line, |
| 7436 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7437 | target->conf.file, target->conf.line); |
| 7438 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7439 | } else { |
| 7440 | free(curproxy->defbe.name); |
| 7441 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7442 | |
| 7443 | /* Emit a warning if this proxy also has some servers */ |
| 7444 | if (curproxy->srv) { |
| 7445 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7446 | curproxy->id); |
| 7447 | err_code |= ERR_WARN; |
| 7448 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7449 | } |
| 7450 | } |
| 7451 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7452 | /* find the target proxy for 'use_backend' rules */ |
| 7453 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7454 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7455 | struct logformat_node *node; |
| 7456 | char *pxname; |
| 7457 | |
| 7458 | /* Try to parse the string as a log format expression. If the result |
| 7459 | * of the parsing is only one entry containing a simple string, then |
| 7460 | * it's a standard string corresponding to a static rule, thus the |
| 7461 | * parsing is cancelled and be.name is restored to be resolved. |
| 7462 | */ |
| 7463 | pxname = rule->be.name; |
| 7464 | LIST_INIT(&rule->be.expr); |
| 7465 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 7466 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 7467 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7468 | |
| 7469 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7470 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7471 | rule->dynamic = 1; |
| 7472 | free(pxname); |
| 7473 | continue; |
| 7474 | } |
| 7475 | /* simple string: free the expression and fall back to static rule */ |
| 7476 | free(node->arg); |
| 7477 | free(node); |
| 7478 | } |
| 7479 | |
| 7480 | rule->dynamic = 0; |
| 7481 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7482 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7483 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7484 | if (!target) { |
| 7485 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7486 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7487 | cfgerr++; |
| 7488 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7489 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7490 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7491 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7492 | } else if (target->mode != curproxy->mode && |
| 7493 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7494 | |
| 7495 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7496 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7497 | curproxy->conf.file, curproxy->conf.line, |
| 7498 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7499 | target->conf.file, target->conf.line); |
| 7500 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7501 | } else { |
| 7502 | free((void *)rule->be.name); |
| 7503 | rule->be.backend = target; |
| 7504 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7505 | } |
| 7506 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7507 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7508 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7509 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7510 | |
| 7511 | if (!target) { |
| 7512 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7513 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7514 | cfgerr++; |
| 7515 | continue; |
| 7516 | } |
| 7517 | free((void *)srule->srv.name); |
| 7518 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7519 | } |
| 7520 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7521 | /* find the target table for 'stick' rules */ |
| 7522 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7523 | struct proxy *target; |
| 7524 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7525 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7526 | if (mrule->flags & STK_IS_STORE) |
| 7527 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7528 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7529 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7530 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7531 | else |
| 7532 | target = curproxy; |
| 7533 | |
| 7534 | if (!target) { |
| 7535 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7536 | curproxy->id, mrule->table.name); |
| 7537 | cfgerr++; |
| 7538 | } |
| 7539 | else if (target->table.size == 0) { |
| 7540 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7541 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7542 | cfgerr++; |
| 7543 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7544 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7545 | Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7546 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7547 | cfgerr++; |
| 7548 | } |
| 7549 | else { |
| 7550 | free((void *)mrule->table.name); |
| 7551 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7552 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7553 | } |
| 7554 | } |
| 7555 | |
| 7556 | /* find the target table for 'store response' rules */ |
| 7557 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7558 | struct proxy *target; |
| 7559 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7560 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7561 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7562 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7563 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7564 | else |
| 7565 | target = curproxy; |
| 7566 | |
| 7567 | if (!target) { |
| 7568 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7569 | curproxy->id, mrule->table.name); |
| 7570 | cfgerr++; |
| 7571 | } |
| 7572 | else if (target->table.size == 0) { |
| 7573 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7574 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7575 | cfgerr++; |
| 7576 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7577 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7578 | Alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7579 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7580 | cfgerr++; |
| 7581 | } |
| 7582 | else { |
| 7583 | free((void *)mrule->table.name); |
| 7584 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7585 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7586 | } |
| 7587 | } |
| 7588 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7589 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7590 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7591 | struct proxy *target; |
| 7592 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 7593 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7594 | continue; |
| 7595 | |
| 7596 | if (trule->act_prm.trk_ctr.table.n) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7597 | target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7598 | else |
| 7599 | target = curproxy; |
| 7600 | |
| 7601 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7602 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7603 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7604 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7605 | cfgerr++; |
| 7606 | } |
| 7607 | else if (target->table.size == 0) { |
| 7608 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7609 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 7610 | cfgerr++; |
| 7611 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7612 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 7613 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7614 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7615 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7616 | cfgerr++; |
| 7617 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7618 | else { |
| 7619 | free(trule->act_prm.trk_ctr.table.n); |
| 7620 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7621 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7622 | * to pass a list of counters to track and allocate them right here using |
| 7623 | * stktable_alloc_data_type(). |
| 7624 | */ |
| 7625 | } |
| 7626 | } |
| 7627 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7628 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7629 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7630 | struct proxy *target; |
| 7631 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 7632 | if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7633 | continue; |
| 7634 | |
| 7635 | if (trule->act_prm.trk_ctr.table.n) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7636 | target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7637 | else |
| 7638 | target = curproxy; |
| 7639 | |
| 7640 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7641 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7642 | curproxy->id, trule->act_prm.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7643 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7644 | cfgerr++; |
| 7645 | } |
| 7646 | else if (target->table.size == 0) { |
| 7647 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7648 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id); |
| 7649 | cfgerr++; |
| 7650 | } |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7651 | else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr, target->table.type)) { |
| 7652 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7653 | curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7654 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7655 | cfgerr++; |
| 7656 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7657 | else { |
| 7658 | free(trule->act_prm.trk_ctr.table.n); |
| 7659 | trule->act_prm.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7660 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7661 | * to pass a list of counters to track and allocate them right here using |
| 7662 | * stktable_alloc_data_type(). |
| 7663 | */ |
| 7664 | } |
| 7665 | } |
| 7666 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7667 | /* find the target table for 'http-request' layer 7 rules */ |
| 7668 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7669 | struct proxy *target; |
| 7670 | |
| 7671 | if (hrqrule->action < HTTP_REQ_ACT_TRK_SC0 || hrqrule->action > HTTP_REQ_ACT_TRK_SCMAX) |
| 7672 | continue; |
| 7673 | |
| 7674 | if (hrqrule->act_prm.trk_ctr.table.n) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7675 | target = proxy_tbl_by_name(hrqrule->act_prm.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7676 | else |
| 7677 | target = curproxy; |
| 7678 | |
| 7679 | if (!target) { |
| 7680 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7681 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n, |
| 7682 | http_req_trk_idx(hrqrule->action)); |
| 7683 | cfgerr++; |
| 7684 | } |
| 7685 | else if (target->table.size == 0) { |
| 7686 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7687 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id); |
| 7688 | cfgerr++; |
| 7689 | } |
| 7690 | else if (!stktable_compatible_sample(hrqrule->act_prm.trk_ctr.expr, target->table.type)) { |
| 7691 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7692 | curproxy->id, hrqrule->act_prm.trk_ctr.table.n ? hrqrule->act_prm.trk_ctr.table.n : curproxy->id, |
| 7693 | http_req_trk_idx(hrqrule->action)); |
| 7694 | cfgerr++; |
| 7695 | } |
| 7696 | else { |
| 7697 | free(hrqrule->act_prm.trk_ctr.table.n); |
| 7698 | hrqrule->act_prm.trk_ctr.table.t = &target->table; |
| 7699 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7700 | * to pass a list of counters to track and allocate them right here using |
| 7701 | * stktable_alloc_data_type(). |
| 7702 | */ |
| 7703 | } |
| 7704 | } |
| 7705 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 7706 | /* move any "block" rules at the beginning of the http-request rules */ |
| 7707 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 7708 | /* insert block_rules into http_req_rules at the beginning */ |
| 7709 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 7710 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 7711 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 7712 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 7713 | LIST_INIT(&curproxy->block_rules); |
| 7714 | } |
| 7715 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7716 | if (curproxy->table.peers.name) { |
| 7717 | struct peers *curpeers = peers; |
| 7718 | |
| 7719 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 7720 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 7721 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 7722 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7723 | break; |
| 7724 | } |
| 7725 | } |
| 7726 | |
| 7727 | if (!curpeers) { |
| 7728 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 7729 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7730 | free((void *)curproxy->table.peers.name); |
| 7731 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7732 | cfgerr++; |
| 7733 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7734 | else if (curpeers->state == PR_STSTOPPED) { |
| 7735 | /* silently disable this peers section */ |
| 7736 | curproxy->table.peers.p = NULL; |
| 7737 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7738 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7739 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 7740 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7741 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7742 | cfgerr++; |
| 7743 | } |
| 7744 | } |
| 7745 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7746 | |
| 7747 | if (curproxy->email_alert.mailers.name) { |
| 7748 | struct mailers *curmailers = mailers; |
| 7749 | |
| 7750 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 7751 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 7752 | free(curproxy->email_alert.mailers.name); |
| 7753 | curproxy->email_alert.mailers.m = curmailers; |
| 7754 | curmailers->users++; |
| 7755 | break; |
| 7756 | } |
| 7757 | } |
| 7758 | |
| 7759 | if (!curmailers) { |
| 7760 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 7761 | curproxy->id, curproxy->email_alert.mailers.name); |
| 7762 | free_email_alert(curproxy); |
| 7763 | cfgerr++; |
| 7764 | } |
| 7765 | } |
| 7766 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 7767 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7768 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7769 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 7770 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 7771 | "proxy", curproxy->id); |
| 7772 | cfgerr++; |
| 7773 | goto out_uri_auth_compat; |
| 7774 | } |
| 7775 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 7776 | if (curproxy->uri_auth && curproxy->uri_auth->userlist && !(curproxy->uri_auth->flags & ST_CONVDONE)) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7777 | const char *uri_auth_compat_req[10]; |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7778 | struct http_req_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7779 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7780 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7781 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 7782 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7783 | |
| 7784 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7785 | uri_auth_compat_req[i++] = "realm"; |
| 7786 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 7787 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7788 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7789 | uri_auth_compat_req[i++] = "unless"; |
| 7790 | uri_auth_compat_req[i++] = "{"; |
| 7791 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 7792 | uri_auth_compat_req[i++] = "}"; |
| 7793 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7794 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7795 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 7796 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7797 | cfgerr++; |
| 7798 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7799 | } |
| 7800 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7801 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7802 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7803 | if (curproxy->uri_auth->auth_realm) { |
| 7804 | free(curproxy->uri_auth->auth_realm); |
| 7805 | curproxy->uri_auth->auth_realm = NULL; |
| 7806 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 7807 | |
| 7808 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7809 | } |
| 7810 | out_uri_auth_compat: |
| 7811 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 7812 | /* compile the log format */ |
| 7813 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 7814 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 7815 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 7816 | curproxy->conf.logformat_string != clf_http_log_format) |
| 7817 | free(curproxy->conf.logformat_string); |
| 7818 | curproxy->conf.logformat_string = NULL; |
| 7819 | free(curproxy->conf.lfs_file); |
| 7820 | curproxy->conf.lfs_file = NULL; |
| 7821 | curproxy->conf.lfs_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 7822 | } |
| 7823 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 7824 | if (curproxy->conf.logformat_string) { |
| 7825 | curproxy->conf.args.ctx = ARGC_LOG; |
| 7826 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 7827 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 7828 | parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 7829 | SMP_VAL_FE_LOG_END, curproxy->conf.lfs_file, curproxy->conf.lfs_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 7830 | curproxy->conf.args.file = NULL; |
| 7831 | curproxy->conf.args.line = 0; |
| 7832 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 7833 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 7834 | if (curproxy->conf.uniqueid_format_string) { |
| 7835 | curproxy->conf.args.ctx = ARGC_UIF; |
| 7836 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 7837 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 7838 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Godbach | d972203 | 2014-12-18 15:44:58 +0800 | [diff] [blame] | 7839 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 7840 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 7841 | curproxy->conf.args.file = NULL; |
| 7842 | curproxy->conf.args.line = 0; |
| 7843 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 7844 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7845 | /* only now we can check if some args remain unresolved. |
| 7846 | * This must be done after the users and groups resolution. |
| 7847 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 7848 | cfgerr += smp_resolve_args(curproxy); |
| 7849 | if (!cfgerr) |
| 7850 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 7851 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 7852 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7853 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 7854 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 7855 | (!curproxy->timeout.connect || |
| 7856 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7857 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 7858 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 7859 | " | with such a configuration. To fix this, please ensure that all following\n" |
Willy Tarreau | 0f68eac | 2008-01-20 23:25:06 +0100 | [diff] [blame] | 7860 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7861 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7862 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 7863 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 7864 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7865 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 7866 | * We must still support older configurations, so let's find out whether those |
| 7867 | * parameters have been set or must be copied from contimeouts. |
| 7868 | */ |
| 7869 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7870 | if (!curproxy->timeout.tarpit || |
| 7871 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7872 | /* tarpit timeout not set. We search in the following order: |
| 7873 | * default.tarpit, curr.connect, default.connect. |
| 7874 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7875 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7876 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7877 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7878 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7879 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7880 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7881 | } |
| 7882 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7883 | (!curproxy->timeout.queue || |
| 7884 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7885 | /* queue timeout not set. We search in the following order: |
| 7886 | * default.queue, curr.connect, default.connect. |
| 7887 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7888 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7889 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7890 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7891 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 7892 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 7893 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 7894 | } |
| 7895 | } |
| 7896 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7897 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 7898 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
| 7899 | curproxy->check_req = (char *)malloc(curproxy->check_len); |
| 7900 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 7901 | } |
| 7902 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 7903 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 7904 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 7905 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 7906 | proxy_type_str(curproxy), curproxy->id); |
| 7907 | err_code |= ERR_WARN; |
| 7908 | } |
| 7909 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7910 | /* ensure that cookie capture length is not too large */ |
| 7911 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 7912 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 7913 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 7914 | err_code |= ERR_WARN; |
| 7915 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 7916 | } |
| 7917 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 7918 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 7919 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 7920 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 7921 | curproxy->nb_req_cap * sizeof(char *), |
| 7922 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 7926 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 7927 | curproxy->nb_rsp_cap * sizeof(char *), |
| 7928 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 7929 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 7930 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7931 | /* first, we will invert the servers list order */ |
| 7932 | newsrv = NULL; |
| 7933 | while (curproxy->srv) { |
| 7934 | struct server *next; |
| 7935 | |
| 7936 | next = curproxy->srv->next; |
| 7937 | curproxy->srv->next = newsrv; |
| 7938 | newsrv = curproxy->srv; |
| 7939 | if (!next) |
| 7940 | break; |
| 7941 | curproxy->srv = next; |
| 7942 | } |
| 7943 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 7944 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 7945 | * We only emit a warning for the first conflict affecting each server, |
| 7946 | * in order to avoid combinatory explosion if all servers have the same |
| 7947 | * name. We do that only for servers which do not have an explicit ID, |
| 7948 | * because these IDs were made also for distinguishing them and we don't |
| 7949 | * want to annoy people who correctly manage them. |
| 7950 | */ |
| 7951 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 7952 | struct server *other_srv; |
| 7953 | |
| 7954 | if (newsrv->puid) |
| 7955 | continue; |
| 7956 | |
| 7957 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 7958 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 7959 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 7960 | newsrv->conf.file, newsrv->conf.line, |
| 7961 | proxy_type_str(curproxy), curproxy->id, |
| 7962 | newsrv->id, other_srv->conf.line); |
| 7963 | break; |
| 7964 | } |
| 7965 | } |
| 7966 | } |
| 7967 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 7968 | /* assign automatic UIDs to servers which don't have one yet */ |
| 7969 | next_id = 1; |
| 7970 | newsrv = curproxy->srv; |
| 7971 | while (newsrv != NULL) { |
| 7972 | if (!newsrv->puid) { |
| 7973 | /* server ID not set, use automatic numbering with first |
| 7974 | * spare entry starting with next_svid. |
| 7975 | */ |
| 7976 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 7977 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 7978 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 7979 | } |
| 7980 | next_id++; |
| 7981 | newsrv = newsrv->next; |
| 7982 | } |
| 7983 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 7984 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 7985 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7986 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 7987 | /* |
| 7988 | * If this server supports a maxconn parameter, it needs a dedicated |
| 7989 | * tasks to fill the emptied slots when a connection leaves. |
| 7990 | * Also, resolve deferred tracking dependency if needed. |
| 7991 | */ |
| 7992 | newsrv = curproxy->srv; |
| 7993 | while (newsrv != NULL) { |
| 7994 | if (newsrv->minconn > newsrv->maxconn) { |
| 7995 | /* Only 'minconn' was specified, or it was higher than or equal |
| 7996 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 7997 | * this will avoid further useless expensive computations. |
| 7998 | */ |
| 7999 | newsrv->maxconn = newsrv->minconn; |
| 8000 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8001 | /* minconn was not specified, so we set it to maxconn */ |
| 8002 | newsrv->minconn = newsrv->maxconn; |
| 8003 | } |
| 8004 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8005 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8006 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 8007 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8008 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8009 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8010 | /* set the check type on the server */ |
| 8011 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8012 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8013 | if (newsrv->trackit) { |
| 8014 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8015 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8016 | char *pname, *sname; |
| 8017 | |
| 8018 | pname = newsrv->trackit; |
| 8019 | sname = strrchr(pname, '/'); |
| 8020 | |
| 8021 | if (sname) |
| 8022 | *sname++ = '\0'; |
| 8023 | else { |
| 8024 | sname = pname; |
| 8025 | pname = NULL; |
| 8026 | } |
| 8027 | |
| 8028 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8029 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8030 | if (!px) { |
| 8031 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8032 | proxy_type_str(curproxy), curproxy->id, |
| 8033 | newsrv->id, pname); |
| 8034 | cfgerr++; |
| 8035 | goto next_srv; |
| 8036 | } |
| 8037 | } else |
| 8038 | px = curproxy; |
| 8039 | |
| 8040 | srv = findserver(px, sname); |
| 8041 | if (!srv) { |
| 8042 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8043 | proxy_type_str(curproxy), curproxy->id, |
| 8044 | newsrv->id, sname); |
| 8045 | cfgerr++; |
| 8046 | goto next_srv; |
| 8047 | } |
| 8048 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8049 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8050 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8051 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8052 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8053 | "tracking as it does not have any check nor agent enabled.\n", |
| 8054 | proxy_type_str(curproxy), curproxy->id, |
| 8055 | newsrv->id, px->id, srv->id); |
| 8056 | cfgerr++; |
| 8057 | goto next_srv; |
| 8058 | } |
| 8059 | |
| 8060 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8061 | |
| 8062 | if (loop) { |
| 8063 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8064 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8065 | proxy_type_str(curproxy), curproxy->id, |
| 8066 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8067 | cfgerr++; |
| 8068 | goto next_srv; |
| 8069 | } |
| 8070 | |
| 8071 | if (curproxy != px && |
| 8072 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8073 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8074 | "tracking: disable-on-404 option inconsistency.\n", |
| 8075 | proxy_type_str(curproxy), curproxy->id, |
| 8076 | newsrv->id, px->id, srv->id); |
| 8077 | cfgerr++; |
| 8078 | goto next_srv; |
| 8079 | } |
| 8080 | |
| 8081 | /* if the other server is forced disabled, we have to do the same here */ |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 8082 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 8083 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 8084 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 8085 | newsrv->check.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8086 | } |
| 8087 | |
| 8088 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8089 | newsrv->tracknext = srv->trackers; |
| 8090 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8091 | |
| 8092 | free(newsrv->trackit); |
| 8093 | newsrv->trackit = NULL; |
| 8094 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8095 | |
| 8096 | /* |
| 8097 | * resolve server's resolvers name and update the resolvers pointer |
| 8098 | * accordingly |
| 8099 | */ |
| 8100 | if (newsrv->resolvers_id) { |
| 8101 | struct dns_resolvers *curr_resolvers; |
| 8102 | int found; |
| 8103 | |
| 8104 | found = 0; |
| 8105 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8106 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8107 | found = 1; |
| 8108 | break; |
| 8109 | } |
| 8110 | } |
| 8111 | |
| 8112 | if (!found) { |
| 8113 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8114 | proxy_type_str(curproxy), curproxy->id, |
| 8115 | newsrv->id, newsrv->resolvers_id); |
| 8116 | cfgerr++; |
| 8117 | } else { |
| 8118 | free(newsrv->resolvers_id); |
| 8119 | newsrv->resolvers_id = NULL; |
| 8120 | if (newsrv->resolution) |
| 8121 | newsrv->resolution->resolvers = curr_resolvers; |
| 8122 | } |
| 8123 | } |
| 8124 | else { |
| 8125 | /* if no resolvers section associated to this server |
| 8126 | * we can clean up the associated resolution structure |
| 8127 | */ |
| 8128 | if (newsrv->resolution) { |
| 8129 | free(newsrv->resolution->hostname_dn); |
| 8130 | newsrv->resolution->hostname_dn = NULL; |
| 8131 | free(newsrv->resolution); |
| 8132 | newsrv->resolution = NULL; |
| 8133 | } |
| 8134 | } |
| 8135 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8136 | next_srv: |
| 8137 | newsrv = newsrv->next; |
| 8138 | } |
| 8139 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8140 | /* We have to initialize the server lookup mechanism depending |
| 8141 | * on what LB algorithm was choosen. |
| 8142 | */ |
| 8143 | |
| 8144 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8145 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8146 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8147 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8148 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8149 | init_server_map(curproxy); |
| 8150 | } else { |
| 8151 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8152 | fwrr_init_server_groups(curproxy); |
| 8153 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8154 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8155 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8156 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8157 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8158 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8159 | fwlc_init_server_tree(curproxy); |
| 8160 | } else { |
| 8161 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8162 | fas_init_server_tree(curproxy); |
| 8163 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8164 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8165 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8166 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8167 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8168 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8169 | chash_init_server_tree(curproxy); |
| 8170 | } else { |
| 8171 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8172 | init_server_map(curproxy); |
| 8173 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8174 | break; |
| 8175 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8176 | |
| 8177 | if (curproxy->options & PR_O_LOGASAP) |
| 8178 | curproxy->to_log &= ~LW_BYTES; |
| 8179 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8180 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 8181 | (curproxy->cap & PR_CAP_FE) && !LIST_ISEMPTY(&curproxy->logformat) && LIST_ISEMPTY(&curproxy->logsrvs)) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8182 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8183 | proxy_type_str(curproxy), curproxy->id); |
| 8184 | err_code |= ERR_WARN; |
| 8185 | } |
| 8186 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8187 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8188 | int optnum; |
| 8189 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8190 | if (curproxy->uri_auth) { |
| 8191 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8192 | proxy_type_str(curproxy), curproxy->id); |
| 8193 | err_code |= ERR_WARN; |
| 8194 | curproxy->uri_auth = NULL; |
| 8195 | } |
| 8196 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8197 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8198 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8199 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8200 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8201 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8202 | } |
| 8203 | |
| 8204 | if (curproxy->options & PR_O_ORGTO) { |
| 8205 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8206 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8207 | err_code |= ERR_WARN; |
| 8208 | curproxy->options &= ~PR_O_ORGTO; |
| 8209 | } |
| 8210 | |
| 8211 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8212 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8213 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8214 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8215 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8216 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8217 | err_code |= ERR_WARN; |
| 8218 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8219 | } |
| 8220 | } |
| 8221 | |
| 8222 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8223 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8224 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8225 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8226 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8227 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8228 | err_code |= ERR_WARN; |
| 8229 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8230 | } |
| 8231 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8232 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 8233 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8234 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8235 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8236 | Warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8237 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8238 | err_code |= ERR_WARN; |
| 8239 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8240 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8241 | } |
| 8242 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8243 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8244 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8245 | */ |
| 8246 | newsrv = curproxy->srv; |
| 8247 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8248 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8249 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8250 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8251 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8252 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8253 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8254 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8255 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8256 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8257 | err_code |= ERR_WARN; |
| 8258 | } |
| 8259 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8260 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8261 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8262 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8263 | err_code |= ERR_WARN; |
| 8264 | } |
| 8265 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 8266 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8267 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8268 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8269 | Warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8270 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8271 | err_code |= ERR_WARN; |
| 8272 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8273 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8274 | newsrv = newsrv->next; |
| 8275 | } |
| 8276 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8277 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8278 | * with no inspect-delay |
| 8279 | */ |
| 8280 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8281 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 8282 | if (trule->action == TCP_ACT_CAPTURE && |
| 8283 | !(trule->act_prm.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 8284 | break; |
| 8285 | if ((trule->action >= TCP_ACT_TRK_SC0 && trule->action <= TCP_ACT_TRK_SCMAX) && |
| 8286 | !(trule->act_prm.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
| 8287 | break; |
| 8288 | } |
| 8289 | |
| 8290 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8291 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8292 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8293 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8294 | " setting the tcp-request inspect-delay.\n", |
| 8295 | proxy_type_str(curproxy), curproxy->id); |
| 8296 | err_code |= ERR_WARN; |
| 8297 | } |
| 8298 | } |
| 8299 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8300 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8301 | if (!curproxy->accept) |
| 8302 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8303 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8304 | if (curproxy->tcp_req.inspect_delay || |
| 8305 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8306 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8307 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8308 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8309 | curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 8310 | curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8311 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8312 | |
| 8313 | /* both TCP and HTTP must check switching rules */ |
| 8314 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
| 8315 | } |
| 8316 | |
| 8317 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8318 | if (curproxy->tcp_req.inspect_delay || |
| 8319 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8320 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8321 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8322 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8323 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8324 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8325 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8326 | curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 8327 | curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE; |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8328 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8329 | |
| 8330 | /* If the backend does requires RDP cookie persistence, we have to |
| 8331 | * enable the corresponding analyser. |
| 8332 | */ |
| 8333 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8334 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
| 8335 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8336 | } |
| 8337 | |
| 8338 | /***********************************************************/ |
| 8339 | /* At this point, target names have already been resolved. */ |
| 8340 | /***********************************************************/ |
| 8341 | |
| 8342 | /* Check multi-process mode compatibility */ |
| 8343 | |
| 8344 | if (global.nbproc > 1 && global.stats_fe) { |
| 8345 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8346 | unsigned long mask; |
| 8347 | |
| 8348 | mask = nbits(global.nbproc); |
| 8349 | if (global.stats_fe->bind_proc) |
| 8350 | mask &= global.stats_fe->bind_proc; |
| 8351 | |
| 8352 | if (bind_conf->bind_proc) |
| 8353 | mask &= bind_conf->bind_proc; |
| 8354 | |
| 8355 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8356 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8357 | break; |
| 8358 | } |
| 8359 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8360 | 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"); |
| 8361 | } |
| 8362 | } |
| 8363 | |
| 8364 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8365 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8366 | if (curproxy->bind_proc) |
| 8367 | continue; |
| 8368 | |
| 8369 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8370 | unsigned long mask; |
| 8371 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8372 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8373 | curproxy->bind_proc |= mask; |
| 8374 | } |
| 8375 | |
| 8376 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8377 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8378 | } |
| 8379 | |
| 8380 | if (global.stats_fe) { |
| 8381 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8382 | unsigned long mask; |
| 8383 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8384 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8385 | global.stats_fe->bind_proc |= mask; |
| 8386 | } |
| 8387 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8388 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8389 | } |
| 8390 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8391 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8392 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8393 | */ |
| 8394 | if (!cfgerr) { |
| 8395 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8396 | if (curproxy->cap & PR_CAP_FE) |
| 8397 | propagate_processes(curproxy, NULL); |
| 8398 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8399 | } |
| 8400 | |
| 8401 | /* Bind each unbound backend to all processes when not specified. */ |
| 8402 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8403 | if (curproxy->bind_proc) |
| 8404 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8405 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8406 | } |
| 8407 | |
| 8408 | /*******************************************************/ |
| 8409 | /* At this step, all proxies have a non-null bind_proc */ |
| 8410 | /*******************************************************/ |
| 8411 | |
| 8412 | /* perform the final checks before creating tasks */ |
| 8413 | |
| 8414 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8415 | struct listener *listener; |
| 8416 | unsigned int next_id; |
| 8417 | int nbproc; |
| 8418 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8419 | nbproc = my_popcountl(curproxy->bind_proc & nbits(global.nbproc)); |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8420 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8421 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8422 | /* Configure SSL for each bind line. |
| 8423 | * Note: if configuration fails at some point, the ->ctx member |
| 8424 | * remains NULL so that listeners can later detach. |
| 8425 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8426 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8427 | int alloc_ctx; |
| 8428 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8429 | if (!bind_conf->is_ssl) { |
| 8430 | if (bind_conf->default_ctx) { |
| 8431 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 8432 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8433 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8434 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8435 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8436 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8437 | Alert("Proxy '%s': no SSL certificate specified for bind '%s' at [%s:%d] (use 'crt').\n", |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8438 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8439 | cfgerr++; |
| 8440 | continue; |
| 8441 | } |
| 8442 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 8443 | alloc_ctx = shared_context_init(global.tune.sslcachesize, (!global.tune.sslprivatecache && (global.nbproc > 1)) ? 1 : 0); |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8444 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8445 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 8446 | Alert("Unable to initialize the lock for the shared SSL session cache. You can retry using the global statement 'tune.ssl.force-private-cache' but it could increase CPU usage due to renegotiations if nbproc > 1.\n"); |
| 8447 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8448 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8449 | cfgerr++; |
| 8450 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8451 | } |
| 8452 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8453 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8454 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8455 | |
| 8456 | /* initialize CA variables if the certificates generation is enabled */ |
| 8457 | cfgerr += ssl_sock_load_ca(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8458 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8459 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8460 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8461 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8462 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8463 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8464 | if (!listener->luid) { |
| 8465 | /* listener ID not set, use automatic numbering with first |
| 8466 | * spare entry starting with next_luid. |
| 8467 | */ |
| 8468 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8469 | listener->conf.id.key = listener->luid = next_id; |
| 8470 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8471 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8472 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8473 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8474 | /* enable separate counters */ |
| 8475 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
| 8476 | listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8477 | if (!listener->name) |
| 8478 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8479 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8480 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8481 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8482 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8483 | if (!listener->maxconn) |
| 8484 | listener->maxconn = curproxy->maxconn; |
| 8485 | if (!listener->backlog) |
| 8486 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8487 | if (!listener->maxaccept) |
| 8488 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8489 | |
| 8490 | /* we want to have an optimal behaviour on single process mode to |
| 8491 | * maximize the work at once, but in multi-process we want to keep |
| 8492 | * some fairness between processes, so we target half of the max |
| 8493 | * number of events to be balanced over all the processes the proxy |
| 8494 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8495 | * used to disable the limit. |
| 8496 | */ |
| 8497 | if (listener->maxaccept > 0) { |
| 8498 | if (nbproc > 1) |
| 8499 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8500 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8501 | } |
| 8502 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8503 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8504 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8505 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8506 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8507 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8508 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
| 8509 | listener->options |= LI_O_TCP_RULES; |
| 8510 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8511 | if (curproxy->mon_mask.s_addr) |
| 8512 | listener->options |= LI_O_CHK_MONNET; |
| 8513 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8514 | /* smart accept mode is automatic in HTTP mode */ |
| 8515 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8516 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8517 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8518 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8519 | } |
| 8520 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8521 | /* Release unused SSL configs */ |
| 8522 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8523 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8524 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8525 | #ifdef USE_OPENSSL |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8526 | ssl_sock_free_ca(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8527 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8528 | free(bind_conf->ca_file); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8529 | free(bind_conf->ca_sign_file); |
| 8530 | free(bind_conf->ca_sign_pass); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8531 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 8532 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8533 | free(bind_conf->crl_file); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 8534 | if(bind_conf->keys_ref) { |
| 8535 | free(bind_conf->keys_ref->filename); |
| 8536 | free(bind_conf->keys_ref->tlskeys); |
| 8537 | free(bind_conf->keys_ref); |
| 8538 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8539 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8540 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8541 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8542 | if (nbproc > 1) { |
| 8543 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8544 | int count, maxproc = 0; |
| 8545 | |
| 8546 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8547 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8548 | if (count > maxproc) |
| 8549 | maxproc = count; |
| 8550 | } |
| 8551 | /* backends have 0, frontends have 1 or more */ |
| 8552 | if (maxproc != 1) |
| 8553 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 8554 | " limited to process assigned to the current request.\n", |
| 8555 | curproxy->id); |
| 8556 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8557 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 8558 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8559 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8560 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8561 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8562 | if (curproxy->appsession_name) { |
| 8563 | Warning("Proxy '%s': appsession will not work correctly in multi-process mode.\n", |
| 8564 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8565 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8566 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 8567 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8568 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8569 | } |
| 8570 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8571 | |
| 8572 | /* create the task associated with the proxy */ |
| 8573 | curproxy->task = task_new(); |
| 8574 | if (curproxy->task) { |
| 8575 | curproxy->task->context = curproxy; |
| 8576 | curproxy->task->process = manage_proxy; |
| 8577 | /* no need to queue, it will be done automatically if some |
| 8578 | * listener gets limited. |
| 8579 | */ |
| 8580 | curproxy->task->expire = TICK_ETERNITY; |
| 8581 | } else { |
| 8582 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8583 | curproxy->id); |
| 8584 | cfgerr++; |
| 8585 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8586 | } |
| 8587 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8588 | /* automatically compute fullconn if not set. We must not do it in the |
| 8589 | * loop above because cross-references are not yet fully resolved. |
| 8590 | */ |
| 8591 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8592 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 8593 | * the possible incoming frontend's maxconns. |
| 8594 | */ |
| 8595 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 8596 | struct proxy *fe; |
| 8597 | int total = 0; |
| 8598 | |
| 8599 | /* sum up the number of maxconns of frontends which |
| 8600 | * reference this backend at least once or which are |
| 8601 | * the same one ('listen'). |
| 8602 | */ |
| 8603 | for (fe = proxy; fe; fe = fe->next) { |
| 8604 | struct switching_rule *rule; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8605 | int found = 0; |
| 8606 | |
| 8607 | if (!(fe->cap & PR_CAP_FE)) |
| 8608 | continue; |
| 8609 | |
| 8610 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 8611 | found = 1; |
| 8612 | |
| 8613 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 8614 | found = 1; |
| 8615 | |
| 8616 | /* check if a "use_backend" rule matches */ |
| 8617 | if (!found) { |
| 8618 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 8619 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8620 | found = 1; |
| 8621 | break; |
| 8622 | } |
| 8623 | } |
| 8624 | } |
| 8625 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8626 | /* now we've checked all possible ways to reference a backend |
| 8627 | * from a frontend. |
| 8628 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8629 | if (!found) |
| 8630 | continue; |
| 8631 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8632 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8633 | /* we have the sum of the maxconns in <total>. We only |
| 8634 | * keep 10% of that sum to set the default fullconn, with |
| 8635 | * a hard minimum of 1 (to avoid a divide by zero). |
| 8636 | */ |
| 8637 | curproxy->fullconn = (total + 9) / 10; |
| 8638 | if (!curproxy->fullconn) |
| 8639 | curproxy->fullconn = 1; |
| 8640 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 8641 | } |
| 8642 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8643 | /* |
| 8644 | * Recount currently required checks. |
| 8645 | */ |
| 8646 | |
| 8647 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 8648 | int optnum; |
| 8649 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8650 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 8651 | if (curproxy->options & cfg_opts[optnum].val) |
| 8652 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8653 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8654 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 8655 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 8656 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8657 | } |
| 8658 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 8659 | /* compute the required process bindings for the peers */ |
| 8660 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 8661 | if (curproxy->table.peers.p) |
| 8662 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 8663 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8664 | if (peers) { |
| 8665 | struct peers *curpeers = peers, **last; |
| 8666 | struct peer *p, *pb; |
| 8667 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8668 | /* Remove all peers sections which don't have a valid listener, |
| 8669 | * which are not used by any table, or which are bound to more |
| 8670 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8671 | */ |
| 8672 | last = &peers; |
| 8673 | while (*last) { |
| 8674 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8675 | |
| 8676 | if (curpeers->state == PR_STSTOPPED) { |
| 8677 | /* the "disabled" keyword was present */ |
| 8678 | if (curpeers->peers_fe) |
| 8679 | stop_proxy(curpeers->peers_fe); |
| 8680 | curpeers->peers_fe = NULL; |
| 8681 | } |
| 8682 | else if (!curpeers->peers_fe) { |
| 8683 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 8684 | curpeers->id, localpeer); |
| 8685 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8686 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8687 | /* either it's totally stopped or too much used */ |
| 8688 | if (curpeers->peers_fe->bind_proc) { |
| 8689 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 8690 | "running in different processes (%d different ones). " |
| 8691 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8692 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8693 | cfgerr++; |
| 8694 | } |
| 8695 | stop_proxy(curpeers->peers_fe); |
| 8696 | curpeers->peers_fe = NULL; |
| 8697 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8698 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 8699 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8700 | last = &curpeers->next; |
| 8701 | continue; |
| 8702 | } |
| 8703 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8704 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8705 | p = curpeers->remote; |
| 8706 | while (p) { |
| 8707 | pb = p->next; |
| 8708 | free(p->id); |
| 8709 | free(p); |
| 8710 | p = pb; |
| 8711 | } |
| 8712 | |
| 8713 | /* Destroy and unlink this curpeers section. |
| 8714 | * Note: curpeers is backed up into *last. |
| 8715 | */ |
| 8716 | free(curpeers->id); |
| 8717 | curpeers = curpeers->next; |
| 8718 | free(*last); |
| 8719 | *last = curpeers; |
| 8720 | } |
| 8721 | } |
| 8722 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 8723 | /* initialize stick-tables on backend capable proxies. This must not |
| 8724 | * be done earlier because the data size may be discovered while parsing |
| 8725 | * other proxies. |
| 8726 | */ |
| 8727 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8728 | if (curproxy->state == PR_STSTOPPED) |
| 8729 | continue; |
| 8730 | |
| 8731 | if (!stktable_init(&curproxy->table)) { |
| 8732 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 8733 | cfgerr++; |
| 8734 | } |
| 8735 | } |
| 8736 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 8737 | if (mailers) { |
| 8738 | struct mailers *curmailers = mailers, **last; |
| 8739 | struct mailer *m, *mb; |
| 8740 | |
| 8741 | /* Remove all mailers sections which don't have a valid listener. |
| 8742 | * This can happen when a mailers section is never referenced. |
| 8743 | */ |
| 8744 | last = &mailers; |
| 8745 | while (*last) { |
| 8746 | curmailers = *last; |
| 8747 | if (curmailers->users) { |
| 8748 | last = &curmailers->next; |
| 8749 | continue; |
| 8750 | } |
| 8751 | |
| 8752 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 8753 | curmailers->id); |
| 8754 | |
| 8755 | m = curmailers->mailer_list; |
| 8756 | while (m) { |
| 8757 | mb = m->next; |
| 8758 | free(m->id); |
| 8759 | free(m); |
| 8760 | m = mb; |
| 8761 | } |
| 8762 | |
| 8763 | /* Destroy and unlink this curmailers section. |
| 8764 | * Note: curmailers is backed up into *last. |
| 8765 | */ |
| 8766 | free(curmailers->id); |
| 8767 | curmailers = curmailers->next; |
| 8768 | free(*last); |
| 8769 | *last = curmailers; |
| 8770 | } |
| 8771 | } |
| 8772 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 8773 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 8774 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 8775 | MEM_F_SHARED); |
| 8776 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8777 | if (cfgerr > 0) |
| 8778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 8779 | out: |
| 8780 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8781 | } |
| 8782 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 8783 | /* |
| 8784 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 8785 | * parsing sessions. |
| 8786 | */ |
| 8787 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 8788 | { |
| 8789 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 8790 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8791 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 8792 | /* |
| 8793 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 8794 | */ |
| 8795 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 8796 | { |
| 8797 | LIST_DEL(&kwl->list); |
| 8798 | LIST_INIT(&kwl->list); |
| 8799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8800 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 8801 | /* this function register new section in the haproxy configuration file. |
| 8802 | * <section_name> is the name of this new section and <section_parser> |
| 8803 | * is the called parser. If two section declaration have the same name, |
| 8804 | * only the first declared is used. |
| 8805 | */ |
| 8806 | int cfg_register_section(char *section_name, |
| 8807 | int (*section_parser)(const char *, int, char **, int)) |
| 8808 | { |
| 8809 | struct cfg_section *cs; |
| 8810 | |
| 8811 | cs = calloc(1, sizeof(*cs)); |
| 8812 | if (!cs) { |
| 8813 | Alert("register section '%s': out of memory.\n", section_name); |
| 8814 | return 0; |
| 8815 | } |
| 8816 | |
| 8817 | cs->section_name = section_name; |
| 8818 | cs->section_parser = section_parser; |
| 8819 | |
| 8820 | LIST_ADDQ(§ions, &cs->list); |
| 8821 | |
| 8822 | return 1; |
| 8823 | } |
| 8824 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8825 | /* |
| 8826 | * Local variables: |
| 8827 | * c-indent-level: 8 |
| 8828 | * c-basic-offset: 8 |
| 8829 | * End: |
| 8830 | */ |