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> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 48 | #include <types/filters.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 50 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 51 | #include <types/peers.h> |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 52 | #include <types/mailers.h> |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 53 | #include <types/dns.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 55 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 56 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 58 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 60 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 61 | #include <proto/dumpstats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 62 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 63 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 64 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 65 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 66 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 67 | #include <proto/lb_fwlc.h> |
| 68 | #include <proto/lb_fwrr.h> |
| 69 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 70 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 72 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 73 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 74 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 75 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 76 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 77 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 78 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 79 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 80 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 81 | #include <proto/stream.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 82 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 83 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 84 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 86 | #ifdef USE_OPENSSL |
| 87 | #include <types/ssl_sock.h> |
| 88 | #include <proto/ssl_sock.h> |
| 89 | #include <proto/shctx.h> |
| 90 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 91 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 92 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 93 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 94 | * |
| 95 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 96 | */ |
| 97 | const char sslv3_client_hello_pkt[] = { |
| 98 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 99 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 100 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 101 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 102 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 103 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 104 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 105 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 106 | "\x00" /* Session ID length : empty (no session ID) */ |
| 107 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 108 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 109 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 110 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 111 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 112 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 113 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 114 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 115 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 116 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 117 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 118 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 119 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 120 | }; |
| 121 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 122 | /* various keyword modifiers */ |
| 123 | enum kw_mod { |
| 124 | KWM_STD = 0, /* normal */ |
| 125 | KWM_NO, /* "no" prefixed before the keyword */ |
| 126 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 127 | }; |
| 128 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 129 | /* permit to store configuration section */ |
| 130 | struct cfg_section { |
| 131 | struct list list; |
| 132 | char *section_name; |
| 133 | int (*section_parser)(const char *, int, char **, int); |
| 134 | }; |
| 135 | |
| 136 | /* Used to chain configuration sections definitions. This list |
| 137 | * stores struct cfg_section |
| 138 | */ |
| 139 | struct list sections = LIST_HEAD_INIT(sections); |
| 140 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 141 | /* 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] | 142 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 143 | const char *name; |
| 144 | unsigned int val; |
| 145 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 146 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* proxy->options */ |
| 151 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 152 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 153 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 154 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 155 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 156 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 157 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 158 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 159 | { "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] | 160 | { "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] | 161 | { "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] | 162 | { "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] | 163 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 164 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 165 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 167 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 168 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 169 | #else |
| 170 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 171 | #endif |
| 172 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 173 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 176 | /* proxy->options2 */ |
| 177 | static const struct cfg_opt cfg_opts2[] = |
| 178 | { |
| 179 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 180 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 181 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 182 | { "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] | 183 | #else |
| 184 | { "splice-request", 0, 0, 0, 0 }, |
| 185 | { "splice-response", 0, 0, 0, 0 }, |
| 186 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 187 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 188 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 189 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 190 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 191 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 192 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 193 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 194 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 195 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 196 | { "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] | 197 | { "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] | 198 | { "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] | 199 | { "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] | 200 | { "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] | 201 | { NULL, 0, 0, 0 } |
| 202 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 204 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 206 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 207 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 208 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 209 | /* List head of all known configuration keywords */ |
| 210 | static struct cfg_kw_list cfg_keywords = { |
| 211 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 212 | }; |
| 213 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 214 | /* |
| 215 | * converts <str> to a list of listeners which are dynamically allocated. |
| 216 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 217 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 218 | * - <port> is a numerical port from 1 to 65535 ; |
| 219 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 220 | * 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] | 221 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 222 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 223 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 224 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 225 | 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] | 226 | { |
| 227 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 228 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 229 | int port, end; |
| 230 | |
| 231 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 232 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 233 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 234 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 235 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 236 | |
| 237 | str = next; |
| 238 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 239 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | *next++ = 0; |
| 241 | } |
| 242 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 243 | ss2 = str2sa_range(str, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 244 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 245 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 246 | if (!ss2) |
| 247 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 248 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 249 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 250 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 251 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 252 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 253 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 254 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 255 | if (!port || !end) { |
| 256 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 257 | goto fail; |
| 258 | } |
| 259 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 260 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 261 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 262 | goto fail; |
| 263 | } |
| 264 | |
| 265 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 266 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 267 | goto fail; |
| 268 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 269 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 270 | else if (ss2->ss_family == AF_UNSPEC) { |
| 271 | socklen_t addr_len; |
| 272 | |
| 273 | /* We want to attach to an already bound fd whose number |
| 274 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 275 | * Note that by definition there is a single listener. |
| 276 | * We still have to determine the address family to |
| 277 | * register the correct protocol. |
| 278 | */ |
| 279 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 280 | addr_len = sizeof(*ss2); |
| 281 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 282 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 283 | goto fail; |
| 284 | } |
| 285 | |
| 286 | port = end = get_host_port(ss2); |
| 287 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 288 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 289 | /* OK the address looks correct */ |
Vincent Bernat | 6e61589 | 2016-05-18 16:17:44 +0200 | [diff] [blame] | 290 | memcpy(&ss, ss2, sizeof(ss)); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 291 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 292 | for (; port <= end; port++) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 293 | l = calloc(1, sizeof(*l)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 294 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 295 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 296 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 297 | l->frontend = curproxy; |
| 298 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 300 | l->fd = fd; |
Vincent Bernat | 6e46ff1 | 2016-05-19 11:29:43 +0200 | [diff] [blame] | 301 | memcpy(&l->addr, &ss, sizeof(ss)); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 302 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 303 | l->state = LI_INIT; |
| 304 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 305 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 306 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 307 | tcpv4_add_listener(l); |
| 308 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 309 | else if (ss.ss_family == AF_INET6) { |
| 310 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 311 | tcpv6_add_listener(l); |
| 312 | } |
| 313 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 314 | uxst_add_listener(l); |
| 315 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 316 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 317 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 318 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 319 | } /* end for(port) */ |
| 320 | } /* end while(next) */ |
| 321 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 322 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 323 | fail: |
| 324 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 325 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 326 | } |
| 327 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 328 | /* |
| 329 | * Report a fatal Alert when there is too much arguments |
| 330 | * The index is the current keyword in args |
| 331 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 332 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 333 | */ |
| 334 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 335 | { |
| 336 | char *kw = NULL; |
| 337 | int i; |
| 338 | |
| 339 | if (!*args[index + maxarg + 1]) |
| 340 | return 0; |
| 341 | |
| 342 | memprintf(&kw, "%s", args[0]); |
| 343 | for (i = 1; i <= index; i++) { |
| 344 | memprintf(&kw, "%s %s", kw, args[i]); |
| 345 | } |
| 346 | |
| 347 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 348 | free(kw); |
| 349 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 350 | return 1; |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * same as alertif_too_many_args_idx with a 0 index |
| 355 | */ |
| 356 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 357 | { |
| 358 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 359 | } |
| 360 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 361 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 362 | * Return 1 if the warning has been emitted, otherwise 0. |
| 363 | */ |
| 364 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 365 | { |
| 366 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 367 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 368 | file, line, arg); |
| 369 | return 1; |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 374 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 375 | * Return 1 if the warning has been emitted, otherwise 0. |
| 376 | */ |
| 377 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 378 | { |
| 379 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 380 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 381 | file, line, arg); |
| 382 | return 1; |
| 383 | } |
| 384 | return 0; |
| 385 | } |
| 386 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 387 | /* Report a warning if a rule is placed after a 'block' rule. |
| 388 | * Return 1 if the warning has been emitted, otherwise 0. |
| 389 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 390 | 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] | 391 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 392 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 393 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 394 | file, line, arg); |
| 395 | return 1; |
| 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 400 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 401 | * Return 1 if the warning has been emitted, otherwise 0. |
| 402 | */ |
| 403 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 404 | { |
| 405 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 406 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 407 | file, line, arg); |
| 408 | return 1; |
| 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 413 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 414 | * Return 1 if the warning has been emitted, otherwise 0. |
| 415 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 416 | 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] | 417 | { |
| 418 | if (proxy->req_exp) { |
| 419 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 420 | file, line, arg); |
| 421 | return 1; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /* Report a warning if a rule is placed after a reqadd rule. |
| 427 | * Return 1 if the warning has been emitted, otherwise 0. |
| 428 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 429 | 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] | 430 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 431 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 432 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 433 | file, line, arg); |
| 434 | return 1; |
| 435 | } |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | /* Report a warning if a rule is placed after a redirect rule. |
| 440 | * Return 1 if the warning has been emitted, otherwise 0. |
| 441 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 442 | 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] | 443 | { |
| 444 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 445 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 446 | file, line, arg); |
| 447 | return 1; |
| 448 | } |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 453 | * Return 1 if the warning has been emitted, otherwise 0. |
| 454 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 455 | 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] | 456 | { |
| 457 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 458 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 459 | file, line, arg); |
| 460 | return 1; |
| 461 | } |
| 462 | return 0; |
| 463 | } |
| 464 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 465 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 466 | * Return 1 if the warning has been emitted, otherwise 0. |
| 467 | */ |
| 468 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 469 | { |
| 470 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 471 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 472 | file, line, arg); |
| 473 | return 1; |
| 474 | } |
| 475 | return 0; |
| 476 | } |
| 477 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 478 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 479 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 480 | { |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 481 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 482 | warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 483 | warnif_rule_after_block(proxy, file, line, arg) || |
| 484 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 485 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 486 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 487 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 488 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 489 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 490 | } |
| 491 | |
| 492 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 493 | { |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 494 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 495 | warnif_rule_after_block(proxy, file, line, arg) || |
| 496 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 497 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 498 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 499 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 500 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 501 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 502 | } |
| 503 | |
| 504 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 505 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 506 | { |
| 507 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 508 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 509 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 510 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 511 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 512 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 513 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 514 | } |
| 515 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 516 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 517 | 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] | 518 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 519 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 520 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 521 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 522 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 523 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 524 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* report a warning if an http-request rule is dangerously placed */ |
| 528 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 529 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 530 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 531 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 532 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 533 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 534 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 538 | 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] | 539 | { |
| 540 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 541 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 542 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 543 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 547 | 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] | 548 | { |
| 549 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 550 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 551 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 552 | } |
| 553 | |
| 554 | /* report a warning if a redirect rule is dangerously placed */ |
| 555 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 556 | { |
| 557 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 558 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 561 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 562 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 563 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 564 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 565 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 566 | 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] | 567 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 568 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 569 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 570 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 571 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 572 | return 0; |
| 573 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 574 | acl = acl_cond_conflicts(cond, where); |
| 575 | if (acl) { |
| 576 | if (acl->name && *acl->name) |
| 577 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 578 | file, line, acl->name, sample_ckp_names(where)); |
| 579 | else |
| 580 | 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] | 581 | 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] | 582 | return ERR_WARN; |
| 583 | } |
| 584 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 585 | return 0; |
| 586 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 587 | if (acl->name && *acl->name) |
| 588 | 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] | 589 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 590 | else |
| 591 | 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] | 592 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 593 | return ERR_WARN; |
| 594 | } |
| 595 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 596 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 597 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 598 | * any combination of : |
| 599 | * - ERR_ABORT: must abort ASAP |
| 600 | * - ERR_FATAL: we can continue parsing but not start the service |
| 601 | * - ERR_WARN: a warning has been emitted |
| 602 | * - ERR_ALERT: an alert has been emitted |
| 603 | * Only the two first ones can stop processing, the two others are just |
| 604 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 605 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 606 | 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] | 607 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 608 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 609 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 610 | |
| 611 | if (!strcmp(args[0], "global")) { /* new section */ |
| 612 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 613 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 614 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 615 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 616 | else if (!strcmp(args[0], "ca-base")) { |
| 617 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 618 | if(alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 619 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 620 | if (global.ca_base != NULL) { |
| 621 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 622 | err_code |= ERR_ALERT; |
| 623 | goto out; |
| 624 | } |
| 625 | if (*(args[1]) == 0) { |
| 626 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 628 | goto out; |
| 629 | } |
| 630 | global.ca_base = strdup(args[1]); |
| 631 | #else |
| 632 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 634 | goto out; |
| 635 | #endif |
| 636 | } |
| 637 | else if (!strcmp(args[0], "crt-base")) { |
| 638 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 639 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 640 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 641 | if (global.crt_base != NULL) { |
| 642 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 643 | err_code |= ERR_ALERT; |
| 644 | goto out; |
| 645 | } |
| 646 | if (*(args[1]) == 0) { |
| 647 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 649 | goto out; |
| 650 | } |
| 651 | global.crt_base = strdup(args[1]); |
| 652 | #else |
| 653 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 655 | goto out; |
| 656 | #endif |
| 657 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 658 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 659 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 661 | global.mode |= MODE_DAEMON; |
| 662 | } |
| 663 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 664 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 665 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 666 | global.mode |= MODE_DEBUG; |
| 667 | } |
| 668 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 669 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 670 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 671 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 672 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 673 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 674 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 675 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 676 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 677 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 678 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 679 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 680 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 681 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 682 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 683 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 684 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 685 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 686 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 687 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 688 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 689 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 690 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 691 | global.tune.options &= ~GTUNE_USE_GAI; |
| 692 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 693 | else if (!strcmp(args[0], "noreuseport")) { |
| 694 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 695 | goto out; |
| 696 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 697 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 698 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 699 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 700 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 701 | global.mode |= MODE_QUIET; |
| 702 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 703 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 704 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 705 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 706 | if (global.tune.maxpollevents != 0) { |
| 707 | 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] | 708 | err_code |= ERR_ALERT; |
| 709 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 710 | } |
| 711 | if (*(args[1]) == 0) { |
| 712 | 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] | 713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 714 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 715 | } |
| 716 | global.tune.maxpollevents = atol(args[1]); |
| 717 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 718 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 719 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 720 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 721 | if (global.tune.maxaccept != 0) { |
| 722 | 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] | 723 | err_code |= ERR_ALERT; |
| 724 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 725 | } |
| 726 | if (*(args[1]) == 0) { |
| 727 | 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] | 728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 729 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 730 | } |
| 731 | global.tune.maxaccept = atol(args[1]); |
| 732 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 733 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 734 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 735 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 736 | if (*(args[1]) == 0) { |
| 737 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 739 | goto out; |
| 740 | } |
| 741 | global.tune.chksize = atol(args[1]); |
| 742 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 743 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 744 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 745 | goto out; |
| 746 | if (*(args[1]) == 0) { |
| 747 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 749 | goto out; |
| 750 | } |
| 751 | global.tune.recv_enough = atol(args[1]); |
| 752 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 753 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 754 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 755 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 756 | goto out; |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 757 | global.tune.sslprivatecache = 1; |
| 758 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 759 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 760 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 761 | goto out; |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 762 | if (*(args[1]) == 0) { |
| 763 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 765 | goto out; |
| 766 | } |
| 767 | global.tune.sslcachesize = atol(args[1]); |
| 768 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 769 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 770 | unsigned int ssllifetime; |
| 771 | const char *res; |
| 772 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 773 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 774 | goto out; |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 775 | if (*(args[1]) == 0) { |
| 776 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 778 | goto out; |
| 779 | } |
| 780 | |
| 781 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 782 | if (res) { |
| 783 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 784 | file, linenum, *res, args[0]); |
| 785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 786 | goto out; |
| 787 | } |
| 788 | |
| 789 | global.tune.ssllifetime = ssllifetime; |
| 790 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 791 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
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 | bfd5946 | 2013-02-21 07:46:09 +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.ssl_max_record = atol(args[1]); |
| 800 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 801 | #ifndef OPENSSL_NO_DH |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 802 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 803 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 804 | goto out; |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 805 | if (*(args[1]) == 0) { |
| 806 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 808 | goto out; |
| 809 | } |
| 810 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 811 | if (global.tune.ssl_default_dh_param < 1024) { |
| 812 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 814 | goto out; |
| 815 | } |
| 816 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 817 | #endif |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 818 | else if (!strcmp(args[0], "tune.ssl.ssl-ctx-cache-size")) { |
| 819 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 820 | goto out; |
| 821 | if (*(args[1]) == 0) { |
| 822 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | goto out; |
| 825 | } |
| 826 | global.tune.ssl_ctx_cache = atoi(args[1]); |
| 827 | if (global.tune.ssl_ctx_cache < 0) { |
| 828 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 829 | file, linenum, args[0]); |
| 830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 831 | goto out; |
| 832 | } |
| 833 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 834 | #endif |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 835 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
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 | 33cb065 | 2014-12-23 22:52:37 +0100 | [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.buf_limit = atol(args[1]); |
| 844 | if (global.tune.buf_limit) { |
| 845 | if (global.tune.buf_limit < 3) |
| 846 | global.tune.buf_limit = 3; |
| 847 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 848 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 849 | } |
| 850 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 851 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 852 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 853 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 854 | if (*(args[1]) == 0) { |
| 855 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 857 | goto out; |
| 858 | } |
| 859 | global.tune.reserved_bufs = atol(args[1]); |
| 860 | if (global.tune.reserved_bufs < 2) |
| 861 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 862 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 863 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 864 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 865 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 866 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 867 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 868 | if (*(args[1]) == 0) { |
| 869 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 871 | goto out; |
| 872 | } |
| 873 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 874 | if (global.tune.bufsize <= 0) { |
| 875 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 877 | goto out; |
| 878 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 879 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 880 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 881 | } |
| 882 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 883 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 884 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 885 | if (*(args[1]) == 0) { |
| 886 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 888 | goto out; |
| 889 | } |
| 890 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 891 | if (global.tune.maxrewrite < 0) { |
| 892 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 896 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 897 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 898 | unsigned int idle; |
| 899 | const char *res; |
| 900 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 901 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 902 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 903 | if (*(args[1]) == 0) { |
| 904 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 906 | goto out; |
| 907 | } |
| 908 | |
| 909 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 910 | if (res) { |
| 911 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 912 | file, linenum, *res, args[0]); |
| 913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 914 | goto out; |
| 915 | } |
| 916 | |
| 917 | if (idle > 65535) { |
| 918 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 920 | goto out; |
| 921 | } |
| 922 | global.tune.idle_timer = idle; |
| 923 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 924 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 925 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 926 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 927 | if (global.tune.client_rcvbuf != 0) { |
| 928 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 929 | err_code |= ERR_ALERT; |
| 930 | goto out; |
| 931 | } |
| 932 | if (*(args[1]) == 0) { |
| 933 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 935 | goto out; |
| 936 | } |
| 937 | global.tune.client_rcvbuf = atol(args[1]); |
| 938 | } |
| 939 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 940 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 941 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 942 | if (global.tune.server_rcvbuf != 0) { |
| 943 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 944 | err_code |= ERR_ALERT; |
| 945 | goto out; |
| 946 | } |
| 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.server_rcvbuf = atol(args[1]); |
| 953 | } |
| 954 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
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 | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 957 | if (global.tune.client_sndbuf != 0) { |
| 958 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 959 | err_code |= ERR_ALERT; |
| 960 | goto out; |
| 961 | } |
| 962 | if (*(args[1]) == 0) { |
| 963 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 965 | goto out; |
| 966 | } |
| 967 | global.tune.client_sndbuf = atol(args[1]); |
| 968 | } |
| 969 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 970 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 971 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 972 | if (global.tune.server_sndbuf != 0) { |
| 973 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 974 | err_code |= ERR_ALERT; |
| 975 | goto out; |
| 976 | } |
| 977 | if (*(args[1]) == 0) { |
| 978 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 980 | goto out; |
| 981 | } |
| 982 | global.tune.server_sndbuf = atol(args[1]); |
| 983 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 984 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 985 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 986 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 987 | if (*(args[1]) == 0) { |
| 988 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 990 | goto out; |
| 991 | } |
| 992 | global.tune.pipesize = atol(args[1]); |
| 993 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 994 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 995 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 996 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 997 | if (*(args[1]) == 0) { |
| 998 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1003 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1004 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1005 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1006 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1007 | if (*(args[1]) == 0) { |
| 1008 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1010 | goto out; |
| 1011 | } |
| 1012 | global.tune.max_http_hdr = atol(args[1]); |
| 1013 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1014 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 1015 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1016 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1017 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1018 | if (*args[1]) { |
| 1019 | global.tune.zlibmemlevel = atoi(args[1]); |
| 1020 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 1021 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1022 | file, linenum, args[0]); |
| 1023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1024 | goto out; |
| 1025 | } |
| 1026 | } else { |
| 1027 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1028 | file, linenum, args[0]); |
| 1029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1030 | goto out; |
| 1031 | } |
| 1032 | #else |
| 1033 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1035 | goto out; |
| 1036 | #endif |
| 1037 | } |
| 1038 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 1039 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1040 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1041 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1042 | if (*args[1]) { |
| 1043 | global.tune.zlibwindowsize = atoi(args[1]); |
| 1044 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 1045 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1046 | file, linenum, args[0]); |
| 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | } else { |
| 1051 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1052 | file, linenum, args[0]); |
| 1053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1054 | goto out; |
| 1055 | } |
| 1056 | #else |
| 1057 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1059 | goto out; |
| 1060 | #endif |
| 1061 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1062 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1063 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1064 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1065 | if (*args[1]) { |
| 1066 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1067 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 1068 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1069 | file, linenum, args[0]); |
| 1070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1071 | goto out; |
| 1072 | } |
| 1073 | } else { |
| 1074 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1075 | file, linenum, args[0]); |
| 1076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1080 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1081 | if (*args[1]) { |
| 1082 | global.tune.pattern_cache = atoi(args[1]); |
| 1083 | if (global.tune.pattern_cache < 0) { |
| 1084 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1085 | file, linenum, args[0]); |
| 1086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1087 | goto out; |
| 1088 | } |
| 1089 | } else { |
| 1090 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1091 | file, linenum, args[0]); |
| 1092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1093 | goto out; |
| 1094 | } |
| 1095 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1096 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1097 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1099 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1100 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1101 | err_code |= ERR_ALERT; |
| 1102 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1103 | } |
| 1104 | if (*(args[1]) == 0) { |
| 1105 | 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] | 1106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1108 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1109 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 1110 | Warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]); |
| 1111 | err_code |= ERR_WARN; |
| 1112 | goto out; |
| 1113 | } |
| 1114 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1115 | } |
| 1116 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1117 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1118 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1119 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1120 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1121 | err_code |= ERR_ALERT; |
| 1122 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1123 | } |
| 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 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1129 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 1130 | Warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]); |
| 1131 | err_code |= ERR_WARN; |
| 1132 | goto out; |
| 1133 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1134 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1135 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1136 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1137 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1138 | global.external_check = 1; |
| 1139 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1140 | /* user/group name handling */ |
| 1141 | else if (!strcmp(args[0], "user")) { |
| 1142 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1143 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1144 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1145 | if (global.uid != 0) { |
| 1146 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1147 | err_code |= ERR_ALERT; |
| 1148 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1149 | } |
| 1150 | errno = 0; |
| 1151 | ha_user = getpwnam(args[1]); |
| 1152 | if (ha_user != NULL) { |
| 1153 | global.uid = (int)ha_user->pw_uid; |
| 1154 | } |
| 1155 | else { |
| 1156 | 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] | 1157 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | else if (!strcmp(args[0], "group")) { |
| 1161 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1162 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1163 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1164 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1165 | 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] | 1166 | err_code |= ERR_ALERT; |
| 1167 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1168 | } |
| 1169 | errno = 0; |
| 1170 | ha_group = getgrnam(args[1]); |
| 1171 | if (ha_group != NULL) { |
| 1172 | global.gid = (int)ha_group->gr_gid; |
| 1173 | } |
| 1174 | else { |
| 1175 | 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] | 1176 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1180 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1181 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1182 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1183 | if (*(args[1]) == 0) { |
| 1184 | 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] | 1185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1187 | } |
| 1188 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1189 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1190 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1191 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1193 | goto out; |
| 1194 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1195 | } |
| 1196 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1197 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1199 | if (global.maxconn != 0) { |
| 1200 | 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] | 1201 | err_code |= ERR_ALERT; |
| 1202 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1203 | } |
| 1204 | if (*(args[1]) == 0) { |
| 1205 | 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] | 1206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1208 | } |
| 1209 | global.maxconn = atol(args[1]); |
| 1210 | #ifdef SYSTEM_MAXCONN |
| 1211 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1212 | 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); |
| 1213 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1214 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1215 | } |
| 1216 | #endif /* SYSTEM_MAXCONN */ |
| 1217 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1218 | else if (!strcmp(args[0], "maxsslconn")) { |
| 1219 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1220 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1221 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1222 | if (*(args[1]) == 0) { |
| 1223 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1225 | goto out; |
| 1226 | } |
| 1227 | global.maxsslconn = atol(args[1]); |
| 1228 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1229 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1231 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1232 | #endif |
| 1233 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1234 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 1235 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1236 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1237 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1238 | if (*(args[1]) == 0) { |
| 1239 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1241 | goto out; |
| 1242 | } |
| 1243 | free(global.listen_default_ciphers); |
| 1244 | global.listen_default_ciphers = strdup(args[1]); |
| 1245 | #else |
| 1246 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1248 | goto out; |
| 1249 | #endif |
| 1250 | } |
| 1251 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1252 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1253 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1254 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1255 | if (*(args[1]) == 0) { |
| 1256 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1258 | goto out; |
| 1259 | } |
| 1260 | free(global.connect_default_ciphers); |
| 1261 | global.connect_default_ciphers = strdup(args[1]); |
| 1262 | #else |
| 1263 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1265 | goto out; |
| 1266 | #endif |
| 1267 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 1268 | #ifdef USE_OPENSSL |
| 1269 | #ifndef OPENSSL_NO_DH |
| 1270 | else if (!strcmp(args[0], "ssl-dh-param-file")) { |
| 1271 | if (*(args[1]) == 0) { |
| 1272 | Alert("parsing [%s:%d] : '%s' expects a file path as an argument.\n", file, linenum, args[0]); |
| 1273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | if (ssl_sock_load_global_dh_param_from_file(args[1])) { |
| 1277 | Alert("parsing [%s:%d] : '%s': unable to load DH parameters from file <%s>.\n", file, linenum, args[0], args[1]); |
| 1278 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1279 | goto out; |
| 1280 | } |
| 1281 | } |
| 1282 | #endif |
| 1283 | #endif |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1284 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1285 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1286 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1287 | if (*(args[1]) == 0) { |
| 1288 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1290 | goto out; |
| 1291 | } |
| 1292 | if (strcmp(args[1],"none") == 0) |
| 1293 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1294 | else if (strcmp(args[1],"required") == 0) |
| 1295 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1296 | else { |
| 1297 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1299 | goto out; |
| 1300 | } |
| 1301 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1302 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1303 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1304 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1305 | if (global.cps_lim != 0) { |
| 1306 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1307 | err_code |= ERR_ALERT; |
| 1308 | goto out; |
| 1309 | } |
| 1310 | if (*(args[1]) == 0) { |
| 1311 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1313 | goto out; |
| 1314 | } |
| 1315 | global.cps_lim = atol(args[1]); |
| 1316 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1317 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1318 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1319 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1320 | if (global.sps_lim != 0) { |
| 1321 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1322 | err_code |= ERR_ALERT; |
| 1323 | goto out; |
| 1324 | } |
| 1325 | if (*(args[1]) == 0) { |
| 1326 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1328 | goto out; |
| 1329 | } |
| 1330 | global.sps_lim = atol(args[1]); |
| 1331 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1332 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1333 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1334 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1335 | if (global.ssl_lim != 0) { |
| 1336 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1337 | err_code |= ERR_ALERT; |
| 1338 | goto out; |
| 1339 | } |
| 1340 | if (*(args[1]) == 0) { |
| 1341 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1343 | goto out; |
| 1344 | } |
| 1345 | global.ssl_lim = atol(args[1]); |
| 1346 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1347 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1348 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1349 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1350 | if (*(args[1]) == 0) { |
| 1351 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1352 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1353 | goto out; |
| 1354 | } |
| 1355 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1356 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1357 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1358 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1359 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1360 | if (global.maxpipes != 0) { |
| 1361 | 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] | 1362 | err_code |= ERR_ALERT; |
| 1363 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1364 | } |
| 1365 | if (*(args[1]) == 0) { |
| 1366 | 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] | 1367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1368 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1369 | } |
| 1370 | global.maxpipes = atol(args[1]); |
| 1371 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1372 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1373 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1374 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1375 | if (*(args[1]) == 0) { |
| 1376 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1378 | goto out; |
| 1379 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1380 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1381 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1382 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1383 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1384 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1385 | if (*(args[1]) == 0) { |
| 1386 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1388 | goto out; |
| 1389 | } |
| 1390 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1391 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1392 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1394 | goto out; |
| 1395 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1396 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1397 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1398 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1399 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1400 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1401 | if (global.rlimit_nofile != 0) { |
| 1402 | 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] | 1403 | err_code |= ERR_ALERT; |
| 1404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1405 | } |
| 1406 | if (*(args[1]) == 0) { |
| 1407 | 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] | 1408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1409 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1410 | } |
| 1411 | global.rlimit_nofile = atol(args[1]); |
| 1412 | } |
| 1413 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1414 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1415 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1416 | if (global.chroot != NULL) { |
| 1417 | 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] | 1418 | err_code |= ERR_ALERT; |
| 1419 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1420 | } |
| 1421 | if (*(args[1]) == 0) { |
| 1422 | 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] | 1423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1424 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1425 | } |
| 1426 | global.chroot = strdup(args[1]); |
| 1427 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1428 | else if (!strcmp(args[0], "description")) { |
| 1429 | int i, len=0; |
| 1430 | char *d; |
| 1431 | |
| 1432 | if (!*args[1]) { |
| 1433 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1434 | file, linenum, args[0]); |
| 1435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1436 | goto out; |
| 1437 | } |
| 1438 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1439 | for (i = 1; *args[i]; i++) |
| 1440 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1441 | |
| 1442 | if (global.desc) |
| 1443 | free(global.desc); |
| 1444 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1445 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1446 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1447 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1448 | for (i = 2; *args[i]; i++) |
| 1449 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1450 | } |
| 1451 | else if (!strcmp(args[0], "node")) { |
| 1452 | int i; |
| 1453 | char c; |
| 1454 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1455 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1456 | goto out; |
| 1457 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1458 | for (i=0; args[1][i]; i++) { |
| 1459 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1460 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1461 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | |
| 1465 | if (!i || args[1][i]) { |
| 1466 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1467 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1468 | file, linenum, args[0]); |
| 1469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1470 | goto out; |
| 1471 | } |
| 1472 | |
| 1473 | if (global.node) |
| 1474 | free(global.node); |
| 1475 | |
| 1476 | global.node = strdup(args[1]); |
| 1477 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1478 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1479 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1480 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1481 | if (global.pidfile != NULL) { |
| 1482 | 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] | 1483 | err_code |= ERR_ALERT; |
| 1484 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1485 | } |
| 1486 | if (*(args[1]) == 0) { |
| 1487 | 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] | 1488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1489 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1490 | } |
| 1491 | global.pidfile = strdup(args[1]); |
| 1492 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1493 | else if (!strcmp(args[0], "unix-bind")) { |
| 1494 | int cur_arg = 1; |
| 1495 | while (*(args[cur_arg])) { |
| 1496 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1497 | if (global.unix_bind.prefix != NULL) { |
| 1498 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1499 | err_code |= ERR_ALERT; |
| 1500 | cur_arg += 2; |
| 1501 | continue; |
| 1502 | } |
| 1503 | |
| 1504 | if (*(args[cur_arg+1]) == 0) { |
| 1505 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1507 | goto out; |
| 1508 | } |
| 1509 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1510 | cur_arg += 2; |
| 1511 | continue; |
| 1512 | } |
| 1513 | |
| 1514 | if (!strcmp(args[cur_arg], "mode")) { |
| 1515 | |
| 1516 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1517 | cur_arg += 2; |
| 1518 | continue; |
| 1519 | } |
| 1520 | |
| 1521 | if (!strcmp(args[cur_arg], "uid")) { |
| 1522 | |
| 1523 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1524 | cur_arg += 2; |
| 1525 | continue; |
| 1526 | } |
| 1527 | |
| 1528 | if (!strcmp(args[cur_arg], "gid")) { |
| 1529 | |
| 1530 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1531 | cur_arg += 2; |
| 1532 | continue; |
| 1533 | } |
| 1534 | |
| 1535 | if (!strcmp(args[cur_arg], "user")) { |
| 1536 | struct passwd *user; |
| 1537 | |
| 1538 | user = getpwnam(args[cur_arg + 1]); |
| 1539 | if (!user) { |
| 1540 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1541 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1543 | goto out; |
| 1544 | } |
| 1545 | |
| 1546 | global.unix_bind.ux.uid = user->pw_uid; |
| 1547 | cur_arg += 2; |
| 1548 | continue; |
| 1549 | } |
| 1550 | |
| 1551 | if (!strcmp(args[cur_arg], "group")) { |
| 1552 | struct group *group; |
| 1553 | |
| 1554 | group = getgrnam(args[cur_arg + 1]); |
| 1555 | if (!group) { |
| 1556 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1557 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1559 | goto out; |
| 1560 | } |
| 1561 | |
| 1562 | global.unix_bind.ux.gid = group->gr_gid; |
| 1563 | cur_arg += 2; |
| 1564 | continue; |
| 1565 | } |
| 1566 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1567 | 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] | 1568 | file, linenum, args[0]); |
| 1569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1570 | goto out; |
| 1571 | } |
| 1572 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1573 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1574 | /* delete previous herited or defined syslog servers */ |
| 1575 | struct logsrv *back; |
| 1576 | struct logsrv *tmp; |
| 1577 | |
| 1578 | if (*(args[1]) != 0) { |
| 1579 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1581 | goto out; |
| 1582 | } |
| 1583 | |
| 1584 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1585 | LIST_DEL(&tmp->list); |
| 1586 | free(tmp); |
| 1587 | } |
| 1588 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1589 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1590 | struct sockaddr_storage *sk; |
| 1591 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1592 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1593 | int arg = 0; |
| 1594 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1595 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1596 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1597 | goto out; |
| 1598 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1599 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1600 | 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] | 1601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1602 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1603 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1604 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1605 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1606 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1607 | /* just after the address, a length may be specified */ |
| 1608 | if (strcmp(args[arg+2], "len") == 0) { |
| 1609 | len = atoi(args[arg+3]); |
| 1610 | if (len < 80 || len > 65535) { |
| 1611 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1612 | file, linenum, args[arg+3]); |
| 1613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1614 | goto out; |
| 1615 | } |
| 1616 | logsrv->maxlen = len; |
| 1617 | |
| 1618 | /* skip these two args */ |
| 1619 | arg += 2; |
| 1620 | } |
| 1621 | else |
| 1622 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1623 | |
| 1624 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1625 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 1626 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 1627 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 1628 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 1629 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1632 | /* after the length, a format may be specified */ |
| 1633 | if (strcmp(args[arg+2], "format") == 0) { |
| 1634 | logsrv->format = get_log_format(args[arg+3]); |
| 1635 | if (logsrv->format < 0) { |
| 1636 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1637 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1638 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1639 | goto out; |
| 1640 | } |
| 1641 | |
| 1642 | /* skip these two args */ |
| 1643 | arg += 2; |
| 1644 | } |
| 1645 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1646 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1647 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1648 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1649 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1650 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1651 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1652 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1653 | 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] | 1654 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1655 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1656 | } |
| 1657 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1658 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1659 | if (*(args[arg+3])) { |
| 1660 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1661 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1662 | 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] | 1663 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1664 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1668 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1669 | if (*(args[arg+4])) { |
| 1670 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1671 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1672 | 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] | 1673 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1674 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 1678 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1679 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1680 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1681 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1682 | free(logsrv); |
| 1683 | goto out; |
| 1684 | } |
| 1685 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1686 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1687 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1688 | if (port1 != port2) { |
| 1689 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1690 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1691 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1692 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1693 | goto out; |
| 1694 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1695 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1696 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1697 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1698 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1699 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1700 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1701 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1702 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1703 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1704 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1705 | |
| 1706 | if (global.log_send_hostname != NULL) { |
| 1707 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1708 | err_code |= ERR_ALERT; |
| 1709 | goto out; |
| 1710 | } |
| 1711 | |
| 1712 | if (*(args[1])) |
| 1713 | name = args[1]; |
| 1714 | else |
| 1715 | name = hostname; |
| 1716 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1717 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1718 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1719 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1720 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1721 | if (global.server_state_base != NULL) { |
| 1722 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1723 | err_code |= ERR_ALERT; |
| 1724 | goto out; |
| 1725 | } |
| 1726 | |
| 1727 | if (!*(args[1])) { |
| 1728 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1729 | err_code |= ERR_FATAL; |
| 1730 | goto out; |
| 1731 | } |
| 1732 | |
| 1733 | global.server_state_base = strdup(args[1]); |
| 1734 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1735 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1736 | if (global.server_state_file != NULL) { |
| 1737 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1738 | err_code |= ERR_ALERT; |
| 1739 | goto out; |
| 1740 | } |
| 1741 | |
| 1742 | if (!*(args[1])) { |
| 1743 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1744 | err_code |= ERR_FATAL; |
| 1745 | goto out; |
| 1746 | } |
| 1747 | |
| 1748 | global.server_state_file = strdup(args[1]); |
| 1749 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1750 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1751 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1752 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1753 | if (*(args[1]) == 0) { |
| 1754 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1756 | goto out; |
| 1757 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1758 | chunk_destroy(&global.log_tag); |
| 1759 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1760 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1761 | 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] | 1762 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1763 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1764 | if (global.spread_checks != 0) { |
| 1765 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1766 | err_code |= ERR_ALERT; |
| 1767 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1768 | } |
| 1769 | if (*(args[1]) == 0) { |
| 1770 | 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] | 1771 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1772 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1773 | } |
| 1774 | global.spread_checks = atol(args[1]); |
| 1775 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1776 | 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] | 1777 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1778 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1779 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1780 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1781 | const char *err; |
| 1782 | unsigned int val; |
| 1783 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1784 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1785 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1786 | if (*(args[1]) == 0) { |
| 1787 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1789 | goto out; |
| 1790 | } |
| 1791 | |
| 1792 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1793 | if (err) { |
| 1794 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1796 | } |
| 1797 | global.max_spread_checks = val; |
| 1798 | if (global.max_spread_checks < 0) { |
| 1799 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1801 | } |
| 1802 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1803 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1804 | #ifdef USE_CPU_AFFINITY |
| 1805 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1806 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1807 | unsigned long cpus = 0; |
| 1808 | |
| 1809 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1810 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1811 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1812 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1813 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1814 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1815 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1816 | proc = atol(args[1]); |
| 1817 | if (proc >= 1 && proc <= LONGBITS) |
| 1818 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1822 | 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", |
| 1823 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1825 | goto out; |
| 1826 | } |
| 1827 | |
| 1828 | cur_arg = 2; |
| 1829 | while (*args[cur_arg]) { |
| 1830 | unsigned int low, high; |
| 1831 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1832 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1833 | char *dash = strchr(args[cur_arg], '-'); |
| 1834 | |
| 1835 | low = high = str2uic(args[cur_arg]); |
| 1836 | if (dash) |
| 1837 | high = str2uic(dash + 1); |
| 1838 | |
| 1839 | if (high < low) { |
| 1840 | unsigned int swap = low; |
| 1841 | low = high; |
| 1842 | high = swap; |
| 1843 | } |
| 1844 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1845 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1846 | 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] | 1847 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1849 | goto out; |
| 1850 | } |
| 1851 | |
| 1852 | while (low <= high) |
| 1853 | cpus |= 1UL << low++; |
| 1854 | } |
| 1855 | else { |
| 1856 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1857 | file, linenum, args[0], args[cur_arg]); |
| 1858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1859 | goto out; |
| 1860 | } |
| 1861 | cur_arg++; |
| 1862 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1863 | for (i = 0; i < LONGBITS; i++) |
| 1864 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1865 | global.cpu_map[i] = cpus; |
| 1866 | #else |
| 1867 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1869 | goto out; |
| 1870 | #endif |
| 1871 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1872 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1873 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1874 | goto out; |
| 1875 | |
| 1876 | if (*(args[2]) == 0) { |
| 1877 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1879 | goto out; |
| 1880 | } |
| 1881 | |
| 1882 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1883 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1884 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1886 | goto out; |
| 1887 | } |
| 1888 | } |
| 1889 | else if (!strcmp(args[0], "unsetenv")) { |
| 1890 | int arg; |
| 1891 | |
| 1892 | if (*(args[1]) == 0) { |
| 1893 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1895 | goto out; |
| 1896 | } |
| 1897 | |
| 1898 | for (arg = 1; *args[arg]; arg++) { |
| 1899 | if (unsetenv(args[arg]) != 0) { |
| 1900 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1902 | goto out; |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | else if (!strcmp(args[0], "resetenv")) { |
| 1907 | extern char **environ; |
| 1908 | char **env = environ; |
| 1909 | |
| 1910 | /* args contain variable names to keep, one per argument */ |
| 1911 | while (*env) { |
| 1912 | int arg; |
| 1913 | |
| 1914 | /* look for current variable in among all those we want to keep */ |
| 1915 | for (arg = 1; *args[arg]; arg++) { |
| 1916 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1917 | (*env)[strlen(args[arg])] == '=') |
| 1918 | break; |
| 1919 | } |
| 1920 | |
| 1921 | /* delete this variable */ |
| 1922 | if (!*args[arg]) { |
| 1923 | char *delim = strchr(*env, '='); |
| 1924 | |
| 1925 | if (!delim || delim - *env >= trash.size) { |
| 1926 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
| 1931 | memcpy(trash.str, *env, delim - *env); |
| 1932 | trash.str[delim - *env] = 0; |
| 1933 | |
| 1934 | if (unsetenv(trash.str) != 0) { |
| 1935 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1937 | goto out; |
| 1938 | } |
| 1939 | } |
| 1940 | else |
| 1941 | env++; |
| 1942 | } |
| 1943 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1944 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1945 | struct cfg_kw_list *kwl; |
| 1946 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1947 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1948 | |
| 1949 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1950 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1951 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1952 | continue; |
| 1953 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1954 | 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] | 1955 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1956 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1957 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1958 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1959 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1960 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1961 | err_code |= ERR_WARN; |
| 1962 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1963 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1964 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | } |
| 1968 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1969 | 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] | 1970 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1971 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1972 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1973 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1974 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1975 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1976 | } |
| 1977 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1978 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1979 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1980 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1981 | defproxy.mode = PR_MODE_TCP; |
| 1982 | defproxy.state = PR_STNEW; |
| 1983 | defproxy.maxconn = cfg_maxpconn; |
| 1984 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1985 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1986 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1987 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1988 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1989 | defproxy.defsrv.check.fastinter = 0; |
| 1990 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1991 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1992 | defproxy.defsrv.agent.fastinter = 0; |
| 1993 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1994 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1995 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1996 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1997 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1998 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1999 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2000 | defproxy.defsrv.maxqueue = 0; |
| 2001 | defproxy.defsrv.minconn = 0; |
| 2002 | defproxy.defsrv.maxconn = 0; |
| 2003 | defproxy.defsrv.slowstart = 0; |
| 2004 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 2005 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 2006 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2007 | |
| 2008 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2009 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2012 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2013 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 2014 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 2015 | * ERR_FATAL in case of error. |
| 2016 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2017 | static int create_cond_regex_rule(const char *file, int line, |
| 2018 | struct proxy *px, int dir, int action, int flags, |
| 2019 | const char *cmd, const char *reg, const char *repl, |
| 2020 | const char **cond_start) |
| 2021 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2022 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2023 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2024 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2025 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2026 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2027 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2028 | int cs; |
| 2029 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2030 | |
| 2031 | if (px == &defproxy) { |
| 2032 | 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] | 2033 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2034 | goto err; |
| 2035 | } |
| 2036 | |
| 2037 | if (*reg == 0) { |
| 2038 | 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] | 2039 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2040 | goto err; |
| 2041 | } |
| 2042 | |
| 2043 | if (warnifnotcap(px, PR_CAP_RS, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2044 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2045 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2046 | if (cond_start && |
| 2047 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2048 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 2049 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 2050 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2051 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2052 | goto err; |
| 2053 | } |
| 2054 | } |
| 2055 | else if (cond_start && **cond_start) { |
| 2056 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 2057 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2058 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2059 | goto err; |
| 2060 | } |
| 2061 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2062 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2063 | (dir == SMP_OPT_DIR_REQ) ? |
| 2064 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 2065 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 2066 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2067 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2068 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2069 | if (!preg) { |
| 2070 | 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] | 2071 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2072 | goto err; |
| 2073 | } |
| 2074 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2075 | cs = !(flags & REG_ICASE); |
| 2076 | cap = !(flags & REG_NOSUB); |
| 2077 | error = NULL; |
| 2078 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 2079 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 2080 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2081 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2082 | goto err; |
| 2083 | } |
| 2084 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2085 | 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] | 2086 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2087 | if (repl && err) { |
| 2088 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 2089 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2090 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 2091 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2094 | 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] | 2095 | ret_code |= ERR_WARN; |
| 2096 | |
| 2097 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2098 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2099 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2100 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2101 | err: |
| 2102 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2103 | free(errmsg); |
| 2104 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2107 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2108 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2109 | * Returns the error code, 0 if OK, or any combination of : |
| 2110 | * - ERR_ABORT: must abort ASAP |
| 2111 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2112 | * - ERR_WARN: a warning has been emitted |
| 2113 | * - ERR_ALERT: an alert has been emitted |
| 2114 | * Only the two first ones can stop processing, the two others are just |
| 2115 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2116 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2117 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 2118 | { |
| 2119 | static struct peers *curpeers = NULL; |
| 2120 | struct peer *newpeer = NULL; |
| 2121 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2122 | struct bind_conf *bind_conf; |
| 2123 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2124 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2125 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2126 | |
| 2127 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2128 | if (!*args[1]) { |
| 2129 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2130 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2131 | goto out; |
| 2132 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2133 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2134 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2135 | goto out; |
| 2136 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2137 | err = invalid_char(args[1]); |
| 2138 | if (err) { |
| 2139 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2140 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2141 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2142 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 2146 | /* |
| 2147 | * If there are two proxies with the same name only following |
| 2148 | * combinations are allowed: |
| 2149 | */ |
| 2150 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2151 | 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] | 2152 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2153 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2157 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2158 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2159 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2160 | goto out; |
| 2161 | } |
| 2162 | |
| 2163 | curpeers->next = peers; |
| 2164 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2165 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2166 | curpeers->conf.line = linenum; |
| 2167 | curpeers->last_change = now.tv_sec; |
| 2168 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2169 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2170 | } |
| 2171 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2172 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2173 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2174 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2175 | |
| 2176 | if (!*args[2]) { |
| 2177 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2178 | file, linenum, args[0]); |
| 2179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2180 | goto out; |
| 2181 | } |
| 2182 | |
| 2183 | err = invalid_char(args[1]); |
| 2184 | if (err) { |
| 2185 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2186 | file, linenum, *err, args[1]); |
| 2187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2188 | goto out; |
| 2189 | } |
| 2190 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2191 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2192 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2193 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2194 | goto out; |
| 2195 | } |
| 2196 | |
| 2197 | /* the peers are linked backwards first */ |
| 2198 | curpeers->count++; |
| 2199 | newpeer->next = curpeers->remote; |
| 2200 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2201 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2202 | newpeer->conf.line = linenum; |
| 2203 | |
| 2204 | newpeer->last_change = now.tv_sec; |
| 2205 | newpeer->id = strdup(args[1]); |
| 2206 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2207 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2208 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2209 | 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] | 2210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2211 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2212 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2213 | |
| 2214 | proto = protocol_by_family(sk->ss_family); |
| 2215 | if (!proto || !proto->connect) { |
| 2216 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2217 | file, linenum, args[0], args[1]); |
| 2218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2219 | goto out; |
| 2220 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2221 | |
| 2222 | if (port1 != port2) { |
| 2223 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2224 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2226 | goto out; |
| 2227 | } |
| 2228 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2229 | if (!port1) { |
| 2230 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2231 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2233 | goto out; |
| 2234 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2235 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2236 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2237 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 2238 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2239 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2240 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2241 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2242 | /* Current is local peer, it define a frontend */ |
| 2243 | newpeer->local = 1; |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 2244 | peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2245 | |
| 2246 | if (!curpeers->peers_fe) { |
| 2247 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2248 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2249 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2250 | goto out; |
| 2251 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2252 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2253 | init_new_proxy(curpeers->peers_fe); |
| 2254 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2255 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2256 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2257 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2258 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2259 | |
| 2260 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 2261 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2262 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2263 | if (errmsg && *errmsg) { |
| 2264 | indent_msg(&errmsg, 2); |
| 2265 | 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] | 2266 | } |
| 2267 | else |
| 2268 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2269 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2270 | err_code |= ERR_FATAL; |
| 2271 | goto out; |
| 2272 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2273 | |
| 2274 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2275 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2276 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2277 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2278 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2279 | l->handler = process_stream; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2280 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2281 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2282 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2283 | global.maxsock += l->maxconn; |
| 2284 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2285 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2286 | else { |
| 2287 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2288 | file, linenum, args[0], args[1], |
| 2289 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2290 | err_code |= ERR_FATAL; |
| 2291 | goto out; |
| 2292 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2293 | } |
| 2294 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2295 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2296 | curpeers->state = PR_STSTOPPED; |
| 2297 | } |
| 2298 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2299 | curpeers->state = PR_STNEW; |
| 2300 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2301 | else if (*args[0] != 0) { |
| 2302 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2304 | goto out; |
| 2305 | } |
| 2306 | |
| 2307 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2308 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2309 | return err_code; |
| 2310 | } |
| 2311 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2312 | /* |
| 2313 | * Parse a <resolvers> section. |
| 2314 | * Returns the error code, 0 if OK, or any combination of : |
| 2315 | * - ERR_ABORT: must abort ASAP |
| 2316 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2317 | * - ERR_WARN: a warning has been emitted |
| 2318 | * - ERR_ALERT: an alert has been emitted |
| 2319 | * Only the two first ones can stop processing, the two others are just |
| 2320 | * indicators. |
| 2321 | */ |
| 2322 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2323 | { |
| 2324 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2325 | struct dns_nameserver *newnameserver = NULL; |
| 2326 | const char *err; |
| 2327 | int err_code = 0; |
| 2328 | char *errmsg = NULL; |
| 2329 | |
| 2330 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2331 | if (!*args[1]) { |
| 2332 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2333 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2334 | goto out; |
| 2335 | } |
| 2336 | |
| 2337 | err = invalid_char(args[1]); |
| 2338 | if (err) { |
| 2339 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2340 | file, linenum, *err, args[0], args[1]); |
| 2341 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2342 | goto out; |
| 2343 | } |
| 2344 | |
| 2345 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2346 | /* Error if two resolvers owns the same name */ |
| 2347 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2348 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2349 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2350 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2351 | } |
| 2352 | } |
| 2353 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2354 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2355 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2356 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2357 | goto out; |
| 2358 | } |
| 2359 | |
| 2360 | /* default values */ |
| 2361 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2362 | curr_resolvers->conf.file = strdup(file); |
| 2363 | curr_resolvers->conf.line = linenum; |
| 2364 | curr_resolvers->id = strdup(args[1]); |
| 2365 | curr_resolvers->query_ids = EB_ROOT; |
| 2366 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2367 | curr_resolvers->hold.valid = 10000; |
| 2368 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2369 | curr_resolvers->resolve_retries = 3; |
| 2370 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2371 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2372 | } |
| 2373 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2374 | struct sockaddr_storage *sk; |
| 2375 | int port1, port2; |
| 2376 | struct protocol *proto; |
| 2377 | |
| 2378 | if (!*args[2]) { |
| 2379 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2380 | file, linenum, args[0]); |
| 2381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2382 | goto out; |
| 2383 | } |
| 2384 | |
| 2385 | err = invalid_char(args[1]); |
| 2386 | if (err) { |
| 2387 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2388 | file, linenum, *err, args[1]); |
| 2389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2393 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2394 | /* Error if two resolvers owns the same name */ |
| 2395 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2396 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2397 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2399 | } |
| 2400 | } |
| 2401 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2402 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2403 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2404 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2405 | goto out; |
| 2406 | } |
| 2407 | |
| 2408 | /* the nameservers are linked backward first */ |
| 2409 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2410 | curr_resolvers->count_nameservers++; |
| 2411 | newnameserver->resolvers = curr_resolvers; |
| 2412 | newnameserver->conf.file = strdup(file); |
| 2413 | newnameserver->conf.line = linenum; |
| 2414 | newnameserver->id = strdup(args[1]); |
| 2415 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2416 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2417 | if (!sk) { |
| 2418 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2420 | goto out; |
| 2421 | } |
| 2422 | |
| 2423 | proto = protocol_by_family(sk->ss_family); |
| 2424 | if (!proto || !proto->connect) { |
| 2425 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2426 | file, linenum, args[0], args[1]); |
| 2427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2428 | goto out; |
| 2429 | } |
| 2430 | |
| 2431 | if (port1 != port2) { |
| 2432 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2433 | file, linenum, args[0], args[1], args[2]); |
| 2434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2435 | goto out; |
| 2436 | } |
| 2437 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2438 | if (!port1 && !port2) { |
| 2439 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2440 | file, linenum, args[0], args[1]); |
| 2441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2442 | goto out; |
| 2443 | } |
| 2444 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2445 | newnameserver->addr = *sk; |
| 2446 | } |
| 2447 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2448 | const char *res; |
| 2449 | unsigned int time; |
| 2450 | |
| 2451 | if (!*args[2]) { |
| 2452 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2453 | file, linenum, args[0]); |
| 2454 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2456 | goto out; |
| 2457 | } |
| 2458 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2459 | if (res) { |
| 2460 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2461 | file, linenum, *res, args[0]); |
| 2462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2463 | goto out; |
| 2464 | } |
| 2465 | if (strcmp(args[1], "valid") == 0) |
| 2466 | curr_resolvers->hold.valid = time; |
| 2467 | else { |
| 2468 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects 'valid'\n", |
| 2469 | file, linenum, args[0], args[1]); |
| 2470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2471 | goto out; |
| 2472 | } |
| 2473 | |
| 2474 | } |
| 2475 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2476 | if (!*args[1]) { |
| 2477 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2478 | file, linenum, args[0]); |
| 2479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2480 | goto out; |
| 2481 | } |
| 2482 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2483 | } |
| 2484 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2485 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2486 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2487 | file, linenum, args[0]); |
| 2488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2489 | goto out; |
| 2490 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2491 | else if (strcmp(args[1], "retry") == 0) { |
| 2492 | const char *res; |
| 2493 | unsigned int timeout_retry; |
| 2494 | |
| 2495 | if (!*args[2]) { |
| 2496 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2497 | file, linenum, args[0], args[1]); |
| 2498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2499 | goto out; |
| 2500 | } |
| 2501 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2502 | if (res) { |
| 2503 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2504 | file, linenum, *res, args[0], args[1]); |
| 2505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2506 | goto out; |
| 2507 | } |
| 2508 | curr_resolvers->timeout.retry = timeout_retry; |
| 2509 | } |
| 2510 | else { |
| 2511 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2512 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2514 | goto out; |
| 2515 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2516 | } /* neither "nameserver" nor "resolvers" */ |
| 2517 | else if (*args[0] != 0) { |
| 2518 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2520 | goto out; |
| 2521 | } |
| 2522 | |
| 2523 | out: |
| 2524 | free(errmsg); |
| 2525 | return err_code; |
| 2526 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2527 | |
| 2528 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2529 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2530 | * Returns the error code, 0 if OK, or any combination of : |
| 2531 | * - ERR_ABORT: must abort ASAP |
| 2532 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2533 | * - ERR_WARN: a warning has been emitted |
| 2534 | * - ERR_ALERT: an alert has been emitted |
| 2535 | * Only the two first ones can stop processing, the two others are just |
| 2536 | * indicators. |
| 2537 | */ |
| 2538 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2539 | { |
| 2540 | static struct mailers *curmailers = NULL; |
| 2541 | struct mailer *newmailer = NULL; |
| 2542 | const char *err; |
| 2543 | int err_code = 0; |
| 2544 | char *errmsg = NULL; |
| 2545 | |
| 2546 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2547 | if (!*args[1]) { |
| 2548 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2549 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2550 | goto out; |
| 2551 | } |
| 2552 | |
| 2553 | err = invalid_char(args[1]); |
| 2554 | if (err) { |
| 2555 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2556 | file, linenum, *err, args[0], args[1]); |
| 2557 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2558 | goto out; |
| 2559 | } |
| 2560 | |
| 2561 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2562 | /* |
| 2563 | * If there are two proxies with the same name only following |
| 2564 | * combinations are allowed: |
| 2565 | */ |
| 2566 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2567 | 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] | 2568 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2569 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2573 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2574 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2575 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2576 | goto out; |
| 2577 | } |
| 2578 | |
| 2579 | curmailers->next = mailers; |
| 2580 | mailers = curmailers; |
| 2581 | curmailers->conf.file = strdup(file); |
| 2582 | curmailers->conf.line = linenum; |
| 2583 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2584 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2585 | * But need enough time so that timeouts don't occur |
| 2586 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2587 | } |
| 2588 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2589 | struct sockaddr_storage *sk; |
| 2590 | int port1, port2; |
| 2591 | struct protocol *proto; |
| 2592 | |
| 2593 | if (!*args[2]) { |
| 2594 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2595 | file, linenum, args[0]); |
| 2596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2597 | goto out; |
| 2598 | } |
| 2599 | |
| 2600 | err = invalid_char(args[1]); |
| 2601 | if (err) { |
| 2602 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2603 | file, linenum, *err, args[1]); |
| 2604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2605 | goto out; |
| 2606 | } |
| 2607 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2608 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2609 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2610 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2611 | goto out; |
| 2612 | } |
| 2613 | |
| 2614 | /* the mailers are linked backwards first */ |
| 2615 | curmailers->count++; |
| 2616 | newmailer->next = curmailers->mailer_list; |
| 2617 | curmailers->mailer_list = newmailer; |
| 2618 | newmailer->mailers = curmailers; |
| 2619 | newmailer->conf.file = strdup(file); |
| 2620 | newmailer->conf.line = linenum; |
| 2621 | |
| 2622 | newmailer->id = strdup(args[1]); |
| 2623 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2624 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2625 | if (!sk) { |
| 2626 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2628 | goto out; |
| 2629 | } |
| 2630 | |
| 2631 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2632 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2633 | 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] | 2634 | file, linenum, args[0], args[1]); |
| 2635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2636 | goto out; |
| 2637 | } |
| 2638 | |
| 2639 | if (port1 != port2) { |
| 2640 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2641 | file, linenum, args[0], args[1], args[2]); |
| 2642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
| 2646 | if (!port1) { |
| 2647 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2648 | file, linenum, args[0], args[1], args[2]); |
| 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
| 2653 | newmailer->addr = *sk; |
| 2654 | newmailer->proto = proto; |
| 2655 | newmailer->xprt = &raw_sock; |
| 2656 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2657 | } |
| 2658 | else if (strcmp(args[0], "timeout") == 0) { |
| 2659 | if (!*args[1]) { |
| 2660 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2661 | file, linenum, args[0]); |
| 2662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2663 | goto out; |
| 2664 | } |
| 2665 | else if (strcmp(args[1], "mail") == 0) { |
| 2666 | const char *res; |
| 2667 | unsigned int timeout_mail; |
| 2668 | if (!*args[2]) { |
| 2669 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2670 | file, linenum, args[0], args[1]); |
| 2671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2672 | goto out; |
| 2673 | } |
| 2674 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2675 | if (res) { |
| 2676 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2677 | file, linenum, *res, args[0]); |
| 2678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2679 | goto out; |
| 2680 | } |
| 2681 | if (timeout_mail <= 0) { |
| 2682 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | curmailers->timeout.mail = timeout_mail; |
| 2687 | } else { |
| 2688 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2689 | file, linenum, args[0], args[1]); |
| 2690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2691 | goto out; |
| 2692 | } |
| 2693 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2694 | else if (*args[0] != 0) { |
| 2695 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
| 2698 | } |
| 2699 | |
| 2700 | out: |
| 2701 | free(errmsg); |
| 2702 | return err_code; |
| 2703 | } |
| 2704 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2705 | static void free_email_alert(struct proxy *p) |
| 2706 | { |
| 2707 | free(p->email_alert.mailers.name); |
| 2708 | p->email_alert.mailers.name = NULL; |
| 2709 | free(p->email_alert.from); |
| 2710 | p->email_alert.from = NULL; |
| 2711 | free(p->email_alert.to); |
| 2712 | p->email_alert.to = NULL; |
| 2713 | free(p->email_alert.myhostname); |
| 2714 | p->email_alert.myhostname = NULL; |
| 2715 | } |
| 2716 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2717 | 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] | 2718 | { |
| 2719 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2720 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2721 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2722 | int rc; |
| 2723 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2724 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2725 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2726 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2727 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2728 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2729 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2730 | if (!strcmp(args[0], "listen")) |
| 2731 | rc = PR_CAP_LISTEN; |
| 2732 | else if (!strcmp(args[0], "frontend")) |
| 2733 | rc = PR_CAP_FE | PR_CAP_RS; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2734 | else if (!strcmp(args[0], "backend")) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2735 | rc = PR_CAP_BE | PR_CAP_RS; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2736 | else |
| 2737 | rc = PR_CAP_NONE; |
| 2738 | |
| 2739 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2740 | if (!*args[1]) { |
| 2741 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2742 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2743 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2744 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2746 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2747 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2748 | err = invalid_char(args[1]); |
| 2749 | if (err) { |
| 2750 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2751 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2752 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2753 | } |
| 2754 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2755 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2756 | if (curproxy) { |
| 2757 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2758 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2759 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2760 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2761 | } |
| 2762 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2763 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2764 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2765 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2766 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2767 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2768 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2769 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2770 | curproxy->next = proxy; |
| 2771 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2772 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2773 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2774 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2775 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2776 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2777 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2778 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2779 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2780 | if (curproxy->cap & PR_CAP_FE) |
| 2781 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2782 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2786 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2787 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2788 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2789 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2790 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2791 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2792 | curproxy->no_options = defproxy.no_options; |
| 2793 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2794 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2795 | curproxy->except_net = defproxy.except_net; |
| 2796 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2797 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2798 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2799 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2800 | if (defproxy.fwdfor_hdr_len) { |
| 2801 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2802 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2803 | } |
| 2804 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2805 | if (defproxy.orgto_hdr_len) { |
| 2806 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2807 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2808 | } |
| 2809 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2810 | if (defproxy.server_id_hdr_len) { |
| 2811 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2812 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2813 | } |
| 2814 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2815 | if (curproxy->cap & PR_CAP_FE) { |
| 2816 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2817 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2818 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2819 | |
| 2820 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2821 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2822 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2823 | |
| 2824 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2825 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2826 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2827 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2828 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2829 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2830 | curproxy->fullconn = defproxy.fullconn; |
| 2831 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2832 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2833 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2834 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2835 | if (defproxy.check_req) { |
| 2836 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2837 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2838 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2839 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2840 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2841 | if (defproxy.expect_str) { |
| 2842 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2843 | if (defproxy.expect_regex) { |
| 2844 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2845 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2846 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2850 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2851 | if (defproxy.cookie_name) |
| 2852 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2853 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2854 | if (defproxy.cookie_domain) |
| 2855 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2856 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2857 | if (defproxy.cookie_maxidle) |
| 2858 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2859 | |
| 2860 | if (defproxy.cookie_maxlife) |
| 2861 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2862 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2863 | if (defproxy.rdp_cookie_name) |
| 2864 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2865 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2866 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2867 | if (defproxy.url_param_name) |
| 2868 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2869 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2870 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2871 | if (defproxy.hh_name) |
| 2872 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2873 | curproxy->hh_len = defproxy.hh_len; |
| 2874 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2875 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2876 | if (defproxy.conn_src.iface_name) |
| 2877 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2878 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2879 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2880 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2881 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2882 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2883 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2884 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2885 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2886 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2887 | if (defproxy.capture_name) |
| 2888 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2889 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2890 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2891 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2892 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2893 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2894 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2895 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2896 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2897 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2898 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2899 | curproxy->mon_net = defproxy.mon_net; |
| 2900 | curproxy->mon_mask = defproxy.mon_mask; |
| 2901 | if (defproxy.monitor_uri) |
| 2902 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2903 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2904 | if (defproxy.defbe.name) |
| 2905 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2906 | |
| 2907 | /* 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] | 2908 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2909 | if (curproxy->conf.logformat_string && |
| 2910 | curproxy->conf.logformat_string != default_http_log_format && |
| 2911 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2912 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2913 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2914 | |
| 2915 | if (defproxy.conf.lfs_file) { |
| 2916 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2917 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2918 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2919 | |
| 2920 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2921 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2922 | if (curproxy->conf.logformat_sd_string && |
| 2923 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2924 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2925 | |
| 2926 | if (defproxy.conf.lfsd_file) { |
| 2927 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2928 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2929 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2933 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2934 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2935 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2936 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2937 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2938 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2939 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2940 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2941 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2942 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2943 | } |
| 2944 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2945 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2946 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2947 | |
| 2948 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2949 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2950 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2951 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2952 | LIST_INIT(&node->list); |
| 2953 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2954 | } |
| 2955 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2956 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2957 | if (curproxy->conf.uniqueid_format_string) |
| 2958 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2959 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2960 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2961 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2962 | if (defproxy.conf.uif_file) { |
| 2963 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2964 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2965 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2966 | |
| 2967 | /* copy default header unique id */ |
| 2968 | if (defproxy.header_unique_id) |
| 2969 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2970 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2971 | /* default compression options */ |
| 2972 | if (defproxy.comp != NULL) { |
| 2973 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2974 | curproxy->comp->algos = defproxy.comp->algos; |
| 2975 | curproxy->comp->types = defproxy.comp->types; |
| 2976 | } |
| 2977 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2978 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2979 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2980 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2981 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2982 | if (defproxy.check_path) |
| 2983 | curproxy->check_path = strdup(defproxy.check_path); |
| 2984 | if (defproxy.check_command) |
| 2985 | curproxy->check_command = strdup(defproxy.check_command); |
| 2986 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2987 | if (defproxy.email_alert.mailers.name) |
| 2988 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 2989 | if (defproxy.email_alert.from) |
| 2990 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 2991 | if (defproxy.email_alert.to) |
| 2992 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 2993 | if (defproxy.email_alert.myhostname) |
| 2994 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2995 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 2996 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2997 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2998 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2999 | } |
| 3000 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3001 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3002 | /* FIXME-20070101: we should do this too at the end of the |
| 3003 | * config parsing to free all default values. |
| 3004 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3005 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3006 | err_code |= ERR_ABORT; |
| 3007 | goto out; |
| 3008 | } |
| 3009 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3010 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3011 | free(defproxy.check_command); |
| 3012 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3013 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3014 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3015 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3016 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3017 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3018 | free(defproxy.capture_name); |
| 3019 | free(defproxy.monitor_uri); |
| 3020 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3021 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3022 | free(defproxy.fwdfor_hdr_name); |
| 3023 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3024 | free(defproxy.orgto_hdr_name); |
| 3025 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3026 | free(defproxy.server_id_hdr_name); |
| 3027 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3028 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3029 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3030 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3031 | free(defproxy.expect_regex); |
| 3032 | defproxy.expect_regex = NULL; |
| 3033 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3034 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3035 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3036 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3037 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3038 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3039 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3040 | free(defproxy.conf.uniqueid_format_string); |
| 3041 | free(defproxy.conf.lfs_file); |
| 3042 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3043 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3044 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3045 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3046 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3047 | free(defproxy.conf.logformat_sd_string); |
| 3048 | free(defproxy.conf.lfsd_file); |
| 3049 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3050 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3051 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3053 | /* we cannot free uri_auth because it might already be used */ |
| 3054 | init_default_instance(); |
| 3055 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3056 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3057 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3058 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3059 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3060 | } |
| 3061 | else if (curproxy == NULL) { |
| 3062 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3064 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3065 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3066 | |
| 3067 | /* update the current file and line being parsed */ |
| 3068 | curproxy->conf.args.file = curproxy->conf.file; |
| 3069 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3070 | |
| 3071 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3072 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 3073 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3074 | if (err_code & ERR_FATAL) |
| 3075 | goto out; |
| 3076 | } |
| 3077 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3078 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3079 | int cur_arg; |
| 3080 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3081 | if (curproxy == &defproxy) { |
| 3082 | 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] | 3083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3085 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3086 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3087 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3088 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3089 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 3090 | 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] | 3091 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3092 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3093 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3094 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3095 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 3096 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 3097 | |
| 3098 | /* use default settings for unix sockets */ |
| 3099 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3100 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3101 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3102 | |
| 3103 | /* NOTE: the following line might create several listeners if there |
| 3104 | * are comma-separated IPs or port ranges. So all further processing |
| 3105 | * will have to be applied to all listeners created after last_listen. |
| 3106 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3107 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3108 | if (errmsg && *errmsg) { |
| 3109 | indent_msg(&errmsg, 2); |
| 3110 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 3111 | } |
| 3112 | else |
| 3113 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3114 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3116 | goto out; |
| 3117 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3118 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3119 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3120 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3121 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3122 | } |
| 3123 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3124 | cur_arg = 2; |
| 3125 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3126 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3127 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3128 | char *err; |
| 3129 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3130 | kw = bind_find_kw(args[cur_arg]); |
| 3131 | if (kw) { |
| 3132 | char *err = NULL; |
| 3133 | int code; |
| 3134 | |
| 3135 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3136 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3137 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3138 | cur_arg += 1 + kw->skip ; |
| 3139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3140 | goto out; |
| 3141 | } |
| 3142 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3143 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3144 | err_code |= code; |
| 3145 | |
| 3146 | if (code) { |
| 3147 | if (err && *err) { |
| 3148 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3149 | 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] | 3150 | } |
| 3151 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3152 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3153 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3154 | if (code & ERR_FATAL) { |
| 3155 | free(err); |
| 3156 | cur_arg += 1 + kw->skip; |
| 3157 | goto out; |
| 3158 | } |
| 3159 | } |
| 3160 | free(err); |
| 3161 | cur_arg += 1 + kw->skip; |
| 3162 | continue; |
| 3163 | } |
| 3164 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3165 | err = NULL; |
| 3166 | if (!bind_dumped) { |
| 3167 | bind_dump_kws(&err); |
| 3168 | indent_msg(&err, 4); |
| 3169 | bind_dumped = 1; |
| 3170 | } |
| 3171 | |
| 3172 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3173 | file, linenum, args[0], args[1], args[cur_arg], |
| 3174 | err ? " Registered keywords :" : "", err ? err : ""); |
| 3175 | free(err); |
| 3176 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3178 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3179 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3180 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3181 | } |
| 3182 | 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] | 3183 | 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] | 3184 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3185 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3188 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3189 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3190 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3191 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3192 | /* flush useless bits */ |
| 3193 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3194 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3195 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3196 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3197 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3198 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3199 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3200 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3201 | goto out; |
| 3202 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3203 | if (!*args[1]) { |
| 3204 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3205 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3207 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3208 | } |
| 3209 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3210 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3211 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3212 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3213 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3214 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3215 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3216 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3217 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3218 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3219 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3220 | goto out; |
| 3221 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3222 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3223 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3224 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3225 | else { |
| 3226 | 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] | 3227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3228 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3229 | } |
| 3230 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3231 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3232 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3233 | |
| 3234 | if (curproxy == &defproxy) { |
| 3235 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3236 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3238 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3239 | } |
| 3240 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3241 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3242 | goto out; |
| 3243 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3244 | if (!*args[1]) { |
| 3245 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3246 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3248 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3252 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3253 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3254 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3255 | if (curproxy->uuid <= 0) { |
| 3256 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3257 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3259 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3262 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3263 | if (node) { |
| 3264 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3265 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3266 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3267 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3269 | goto out; |
| 3270 | } |
| 3271 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3272 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3273 | else if (!strcmp(args[0], "description")) { |
| 3274 | int i, len=0; |
| 3275 | char *d; |
| 3276 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3277 | if (curproxy == &defproxy) { |
| 3278 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3279 | file, linenum, args[0]); |
| 3280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3281 | goto out; |
| 3282 | } |
| 3283 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3284 | if (!*args[1]) { |
| 3285 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3286 | file, linenum, args[0]); |
| 3287 | return -1; |
| 3288 | } |
| 3289 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3290 | for (i = 1; *args[i]; i++) |
| 3291 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3292 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3293 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3294 | curproxy->desc = d; |
| 3295 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3296 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3297 | for (i = 2; *args[i]; i++) |
| 3298 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3299 | |
| 3300 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3301 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3302 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | curproxy->state = PR_STSTOPPED; |
| 3305 | } |
| 3306 | 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] | 3307 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3308 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3309 | curproxy->state = PR_STNEW; |
| 3310 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3311 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3312 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3313 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3314 | |
| 3315 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3316 | unsigned int low, high; |
| 3317 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3318 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3319 | set = 0; |
| 3320 | break; |
| 3321 | } |
| 3322 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3323 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3324 | } |
| 3325 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3326 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3327 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3328 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3329 | char *dash = strchr(args[cur_arg], '-'); |
| 3330 | |
| 3331 | low = high = str2uic(args[cur_arg]); |
| 3332 | if (dash) |
| 3333 | high = str2uic(dash + 1); |
| 3334 | |
| 3335 | if (high < low) { |
| 3336 | unsigned int swap = low; |
| 3337 | low = high; |
| 3338 | high = swap; |
| 3339 | } |
| 3340 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3341 | if (low < 1 || high > LONGBITS) { |
| 3342 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3343 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3345 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3346 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3347 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3348 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3349 | } |
| 3350 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3351 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3352 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3355 | } |
| 3356 | cur_arg++; |
| 3357 | } |
| 3358 | curproxy->bind_proc = set; |
| 3359 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3360 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3361 | if (curproxy == &defproxy) { |
| 3362 | 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] | 3363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3364 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3365 | } |
| 3366 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3367 | err = invalid_char(args[1]); |
| 3368 | if (err) { |
| 3369 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3370 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3371 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3372 | } |
| 3373 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3374 | 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] | 3375 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3376 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3378 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3379 | } |
| 3380 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3381 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3382 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3383 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3384 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3385 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3386 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3387 | if (*(args[1]) == 0) { |
| 3388 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3389 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3391 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3393 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3394 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3395 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3396 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3397 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3398 | curproxy->cookie_name = strdup(args[1]); |
| 3399 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3400 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3401 | cur_arg = 2; |
| 3402 | while (*(args[cur_arg])) { |
| 3403 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3404 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3405 | } |
| 3406 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3407 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3408 | } |
| 3409 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3410 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3411 | } |
| 3412 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3413 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3414 | } |
| 3415 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3416 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3417 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3418 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3419 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3420 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3421 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3422 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3423 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3424 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3425 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3426 | } |
| 3427 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3428 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3429 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3430 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3431 | if (!*args[cur_arg + 1]) { |
| 3432 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3433 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3435 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3436 | } |
| 3437 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3438 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3439 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3440 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3441 | " dots nor does not start with a dot." |
| 3442 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3443 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3444 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3448 | if (err) { |
| 3449 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3450 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3452 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3453 | } |
| 3454 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3455 | if (!curproxy->cookie_domain) { |
| 3456 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3457 | } else { |
| 3458 | /* one domain was already specified, add another one by |
| 3459 | * building the string which will be returned along with |
| 3460 | * the cookie. |
| 3461 | */ |
| 3462 | char *new_ptr; |
| 3463 | int new_len = strlen(curproxy->cookie_domain) + |
| 3464 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3465 | new_ptr = malloc(new_len); |
| 3466 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3467 | free(curproxy->cookie_domain); |
| 3468 | curproxy->cookie_domain = new_ptr; |
| 3469 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3470 | cur_arg++; |
| 3471 | } |
| 3472 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3473 | unsigned int maxidle; |
| 3474 | const char *res; |
| 3475 | |
| 3476 | if (!*args[cur_arg + 1]) { |
| 3477 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3478 | file, linenum, args[cur_arg]); |
| 3479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3480 | goto out; |
| 3481 | } |
| 3482 | |
| 3483 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3484 | if (res) { |
| 3485 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3486 | file, linenum, *res, args[cur_arg]); |
| 3487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3488 | goto out; |
| 3489 | } |
| 3490 | curproxy->cookie_maxidle = maxidle; |
| 3491 | cur_arg++; |
| 3492 | } |
| 3493 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3494 | unsigned int maxlife; |
| 3495 | const char *res; |
| 3496 | |
| 3497 | if (!*args[cur_arg + 1]) { |
| 3498 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3499 | file, linenum, args[cur_arg]); |
| 3500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3501 | goto out; |
| 3502 | } |
| 3503 | |
| 3504 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3505 | if (res) { |
| 3506 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3507 | file, linenum, *res, args[cur_arg]); |
| 3508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3509 | goto out; |
| 3510 | } |
| 3511 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3512 | cur_arg++; |
| 3513 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3514 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3515 | 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] | 3516 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3519 | } |
| 3520 | cur_arg++; |
| 3521 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3522 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3523 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3524 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3525 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3526 | } |
| 3527 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3528 | 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] | 3529 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3530 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3531 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3532 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3533 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3534 | 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] | 3535 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3536 | file, linenum); |
| 3537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3538 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3539 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3540 | else if (!strcmp(args[0], "email-alert")) { |
| 3541 | if (*(args[1]) == 0) { |
| 3542 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3543 | file, linenum, args[0]); |
| 3544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3545 | goto out; |
| 3546 | } |
| 3547 | |
| 3548 | if (!strcmp(args[1], "from")) { |
| 3549 | if (*(args[1]) == 0) { |
| 3550 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3551 | file, linenum, args[1]); |
| 3552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3553 | goto out; |
| 3554 | } |
| 3555 | free(curproxy->email_alert.from); |
| 3556 | curproxy->email_alert.from = strdup(args[2]); |
| 3557 | } |
| 3558 | else if (!strcmp(args[1], "mailers")) { |
| 3559 | if (*(args[1]) == 0) { |
| 3560 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3561 | file, linenum, args[1]); |
| 3562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3563 | goto out; |
| 3564 | } |
| 3565 | free(curproxy->email_alert.mailers.name); |
| 3566 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3567 | } |
| 3568 | else if (!strcmp(args[1], "myhostname")) { |
| 3569 | if (*(args[1]) == 0) { |
| 3570 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3571 | file, linenum, args[1]); |
| 3572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3573 | goto out; |
| 3574 | } |
| 3575 | free(curproxy->email_alert.myhostname); |
| 3576 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3577 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3578 | else if (!strcmp(args[1], "level")) { |
| 3579 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3580 | if (curproxy->email_alert.level < 0) { |
| 3581 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3582 | file, linenum, args[1], args[2]); |
| 3583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3584 | goto out; |
| 3585 | } |
| 3586 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3587 | else if (!strcmp(args[1], "to")) { |
| 3588 | if (*(args[1]) == 0) { |
| 3589 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3590 | file, linenum, args[1]); |
| 3591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3592 | goto out; |
| 3593 | } |
| 3594 | free(curproxy->email_alert.to); |
| 3595 | curproxy->email_alert.to = strdup(args[2]); |
| 3596 | } |
| 3597 | else { |
| 3598 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3599 | file, linenum, args[1]); |
| 3600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3601 | goto out; |
| 3602 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3603 | /* Indicate that the email_alert is at least partially configured */ |
| 3604 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3605 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3606 | else if (!strcmp(args[0], "external-check")) { |
| 3607 | if (*(args[1]) == 0) { |
| 3608 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3609 | file, linenum, args[0]); |
| 3610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3611 | goto out; |
| 3612 | } |
| 3613 | |
| 3614 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3615 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3616 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3617 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3618 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3619 | file, linenum, args[1]); |
| 3620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3621 | goto out; |
| 3622 | } |
| 3623 | free(curproxy->check_command); |
| 3624 | curproxy->check_command = strdup(args[2]); |
| 3625 | } |
| 3626 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3627 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3628 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3629 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3630 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3631 | file, linenum, args[1]); |
| 3632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3633 | goto out; |
| 3634 | } |
| 3635 | free(curproxy->check_path); |
| 3636 | curproxy->check_path = strdup(args[2]); |
| 3637 | } |
| 3638 | else { |
| 3639 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3640 | file, linenum, args[1]); |
| 3641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3642 | goto out; |
| 3643 | } |
| 3644 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3645 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3646 | if (*(args[1]) == 0) { |
| 3647 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3648 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3650 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3654 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3655 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3656 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3657 | const char *beg, *end; |
| 3658 | |
| 3659 | beg = args[1] + 11; |
| 3660 | end = strchr(beg, ')'); |
| 3661 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3662 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3663 | goto out; |
| 3664 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3665 | if (!end || end == beg) { |
| 3666 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3667 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3669 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | free(curproxy->rdp_cookie_name); |
| 3673 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3674 | curproxy->rdp_cookie_len = end-beg; |
| 3675 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3676 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3677 | free(curproxy->rdp_cookie_name); |
| 3678 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3679 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3680 | } |
| 3681 | else { /* syntax */ |
| 3682 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3683 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3685 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3686 | } |
| 3687 | } |
| 3688 | else { |
| 3689 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3690 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3692 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3693 | } |
| 3694 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3695 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3696 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3698 | goto out; |
| 3699 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3700 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3701 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3702 | err_code |= ERR_WARN; |
| 3703 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3704 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3705 | } |
| 3706 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3707 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3708 | } |
| 3709 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3710 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3711 | } |
| 3712 | else { |
| 3713 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3714 | file, linenum, args[0], args[1]); |
| 3715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3716 | goto out; |
| 3717 | } |
| 3718 | } |
| 3719 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3720 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3721 | err_code |= ERR_WARN; |
| 3722 | if (*(args[1]) == 0) { |
| 3723 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3724 | file, linenum, args[0]); |
| 3725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | else if (!strcmp(args[1], "use-backend-name")) |
| 3729 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3730 | else |
| 3731 | curproxy->server_state_file_name = strdup(args[1]); |
| 3732 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3733 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3734 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3735 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3736 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3737 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3738 | if (curproxy == &defproxy) { |
| 3739 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3741 | goto out; |
| 3742 | } |
| 3743 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3744 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3745 | goto out; |
| 3746 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3747 | if (*(args[4]) == 0) { |
| 3748 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3749 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3751 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3752 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3753 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3754 | curproxy->capture_name = strdup(args[2]); |
| 3755 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3756 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3757 | curproxy->to_log |= LW_COOKIE; |
| 3758 | } |
| 3759 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3760 | struct cap_hdr *hdr; |
| 3761 | |
| 3762 | if (curproxy == &defproxy) { |
| 3763 | 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] | 3764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3765 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3766 | } |
| 3767 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3768 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3769 | goto out; |
| 3770 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3771 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3772 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3773 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3775 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3776 | } |
| 3777 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3778 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3779 | hdr->next = curproxy->req_cap; |
| 3780 | hdr->name = strdup(args[3]); |
| 3781 | hdr->namelen = strlen(args[3]); |
| 3782 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3783 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3784 | hdr->index = curproxy->nb_req_cap++; |
| 3785 | curproxy->req_cap = hdr; |
| 3786 | curproxy->to_log |= LW_REQHDR; |
| 3787 | } |
| 3788 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3789 | struct cap_hdr *hdr; |
| 3790 | |
| 3791 | if (curproxy == &defproxy) { |
| 3792 | 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] | 3793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3794 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3795 | } |
| 3796 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3797 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3798 | goto out; |
| 3799 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3800 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3801 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3802 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3805 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3806 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3807 | hdr->next = curproxy->rsp_cap; |
| 3808 | hdr->name = strdup(args[3]); |
| 3809 | hdr->namelen = strlen(args[3]); |
| 3810 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3811 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3812 | hdr->index = curproxy->nb_rsp_cap++; |
| 3813 | curproxy->rsp_cap = hdr; |
| 3814 | curproxy->to_log |= LW_RSPHDR; |
| 3815 | } |
| 3816 | else { |
| 3817 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3818 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3821 | } |
| 3822 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3823 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3824 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3825 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3826 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3827 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3828 | goto out; |
| 3829 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3830 | if (*(args[1]) == 0) { |
| 3831 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3832 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3835 | } |
| 3836 | curproxy->conn_retries = atol(args[1]); |
| 3837 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3838 | else if (!strcmp(args[0], "http-request")) { /* request access control: allow/deny/auth */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3839 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3840 | |
| 3841 | if (curproxy == &defproxy) { |
| 3842 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3844 | goto out; |
| 3845 | } |
| 3846 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3847 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3848 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3849 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3850 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3851 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3852 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REQ_AUTH)) { |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3853 | 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] | 3854 | file, linenum, args[0]); |
| 3855 | err_code |= ERR_WARN; |
| 3856 | } |
| 3857 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3858 | 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] | 3859 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3860 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3861 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3862 | goto out; |
| 3863 | } |
| 3864 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3865 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3866 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3867 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3868 | file, linenum); |
| 3869 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3870 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3871 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3872 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3873 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3874 | |
| 3875 | if (curproxy == &defproxy) { |
| 3876 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3878 | goto out; |
| 3879 | } |
| 3880 | |
| 3881 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3882 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3883 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3884 | LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_DENY)) { |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3885 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3886 | file, linenum, args[0]); |
| 3887 | err_code |= ERR_WARN; |
| 3888 | } |
| 3889 | |
| 3890 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3891 | |
| 3892 | if (!rule) { |
| 3893 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3894 | goto out; |
| 3895 | } |
| 3896 | |
| 3897 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3898 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3899 | file, linenum); |
| 3900 | |
| 3901 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3902 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3903 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3904 | /* set the header name and length into the proxy structure */ |
| 3905 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3906 | err_code |= ERR_WARN; |
| 3907 | |
| 3908 | if (!*args[1]) { |
| 3909 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3910 | file, linenum, args[0]); |
| 3911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3912 | goto out; |
| 3913 | } |
| 3914 | |
| 3915 | /* set the desired header name */ |
| 3916 | free(curproxy->server_id_hdr_name); |
| 3917 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3918 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3919 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3920 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3921 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3922 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3923 | if (curproxy == &defproxy) { |
| 3924 | 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] | 3925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3926 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3927 | } |
| 3928 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3929 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3930 | * be processed before all http-request rules, we put them into their own list |
| 3931 | * and will insert them at the end. |
| 3932 | */ |
| 3933 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3934 | if (!rule) { |
| 3935 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3936 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3937 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3938 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3939 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3940 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3941 | file, linenum); |
| 3942 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3943 | |
| 3944 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3945 | 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]); |
| 3946 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3947 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3948 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3949 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3950 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3951 | if (curproxy == &defproxy) { |
| 3952 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3954 | goto out; |
| 3955 | } |
| 3956 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3957 | 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] | 3958 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3959 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3961 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3962 | } |
| 3963 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3964 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3965 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3966 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3967 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3968 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3969 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3970 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3971 | struct switching_rule *rule; |
| 3972 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3973 | if (curproxy == &defproxy) { |
| 3974 | 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] | 3975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3976 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3977 | } |
| 3978 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3979 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3980 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3981 | |
| 3982 | if (*(args[1]) == 0) { |
| 3983 | 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] | 3984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3985 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3986 | } |
| 3987 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3988 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3989 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3990 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3991 | file, linenum, errmsg); |
| 3992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3993 | goto out; |
| 3994 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3995 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3996 | 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] | 3997 | } |
| 3998 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3999 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4000 | rule->cond = cond; |
| 4001 | rule->be.name = strdup(args[1]); |
| 4002 | LIST_INIT(&rule->list); |
| 4003 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4004 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4005 | else if (strcmp(args[0], "use-server") == 0) { |
| 4006 | struct server_rule *rule; |
| 4007 | |
| 4008 | if (curproxy == &defproxy) { |
| 4009 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4011 | goto out; |
| 4012 | } |
| 4013 | |
| 4014 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4015 | err_code |= ERR_WARN; |
| 4016 | |
| 4017 | if (*(args[1]) == 0) { |
| 4018 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 4019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4020 | goto out; |
| 4021 | } |
| 4022 | |
| 4023 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4024 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4025 | file, linenum, args[0]); |
| 4026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4027 | goto out; |
| 4028 | } |
| 4029 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4030 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4031 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4032 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4034 | goto out; |
| 4035 | } |
| 4036 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4037 | 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] | 4038 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4039 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4040 | rule->cond = cond; |
| 4041 | rule->srv.name = strdup(args[1]); |
| 4042 | LIST_INIT(&rule->list); |
| 4043 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4044 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4045 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4046 | else if ((!strcmp(args[0], "force-persist")) || |
| 4047 | (!strcmp(args[0], "ignore-persist"))) { |
| 4048 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4049 | |
| 4050 | if (curproxy == &defproxy) { |
| 4051 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4053 | goto out; |
| 4054 | } |
| 4055 | |
| 4056 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4057 | err_code |= ERR_WARN; |
| 4058 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4059 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4060 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4061 | file, linenum, args[0]); |
| 4062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4063 | goto out; |
| 4064 | } |
| 4065 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4066 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 4067 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4068 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4070 | goto out; |
| 4071 | } |
| 4072 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4073 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4074 | * where force-persist is applied. |
| 4075 | */ |
| 4076 | 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] | 4077 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4078 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4079 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4080 | if (!strcmp(args[0], "force-persist")) { |
| 4081 | rule->type = PERSIST_TYPE_FORCE; |
| 4082 | } else { |
| 4083 | rule->type = PERSIST_TYPE_IGNORE; |
| 4084 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4085 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4086 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4087 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4088 | else if (!strcmp(args[0], "stick-table")) { |
| 4089 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4090 | struct proxy *other; |
| 4091 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4092 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4093 | if (other) { |
| 4094 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4095 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 4096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4097 | goto out; |
| 4098 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4099 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4100 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4101 | curproxy->table.type = (unsigned int)-1; |
| 4102 | while (*args[myidx]) { |
| 4103 | const char *err; |
| 4104 | |
| 4105 | if (strcmp(args[myidx], "size") == 0) { |
| 4106 | myidx++; |
| 4107 | if (!*(args[myidx])) { |
| 4108 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4109 | file, linenum, args[myidx-1]); |
| 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4111 | goto out; |
| 4112 | } |
| 4113 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 4114 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4115 | file, linenum, *err, args[myidx-1]); |
| 4116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4117 | goto out; |
| 4118 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4119 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4120 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4121 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4122 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4123 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4124 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4125 | file, linenum, args[myidx-1]); |
| 4126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4127 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4128 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4129 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4130 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4131 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4132 | myidx++; |
| 4133 | if (!*(args[myidx])) { |
| 4134 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4135 | file, linenum, args[myidx-1]); |
| 4136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4137 | goto out; |
| 4138 | } |
| 4139 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4140 | if (err) { |
| 4141 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4142 | file, linenum, *err, args[myidx-1]); |
| 4143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4144 | goto out; |
| 4145 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4146 | if (val > INT_MAX) { |
| 4147 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4148 | file, linenum, val); |
| 4149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4150 | goto out; |
| 4151 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4152 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4153 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4154 | } |
| 4155 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4156 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4157 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4158 | } |
| 4159 | else if (strcmp(args[myidx], "type") == 0) { |
| 4160 | myidx++; |
| 4161 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4162 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4163 | file, linenum, args[myidx]); |
| 4164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4165 | goto out; |
| 4166 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4167 | /* myidx already points to next arg */ |
| 4168 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4169 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4170 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4171 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4172 | |
| 4173 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4174 | nw = args[myidx]; |
| 4175 | while (*nw) { |
| 4176 | /* the "store" keyword supports a comma-separated list */ |
| 4177 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4178 | sa = NULL; /* store arg */ |
| 4179 | while (*nw && *nw != ',') { |
| 4180 | if (*nw == '(') { |
| 4181 | *nw = 0; |
| 4182 | sa = ++nw; |
| 4183 | while (*nw != ')') { |
| 4184 | if (!*nw) { |
| 4185 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4186 | file, linenum, args[0], cw); |
| 4187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4188 | goto out; |
| 4189 | } |
| 4190 | nw++; |
| 4191 | } |
| 4192 | *nw = '\0'; |
| 4193 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4194 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4195 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4196 | if (*nw) |
| 4197 | *nw++ = '\0'; |
| 4198 | type = stktable_get_data_type(cw); |
| 4199 | if (type < 0) { |
| 4200 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4201 | file, linenum, args[0], cw); |
| 4202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4203 | goto out; |
| 4204 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4205 | |
| 4206 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4207 | switch (err) { |
| 4208 | case PE_NONE: break; |
| 4209 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4210 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4211 | file, linenum, args[0], cw); |
| 4212 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4213 | break; |
| 4214 | |
| 4215 | case PE_ARG_MISSING: |
| 4216 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4217 | file, linenum, args[0], cw); |
| 4218 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4219 | goto out; |
| 4220 | |
| 4221 | case PE_ARG_NOT_USED: |
| 4222 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4223 | file, linenum, args[0], cw); |
| 4224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4225 | goto out; |
| 4226 | |
| 4227 | default: |
| 4228 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4229 | file, linenum, args[0], cw); |
| 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4232 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4233 | } |
| 4234 | myidx++; |
| 4235 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4236 | else { |
| 4237 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4238 | file, linenum, args[myidx]); |
| 4239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4240 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4241 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | if (!curproxy->table.size) { |
| 4245 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4246 | file, linenum); |
| 4247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4248 | goto out; |
| 4249 | } |
| 4250 | |
| 4251 | if (curproxy->table.type == (unsigned int)-1) { |
| 4252 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4253 | file, linenum); |
| 4254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4255 | goto out; |
| 4256 | } |
| 4257 | } |
| 4258 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4259 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4260 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4261 | int myidx = 0; |
| 4262 | const char *name = NULL; |
| 4263 | int flags; |
| 4264 | |
| 4265 | if (curproxy == &defproxy) { |
| 4266 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4268 | goto out; |
| 4269 | } |
| 4270 | |
| 4271 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4272 | err_code |= ERR_WARN; |
| 4273 | goto out; |
| 4274 | } |
| 4275 | |
| 4276 | myidx++; |
| 4277 | if ((strcmp(args[myidx], "store") == 0) || |
| 4278 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4279 | myidx++; |
| 4280 | flags = STK_IS_STORE; |
| 4281 | } |
| 4282 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4283 | myidx++; |
| 4284 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4285 | } |
| 4286 | else if (strcmp(args[myidx], "match") == 0) { |
| 4287 | myidx++; |
| 4288 | flags = STK_IS_MATCH; |
| 4289 | } |
| 4290 | else if (strcmp(args[myidx], "on") == 0) { |
| 4291 | myidx++; |
| 4292 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4293 | } |
| 4294 | else { |
| 4295 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4297 | goto out; |
| 4298 | } |
| 4299 | |
| 4300 | if (*(args[myidx]) == 0) { |
| 4301 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4303 | goto out; |
| 4304 | } |
| 4305 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4306 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4307 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4308 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4309 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
| 4312 | } |
| 4313 | |
| 4314 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4315 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4316 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4317 | 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] | 4318 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4319 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4320 | goto out; |
| 4321 | } |
| 4322 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4323 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4324 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4325 | 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] | 4326 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4327 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4328 | goto out; |
| 4329 | } |
| 4330 | } |
| 4331 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4332 | /* 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] | 4333 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4334 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4335 | if (strcmp(args[myidx], "table") == 0) { |
| 4336 | myidx++; |
| 4337 | name = args[myidx++]; |
| 4338 | } |
| 4339 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4340 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4341 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4342 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4343 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4344 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4345 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4346 | goto out; |
| 4347 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4348 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4349 | else if (*(args[myidx])) { |
| 4350 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4351 | file, linenum, args[0], args[myidx]); |
| 4352 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4353 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4354 | goto out; |
| 4355 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4356 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4357 | 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] | 4358 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4359 | 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] | 4360 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4361 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4362 | rule->cond = cond; |
| 4363 | rule->expr = expr; |
| 4364 | rule->flags = flags; |
| 4365 | rule->table.name = name ? strdup(name) : NULL; |
| 4366 | LIST_INIT(&rule->list); |
| 4367 | if (flags & STK_ON_RSP) |
| 4368 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4369 | else |
| 4370 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4371 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4372 | else if (!strcmp(args[0], "stats")) { |
| 4373 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4374 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4375 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4376 | if (!*args[1]) { |
| 4377 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4378 | } else if (!strcmp(args[1], "admin")) { |
| 4379 | struct stats_admin_rule *rule; |
| 4380 | |
| 4381 | if (curproxy == &defproxy) { |
| 4382 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4384 | goto out; |
| 4385 | } |
| 4386 | |
| 4387 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4388 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4389 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4390 | goto out; |
| 4391 | } |
| 4392 | |
| 4393 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4394 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4395 | file, linenum, args[0], args[1]); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4399 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4400 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4401 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4402 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4403 | goto out; |
| 4404 | } |
| 4405 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4406 | err_code |= warnif_cond_conflicts(cond, |
| 4407 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4408 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4409 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4410 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4411 | rule->cond = cond; |
| 4412 | LIST_INIT(&rule->list); |
| 4413 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4414 | } else if (!strcmp(args[1], "uri")) { |
| 4415 | if (*(args[2]) == 0) { |
| 4416 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4418 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4419 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4420 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4421 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4422 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4423 | } |
| 4424 | } else if (!strcmp(args[1], "realm")) { |
| 4425 | if (*(args[2]) == 0) { |
| 4426 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4428 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4429 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4430 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4431 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4432 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4433 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4434 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4435 | unsigned interval; |
| 4436 | |
| 4437 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4438 | if (err) { |
| 4439 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4440 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4442 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4443 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4444 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4445 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4446 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4447 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4448 | } else if (!strcmp(args[1], "http-request")) { /* request access control: allow/deny/auth */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4449 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4450 | |
| 4451 | if (curproxy == &defproxy) { |
| 4452 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4454 | goto out; |
| 4455 | } |
| 4456 | |
| 4457 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4458 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4459 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4460 | goto out; |
| 4461 | } |
| 4462 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4463 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4464 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4465 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4466 | file, linenum, args[0]); |
| 4467 | err_code |= ERR_WARN; |
| 4468 | } |
| 4469 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4470 | 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] | 4471 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4472 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4473 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4474 | goto out; |
| 4475 | } |
| 4476 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4477 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4478 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4479 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4480 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4481 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4482 | } else if (!strcmp(args[1], "auth")) { |
| 4483 | if (*(args[2]) == 0) { |
| 4484 | 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] | 4485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4486 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4487 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4488 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4489 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4490 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4491 | } |
| 4492 | } else if (!strcmp(args[1], "scope")) { |
| 4493 | if (*(args[2]) == 0) { |
| 4494 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4496 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4497 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4498 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4499 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4501 | } |
| 4502 | } else if (!strcmp(args[1], "enable")) { |
| 4503 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4504 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4505 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4506 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4507 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4508 | } else if (!strcmp(args[1], "hide-version")) { |
| 4509 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4510 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4511 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4512 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4513 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4514 | } else if (!strcmp(args[1], "show-legends")) { |
| 4515 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4516 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4517 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4518 | goto out; |
| 4519 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4520 | } else if (!strcmp(args[1], "show-node")) { |
| 4521 | |
| 4522 | if (*args[2]) { |
| 4523 | int i; |
| 4524 | char c; |
| 4525 | |
| 4526 | for (i=0; args[2][i]; i++) { |
| 4527 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4528 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4529 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4530 | break; |
| 4531 | } |
| 4532 | |
| 4533 | if (!i || args[2][i]) { |
| 4534 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4535 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4536 | file, linenum, args[0], args[1]); |
| 4537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4538 | goto out; |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4543 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4544 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4545 | goto out; |
| 4546 | } |
| 4547 | } else if (!strcmp(args[1], "show-desc")) { |
| 4548 | char *desc = NULL; |
| 4549 | |
| 4550 | if (*args[2]) { |
| 4551 | int i, len=0; |
| 4552 | char *d; |
| 4553 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4554 | for (i = 2; *args[i]; i++) |
| 4555 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4556 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4557 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4558 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4559 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4560 | for (i = 3; *args[i]; i++) |
| 4561 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | if (!*args[2] && !global.desc) |
| 4565 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4566 | file, linenum, args[1]); |
| 4567 | else { |
| 4568 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4569 | free(desc); |
| 4570 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4571 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4572 | goto out; |
| 4573 | } |
| 4574 | free(desc); |
| 4575 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4576 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4577 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4578 | 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] | 4579 | 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] | 4580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4581 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4585 | int optnum; |
| 4586 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4587 | if (*(args[1]) == '\0') { |
| 4588 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4589 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4591 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4592 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4593 | |
| 4594 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4595 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4596 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4597 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4598 | file, linenum, cfg_opts[optnum].name); |
| 4599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4600 | goto out; |
| 4601 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4602 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4603 | goto out; |
| 4604 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4605 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4606 | err_code |= ERR_WARN; |
| 4607 | goto out; |
| 4608 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4609 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4610 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4611 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4612 | |
| 4613 | switch (kwm) { |
| 4614 | case KWM_STD: |
| 4615 | curproxy->options |= cfg_opts[optnum].val; |
| 4616 | break; |
| 4617 | case KWM_NO: |
| 4618 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4619 | break; |
| 4620 | case KWM_DEF: /* already cleared */ |
| 4621 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4622 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4623 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4624 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4628 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4629 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4630 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4631 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4632 | file, linenum, cfg_opts2[optnum].name); |
| 4633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4634 | goto out; |
| 4635 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4636 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4637 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4638 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4639 | err_code |= ERR_WARN; |
| 4640 | goto out; |
| 4641 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4642 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4643 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4644 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4645 | |
| 4646 | switch (kwm) { |
| 4647 | case KWM_STD: |
| 4648 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4649 | break; |
| 4650 | case KWM_NO: |
| 4651 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4652 | break; |
| 4653 | case KWM_DEF: /* already cleared */ |
| 4654 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4655 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4656 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4657 | } |
| 4658 | } |
| 4659 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4660 | /* HTTP options override each other. They can be cancelled using |
| 4661 | * "no option xxx" which only switches to default mode if the mode |
| 4662 | * was this one (useful for cancelling options set in defaults |
| 4663 | * sections). |
| 4664 | */ |
| 4665 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4666 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4667 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4668 | if (kwm == KWM_STD) { |
| 4669 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4670 | curproxy->options |= PR_O_HTTP_PCL; |
| 4671 | goto out; |
| 4672 | } |
| 4673 | else if (kwm == KWM_NO) { |
| 4674 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4675 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4676 | goto out; |
| 4677 | } |
| 4678 | } |
| 4679 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4680 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4681 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4682 | if (kwm == KWM_STD) { |
| 4683 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4684 | curproxy->options |= PR_O_HTTP_FCL; |
| 4685 | goto out; |
| 4686 | } |
| 4687 | else if (kwm == KWM_NO) { |
| 4688 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4689 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4690 | goto out; |
| 4691 | } |
| 4692 | } |
| 4693 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4694 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4695 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4696 | if (kwm == KWM_STD) { |
| 4697 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4698 | curproxy->options |= PR_O_HTTP_SCL; |
| 4699 | goto out; |
| 4700 | } |
| 4701 | else if (kwm == KWM_NO) { |
| 4702 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4703 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4704 | goto out; |
| 4705 | } |
| 4706 | } |
| 4707 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4708 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4709 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4710 | if (kwm == KWM_STD) { |
| 4711 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4712 | curproxy->options |= PR_O_HTTP_KAL; |
| 4713 | goto out; |
| 4714 | } |
| 4715 | else if (kwm == KWM_NO) { |
| 4716 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4717 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4718 | goto out; |
| 4719 | } |
| 4720 | } |
| 4721 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4722 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4723 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4724 | if (kwm == KWM_STD) { |
| 4725 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4726 | curproxy->options |= PR_O_HTTP_TUN; |
| 4727 | goto out; |
| 4728 | } |
| 4729 | else if (kwm == KWM_NO) { |
| 4730 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4731 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4732 | goto out; |
| 4733 | } |
| 4734 | } |
| 4735 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4736 | /* Redispatch can take an integer argument that control when the |
| 4737 | * resispatch occurs. All values are relative to the retries option. |
| 4738 | * This can be cancelled using "no option xxx". |
| 4739 | */ |
| 4740 | if (strcmp(args[1], "redispatch") == 0) { |
| 4741 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4742 | err_code |= ERR_WARN; |
| 4743 | goto out; |
| 4744 | } |
| 4745 | |
| 4746 | curproxy->no_options &= ~PR_O_REDISP; |
| 4747 | curproxy->options &= ~PR_O_REDISP; |
| 4748 | |
| 4749 | switch (kwm) { |
| 4750 | case KWM_STD: |
| 4751 | curproxy->options |= PR_O_REDISP; |
| 4752 | curproxy->redispatch_after = -1; |
| 4753 | if(*args[2]) { |
| 4754 | curproxy->redispatch_after = atol(args[2]); |
| 4755 | } |
| 4756 | break; |
| 4757 | case KWM_NO: |
| 4758 | curproxy->no_options |= PR_O_REDISP; |
| 4759 | curproxy->redispatch_after = 0; |
| 4760 | break; |
| 4761 | case KWM_DEF: /* already cleared */ |
| 4762 | break; |
| 4763 | } |
| 4764 | goto out; |
| 4765 | } |
| 4766 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4767 | if (kwm != KWM_STD) { |
| 4768 | 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] | 4769 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4771 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4772 | } |
| 4773 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4774 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4775 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4776 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4777 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4778 | if (*(args[2]) != '\0') { |
| 4779 | if (!strcmp(args[2], "clf")) { |
| 4780 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4781 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4782 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4783 | 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] | 4784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4785 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4786 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4787 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4788 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4789 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4790 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4791 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4792 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4793 | free(curproxy->conf.logformat_string); |
| 4794 | curproxy->conf.logformat_string = logformat; |
| 4795 | |
| 4796 | free(curproxy->conf.lfs_file); |
| 4797 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4798 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4799 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4800 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4801 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4802 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4803 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4804 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4805 | free(curproxy->conf.logformat_string); |
| 4806 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4807 | |
| 4808 | free(curproxy->conf.lfs_file); |
| 4809 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4810 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4811 | |
| 4812 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4813 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4814 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4815 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4816 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4817 | 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] | 4818 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4819 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4820 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4821 | goto out; |
| 4822 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4823 | if (curproxy->cap & PR_CAP_FE) |
| 4824 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4825 | if (curproxy->cap & PR_CAP_BE) |
| 4826 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4827 | } |
| 4828 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4829 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4830 | err_code |= ERR_WARN; |
| 4831 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4832 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4833 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4834 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4835 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4836 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4837 | if (!*args[2]) { /* no argument */ |
| 4838 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4839 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4840 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4841 | int reqlen = strlen(args[2]) + strlen("OPTIONS HTTP/1.0\r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4842 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4843 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4844 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4845 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4846 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4847 | if (*args[4]) |
| 4848 | reqlen += strlen(args[4]); |
| 4849 | else |
| 4850 | reqlen += strlen("HTTP/1.0"); |
| 4851 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4852 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4853 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4854 | "%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] | 4855 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4856 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4857 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4858 | } |
| 4859 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4860 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4861 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4862 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4863 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4864 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4865 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4866 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4867 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4868 | |
| 4869 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4870 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4871 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4872 | else if (!strcmp(args[1], "smtpchk")) { |
| 4873 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4874 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4875 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4876 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4877 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4878 | |
| 4879 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4880 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4881 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4882 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4883 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4884 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4885 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4886 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4887 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4888 | } else { |
| 4889 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4890 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4891 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4892 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4893 | } |
| 4894 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4895 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4896 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4897 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4898 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4899 | /* use PostgreSQL request to check servers' health */ |
| 4900 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4901 | err_code |= ERR_WARN; |
| 4902 | |
| 4903 | free(curproxy->check_req); |
| 4904 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4905 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4906 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4907 | |
| 4908 | if (*(args[2])) { |
| 4909 | int cur_arg = 2; |
| 4910 | |
| 4911 | while (*(args[cur_arg])) { |
| 4912 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4913 | char * packet; |
| 4914 | uint32_t packet_len; |
| 4915 | uint32_t pv; |
| 4916 | |
| 4917 | /* suboption header - needs additional argument for it */ |
| 4918 | if (*(args[cur_arg+1]) == 0) { |
| 4919 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4920 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4922 | goto out; |
| 4923 | } |
| 4924 | |
| 4925 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4926 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4927 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4928 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4929 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4930 | |
| 4931 | memcpy(packet + 4, &pv, 4); |
| 4932 | |
| 4933 | /* copy "user" */ |
| 4934 | memcpy(packet + 8, "user", 4); |
| 4935 | |
| 4936 | /* copy username */ |
| 4937 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4938 | |
| 4939 | free(curproxy->check_req); |
| 4940 | curproxy->check_req = packet; |
| 4941 | curproxy->check_len = packet_len; |
| 4942 | |
| 4943 | packet_len = htonl(packet_len); |
| 4944 | memcpy(packet, &packet_len, 4); |
| 4945 | cur_arg += 2; |
| 4946 | } else { |
| 4947 | /* unknown suboption - catchall */ |
| 4948 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4949 | file, linenum, args[0], args[1]); |
| 4950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4951 | goto out; |
| 4952 | } |
| 4953 | } /* end while loop */ |
| 4954 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4955 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4956 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4957 | } |
| 4958 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4959 | else if (!strcmp(args[1], "redis-check")) { |
| 4960 | /* use REDIS PING request to check servers' health */ |
| 4961 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4962 | err_code |= ERR_WARN; |
| 4963 | |
| 4964 | free(curproxy->check_req); |
| 4965 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4966 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4967 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4968 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4969 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4970 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4971 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4972 | |
| 4973 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4974 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4975 | } |
| 4976 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4977 | else if (!strcmp(args[1], "mysql-check")) { |
| 4978 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4979 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4980 | err_code |= ERR_WARN; |
| 4981 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4982 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4983 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4984 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4985 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4986 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4987 | /* 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] | 4988 | * const char mysql40_client_auth_pkt[] = { |
| 4989 | * "\x0e\x00\x00" // packet length |
| 4990 | * "\x01" // packet number |
| 4991 | * "\x00\x00" // client capabilities |
| 4992 | * "\x00\x00\x01" // max packet |
| 4993 | * "haproxy\x00" // username (null terminated string) |
| 4994 | * "\x00" // filler (always 0x00) |
| 4995 | * "\x01\x00\x00" // packet length |
| 4996 | * "\x00" // packet number |
| 4997 | * "\x01" // COM_QUIT command |
| 4998 | * }; |
| 4999 | */ |
| 5000 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5001 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5002 | * const char mysql41_client_auth_pkt[] = { |
| 5003 | * "\x0e\x00\x00\" // packet length |
| 5004 | * "\x01" // packet number |
| 5005 | * "\x00\x00\x00\x00" // client capabilities |
| 5006 | * "\x00\x00\x00\x01" // max packet |
| 5007 | * "\x21" // character set (UTF-8) |
| 5008 | * char[23] // All zeroes |
| 5009 | * "haproxy\x00" // username (null terminated string) |
| 5010 | * "\x00" // filler (always 0x00) |
| 5011 | * "\x01\x00\x00" // packet length |
| 5012 | * "\x00" // packet number |
| 5013 | * "\x01" // COM_QUIT command |
| 5014 | * }; |
| 5015 | */ |
| 5016 | |
| 5017 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5018 | if (*(args[2])) { |
| 5019 | int cur_arg = 2; |
| 5020 | |
| 5021 | while (*(args[cur_arg])) { |
| 5022 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5023 | char *mysqluser; |
| 5024 | int packetlen, reqlen, userlen; |
| 5025 | |
| 5026 | /* suboption header - needs additional argument for it */ |
| 5027 | if (*(args[cur_arg+1]) == 0) { |
| 5028 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5029 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5031 | goto out; |
| 5032 | } |
| 5033 | mysqluser = args[cur_arg + 1]; |
| 5034 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5035 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5036 | if (*(args[cur_arg+2])) { |
| 5037 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5038 | packetlen = userlen + 7 + 27; |
| 5039 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5040 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5041 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5042 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5043 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5044 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5045 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5046 | ((unsigned char) packetlen & 0xff), |
| 5047 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5048 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5049 | |
| 5050 | curproxy->check_req[3] = 1; |
| 5051 | curproxy->check_req[5] = 130; |
| 5052 | curproxy->check_req[11] = 1; |
| 5053 | curproxy->check_req[12] = 33; |
| 5054 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5055 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5056 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5057 | cur_arg += 3; |
| 5058 | } else { |
| 5059 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 5060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5061 | goto out; |
| 5062 | } |
| 5063 | } else { |
| 5064 | packetlen = userlen + 7; |
| 5065 | reqlen = packetlen + 9; |
| 5066 | |
| 5067 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5068 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5069 | curproxy->check_len = reqlen; |
| 5070 | |
| 5071 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5072 | ((unsigned char) packetlen & 0xff), |
| 5073 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5074 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5075 | |
| 5076 | curproxy->check_req[3] = 1; |
| 5077 | curproxy->check_req[5] = 128; |
| 5078 | curproxy->check_req[8] = 1; |
| 5079 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5080 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5081 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5082 | cur_arg += 2; |
| 5083 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5084 | } else { |
| 5085 | /* unknown suboption - catchall */ |
| 5086 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5087 | file, linenum, args[0], args[1]); |
| 5088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5089 | goto out; |
| 5090 | } |
| 5091 | } /* end while loop */ |
| 5092 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5093 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5094 | else if (!strcmp(args[1], "ldap-check")) { |
| 5095 | /* use LDAP request to check servers' health */ |
| 5096 | free(curproxy->check_req); |
| 5097 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5098 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5099 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5100 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5101 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5102 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5103 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5104 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5105 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5106 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5107 | else if (!strcmp(args[1], "tcp-check")) { |
| 5108 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5109 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5110 | err_code |= ERR_WARN; |
| 5111 | |
| 5112 | free(curproxy->check_req); |
| 5113 | curproxy->check_req = NULL; |
| 5114 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5115 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5116 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5117 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5118 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5119 | else if (!strcmp(args[1], "external-check")) { |
| 5120 | /* excute an external command to check servers' health */ |
| 5121 | free(curproxy->check_req); |
| 5122 | curproxy->check_req = NULL; |
| 5123 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5124 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5125 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5126 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5127 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5128 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5129 | int cur_arg; |
| 5130 | |
| 5131 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5132 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5133 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5134 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5135 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5136 | |
| 5137 | free(curproxy->fwdfor_hdr_name); |
| 5138 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5139 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5140 | |
| 5141 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5142 | cur_arg = 2; |
| 5143 | while (*(args[cur_arg])) { |
| 5144 | if (!strcmp(args[cur_arg], "except")) { |
| 5145 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5146 | 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] | 5147 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5148 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5150 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5151 | } |
| 5152 | /* flush useless bits */ |
| 5153 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5154 | cur_arg += 2; |
| 5155 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5156 | /* suboption header - needs additional argument for it */ |
| 5157 | if (*(args[cur_arg+1]) == 0) { |
| 5158 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5159 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5161 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5162 | } |
| 5163 | free(curproxy->fwdfor_hdr_name); |
| 5164 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5165 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5166 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5167 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5168 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5169 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5170 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5171 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5172 | 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] | 5173 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5175 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5176 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5177 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5178 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5179 | else if (!strcmp(args[1], "originalto")) { |
| 5180 | int cur_arg; |
| 5181 | |
| 5182 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5183 | * set default options (ie: bitfield, header name, etc) |
| 5184 | */ |
| 5185 | |
| 5186 | curproxy->options |= PR_O_ORGTO; |
| 5187 | |
| 5188 | free(curproxy->orgto_hdr_name); |
| 5189 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5190 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5191 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5192 | /* 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] | 5193 | cur_arg = 2; |
| 5194 | while (*(args[cur_arg])) { |
| 5195 | if (!strcmp(args[cur_arg], "except")) { |
| 5196 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5197 | 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] | 5198 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5199 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5201 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5202 | } |
| 5203 | /* flush useless bits */ |
| 5204 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5205 | cur_arg += 2; |
| 5206 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5207 | /* suboption header - needs additional argument for it */ |
| 5208 | if (*(args[cur_arg+1]) == 0) { |
| 5209 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5210 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5212 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5213 | } |
| 5214 | free(curproxy->orgto_hdr_name); |
| 5215 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5216 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5217 | cur_arg += 2; |
| 5218 | } else { |
| 5219 | /* unknown suboption - catchall */ |
| 5220 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5221 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5223 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5224 | } |
| 5225 | } /* end while loop */ |
| 5226 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5227 | else { |
| 5228 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5231 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5232 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5233 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5234 | else if (!strcmp(args[0], "default_backend")) { |
| 5235 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5236 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5237 | |
| 5238 | if (*(args[1]) == 0) { |
| 5239 | 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] | 5240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5241 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5242 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5243 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5244 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5245 | |
| 5246 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5247 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5248 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5249 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5250 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5251 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5252 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5253 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5254 | 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] | 5255 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5256 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5257 | /* enable reconnections to dispatch */ |
| 5258 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5259 | |
| 5260 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5261 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5262 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5263 | else if (!strcmp(args[0], "http-reuse")) { |
| 5264 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5265 | err_code |= ERR_WARN; |
| 5266 | |
| 5267 | if (strcmp(args[1], "never") == 0) { |
| 5268 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5269 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5270 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5271 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5272 | goto out; |
| 5273 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5274 | else if (strcmp(args[1], "safe") == 0) { |
| 5275 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5276 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5277 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5278 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5279 | goto out; |
| 5280 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5281 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5282 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5283 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5284 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5285 | goto out; |
| 5286 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5287 | else if (strcmp(args[1], "always") == 0) { |
| 5288 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5289 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5290 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5291 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5292 | goto out; |
| 5293 | } |
| 5294 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5295 | Alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]); |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5297 | goto out; |
| 5298 | } |
| 5299 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5300 | else if (!strcmp(args[0], "http-check")) { |
| 5301 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5302 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5303 | |
| 5304 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5305 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5306 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5307 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5308 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5309 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5310 | else if (strcmp(args[1], "send-state") == 0) { |
| 5311 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5312 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5313 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5314 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5315 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5316 | else if (strcmp(args[1], "expect") == 0) { |
| 5317 | const char *ptr_arg; |
| 5318 | int cur_arg; |
| 5319 | |
| 5320 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5321 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5323 | goto out; |
| 5324 | } |
| 5325 | |
| 5326 | cur_arg = 2; |
| 5327 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5328 | while (*(ptr_arg = args[cur_arg])) { |
| 5329 | while (*ptr_arg == '!') { |
| 5330 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5331 | ptr_arg++; |
| 5332 | } |
| 5333 | if (*ptr_arg) |
| 5334 | break; |
| 5335 | cur_arg++; |
| 5336 | } |
| 5337 | /* now ptr_arg points to the beginning of a word past any possible |
| 5338 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5339 | */ |
| 5340 | if (strcmp(ptr_arg, "status") == 0) { |
| 5341 | if (!*(args[cur_arg + 1])) { |
| 5342 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5343 | file, linenum, args[0], args[1], ptr_arg); |
| 5344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5345 | goto out; |
| 5346 | } |
| 5347 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5348 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5349 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5350 | } |
| 5351 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5352 | if (!*(args[cur_arg + 1])) { |
| 5353 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5354 | file, linenum, args[0], args[1], ptr_arg); |
| 5355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5356 | goto out; |
| 5357 | } |
| 5358 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5359 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5360 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5361 | } |
| 5362 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5363 | if (!*(args[cur_arg + 1])) { |
| 5364 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5365 | file, linenum, args[0], args[1], ptr_arg); |
| 5366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5367 | goto out; |
| 5368 | } |
| 5369 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5370 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5371 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5372 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5373 | free(curproxy->expect_regex); |
| 5374 | curproxy->expect_regex = NULL; |
| 5375 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5376 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5377 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5378 | error = NULL; |
| 5379 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5380 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5381 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5382 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5384 | goto out; |
| 5385 | } |
| 5386 | } |
| 5387 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5388 | if (!*(args[cur_arg + 1])) { |
| 5389 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5390 | file, linenum, args[0], args[1], ptr_arg); |
| 5391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5392 | goto out; |
| 5393 | } |
| 5394 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5395 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5396 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5397 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5398 | free(curproxy->expect_regex); |
| 5399 | curproxy->expect_regex = NULL; |
| 5400 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5401 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5402 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5403 | error = NULL; |
| 5404 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5405 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5406 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5407 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5409 | goto out; |
| 5410 | } |
| 5411 | } |
| 5412 | else { |
| 5413 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5414 | file, linenum, args[0], args[1], ptr_arg); |
| 5415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5416 | goto out; |
| 5417 | } |
| 5418 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5419 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5420 | 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] | 5421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5422 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5423 | } |
| 5424 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5425 | else if (!strcmp(args[0], "tcp-check")) { |
| 5426 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5427 | err_code |= ERR_WARN; |
| 5428 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5429 | if (strcmp(args[1], "comment") == 0) { |
| 5430 | int cur_arg; |
| 5431 | struct tcpcheck_rule *tcpcheck; |
| 5432 | |
| 5433 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5434 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5435 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5436 | |
| 5437 | if (!*args[cur_arg + 1]) { |
| 5438 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5439 | file, linenum, args[cur_arg]); |
| 5440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5441 | goto out; |
| 5442 | } |
| 5443 | |
| 5444 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5445 | |
| 5446 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5447 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5448 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5449 | } |
| 5450 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5451 | const char *ptr_arg; |
| 5452 | int cur_arg; |
| 5453 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5454 | |
| 5455 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5456 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5457 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5458 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5459 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5460 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5461 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5462 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5463 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5464 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5465 | file, linenum); |
| 5466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5467 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5471 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5472 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5473 | |
| 5474 | /* parsing each parameters to fill up the rule */ |
| 5475 | while (*(ptr_arg = args[cur_arg])) { |
| 5476 | /* tcp port */ |
| 5477 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5478 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5479 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5480 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5481 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5483 | goto out; |
| 5484 | } |
| 5485 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5486 | cur_arg += 2; |
| 5487 | } |
| 5488 | /* send proxy protocol */ |
| 5489 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5490 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5491 | cur_arg++; |
| 5492 | } |
| 5493 | #ifdef USE_OPENSSL |
| 5494 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5495 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5496 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5497 | cur_arg++; |
| 5498 | } |
| 5499 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5500 | /* comment for this tcpcheck line */ |
| 5501 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5502 | if (!*args[cur_arg + 1]) { |
| 5503 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5504 | file, linenum, args[cur_arg]); |
| 5505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5506 | goto out; |
| 5507 | } |
| 5508 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5509 | cur_arg += 2; |
| 5510 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5511 | else { |
| 5512 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5513 | 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] | 5514 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5515 | 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] | 5516 | #endif /* USE_OPENSSL */ |
| 5517 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5519 | goto out; |
| 5520 | } |
| 5521 | |
| 5522 | } |
| 5523 | |
| 5524 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5525 | } |
| 5526 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5527 | if (! *(args[2]) ) { |
| 5528 | /* SEND string expected */ |
| 5529 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5530 | file, linenum, args[0], args[1], args[2]); |
| 5531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5532 | goto out; |
| 5533 | } else { |
| 5534 | struct tcpcheck_rule *tcpcheck; |
| 5535 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5536 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5537 | |
| 5538 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5539 | tcpcheck->string_len = strlen(args[2]); |
| 5540 | tcpcheck->string = strdup(args[2]); |
| 5541 | tcpcheck->expect_regex = NULL; |
| 5542 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5543 | /* comment for this tcpcheck line */ |
| 5544 | if (strcmp(args[3], "comment") == 0) { |
| 5545 | if (!*args[4]) { |
| 5546 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5547 | file, linenum, args[3]); |
| 5548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5549 | goto out; |
| 5550 | } |
| 5551 | tcpcheck->comment = strdup(args[4]); |
| 5552 | } |
| 5553 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5554 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5555 | } |
| 5556 | } |
| 5557 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5558 | if (! *(args[2]) ) { |
| 5559 | /* SEND binary string expected */ |
| 5560 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5561 | file, linenum, args[0], args[1], args[2]); |
| 5562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5563 | goto out; |
| 5564 | } else { |
| 5565 | struct tcpcheck_rule *tcpcheck; |
| 5566 | char *err = NULL; |
| 5567 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5568 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5569 | |
| 5570 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5571 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5572 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5573 | file, linenum, args[0], args[1], args[2], err); |
| 5574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5575 | goto out; |
| 5576 | } |
| 5577 | tcpcheck->expect_regex = NULL; |
| 5578 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5579 | /* comment for this tcpcheck line */ |
| 5580 | if (strcmp(args[3], "comment") == 0) { |
| 5581 | if (!*args[4]) { |
| 5582 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5583 | file, linenum, args[3]); |
| 5584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5585 | goto out; |
| 5586 | } |
| 5587 | tcpcheck->comment = strdup(args[4]); |
| 5588 | } |
| 5589 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5590 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5591 | } |
| 5592 | } |
| 5593 | else if (strcmp(args[1], "expect") == 0) { |
| 5594 | const char *ptr_arg; |
| 5595 | int cur_arg; |
| 5596 | int inverse = 0; |
| 5597 | |
| 5598 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5599 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5601 | goto out; |
| 5602 | } |
| 5603 | |
| 5604 | cur_arg = 2; |
| 5605 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5606 | while (*(ptr_arg = args[cur_arg])) { |
| 5607 | while (*ptr_arg == '!') { |
| 5608 | inverse = !inverse; |
| 5609 | ptr_arg++; |
| 5610 | } |
| 5611 | if (*ptr_arg) |
| 5612 | break; |
| 5613 | cur_arg++; |
| 5614 | } |
| 5615 | /* now ptr_arg points to the beginning of a word past any possible |
| 5616 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5617 | */ |
| 5618 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5619 | struct tcpcheck_rule *tcpcheck; |
| 5620 | char *err = NULL; |
| 5621 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5622 | if (!*(args[cur_arg + 1])) { |
| 5623 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5624 | file, linenum, args[0], args[1], ptr_arg); |
| 5625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5626 | goto out; |
| 5627 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5628 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5629 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5630 | |
| 5631 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5632 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5633 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5634 | file, linenum, args[0], args[1], args[2], err); |
| 5635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5636 | goto out; |
| 5637 | } |
| 5638 | tcpcheck->expect_regex = NULL; |
| 5639 | tcpcheck->inverse = inverse; |
| 5640 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5641 | /* tcpcheck comment */ |
| 5642 | cur_arg += 2; |
| 5643 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5644 | if (!*args[cur_arg + 1]) { |
| 5645 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5646 | file, linenum, args[cur_arg + 1]); |
| 5647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5648 | goto out; |
| 5649 | } |
| 5650 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5651 | } |
| 5652 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5653 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5654 | } |
| 5655 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5656 | struct tcpcheck_rule *tcpcheck; |
| 5657 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5658 | if (!*(args[cur_arg + 1])) { |
| 5659 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5660 | file, linenum, args[0], args[1], ptr_arg); |
| 5661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5662 | goto out; |
| 5663 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5664 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5665 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5666 | |
| 5667 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5668 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5669 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5670 | tcpcheck->expect_regex = NULL; |
| 5671 | tcpcheck->inverse = inverse; |
| 5672 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5673 | /* tcpcheck comment */ |
| 5674 | cur_arg += 2; |
| 5675 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5676 | if (!*args[cur_arg + 1]) { |
| 5677 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5678 | file, linenum, args[cur_arg + 1]); |
| 5679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5680 | goto out; |
| 5681 | } |
| 5682 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5683 | } |
| 5684 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5685 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5686 | } |
| 5687 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5688 | struct tcpcheck_rule *tcpcheck; |
| 5689 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5690 | if (!*(args[cur_arg + 1])) { |
| 5691 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5692 | file, linenum, args[0], args[1], ptr_arg); |
| 5693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5694 | goto out; |
| 5695 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5696 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5697 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5698 | |
| 5699 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5700 | tcpcheck->string_len = 0; |
| 5701 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5702 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5703 | error = NULL; |
| 5704 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5705 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5706 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5707 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5709 | goto out; |
| 5710 | } |
| 5711 | tcpcheck->inverse = inverse; |
| 5712 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5713 | /* tcpcheck comment */ |
| 5714 | cur_arg += 2; |
| 5715 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5716 | if (!*args[cur_arg + 1]) { |
| 5717 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5718 | file, linenum, args[cur_arg + 1]); |
| 5719 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5720 | goto out; |
| 5721 | } |
| 5722 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5723 | } |
| 5724 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5725 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5726 | } |
| 5727 | else { |
| 5728 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5729 | file, linenum, args[0], args[1], ptr_arg); |
| 5730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5731 | goto out; |
| 5732 | } |
| 5733 | } |
| 5734 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5735 | 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] | 5736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5737 | goto out; |
| 5738 | } |
| 5739 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5740 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5741 | if (curproxy == &defproxy) { |
| 5742 | 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] | 5743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5744 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5745 | } |
| 5746 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5747 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5748 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5749 | |
| 5750 | if (strcmp(args[1], "fail") == 0) { |
| 5751 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5752 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5753 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5754 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5756 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5757 | } |
| 5758 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5759 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5760 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5761 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5763 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5764 | } |
| 5765 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5766 | } |
| 5767 | else { |
| 5768 | 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] | 5769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5770 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5771 | } |
| 5772 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5773 | #ifdef TPROXY |
| 5774 | else if (!strcmp(args[0], "transparent")) { |
| 5775 | /* enable transparent proxy connections */ |
| 5776 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5777 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5778 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5779 | } |
| 5780 | #endif |
| 5781 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5782 | 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] | 5783 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5784 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5785 | if (*(args[1]) == 0) { |
| 5786 | 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] | 5787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5788 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5789 | } |
| 5790 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5791 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5792 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5793 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5794 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5795 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5796 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5797 | |
| 5798 | if (*(args[1]) == 0) { |
| 5799 | 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] | 5800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5801 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5802 | } |
| 5803 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5804 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5805 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5806 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5807 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5808 | 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] | 5809 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5810 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5811 | if (*(args[1]) == 0) { |
| 5812 | 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] | 5813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5814 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5815 | } |
| 5816 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5817 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5818 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5819 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5820 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5821 | if (*(args[1]) == 0) { |
| 5822 | 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] | 5823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5824 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5825 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5826 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5827 | if (err) { |
| 5828 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5829 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5831 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5832 | } |
| 5833 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5834 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5835 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5836 | } |
| 5837 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5838 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5839 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5840 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5841 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5842 | if (curproxy == &defproxy) { |
| 5843 | 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] | 5844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5845 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5846 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5847 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5848 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5849 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 5850 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5851 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5852 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5853 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5854 | goto out; |
| 5855 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5856 | |
| 5857 | proto = protocol_by_family(sk->ss_family); |
| 5858 | if (!proto || !proto->connect) { |
| 5859 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5860 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5862 | goto out; |
| 5863 | } |
| 5864 | |
| 5865 | if (port1 != port2) { |
| 5866 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5867 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5869 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5870 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5871 | |
| 5872 | if (!port1) { |
| 5873 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5874 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5876 | goto out; |
| 5877 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5878 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5879 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5880 | goto out; |
| 5881 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5882 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5883 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | } |
| 5885 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5886 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5887 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5888 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5889 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5890 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5892 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5893 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5894 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5895 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5896 | /** |
| 5897 | * The syntax for hash-type config element is |
| 5898 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5899 | * |
| 5900 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5901 | */ |
| 5902 | 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] | 5903 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5904 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5905 | err_code |= ERR_WARN; |
| 5906 | |
| 5907 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5908 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5909 | } |
| 5910 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5911 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5912 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5913 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5914 | 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]); |
| 5915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5916 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5917 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5918 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5919 | 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] | 5920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5921 | goto out; |
| 5922 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5923 | |
| 5924 | /* set the hash function to use */ |
| 5925 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5926 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5927 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5928 | |
| 5929 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5930 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5931 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5932 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5933 | /* set the hash function */ |
| 5934 | if (!strcmp(args[2], "sdbm")) { |
| 5935 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5936 | } |
| 5937 | else if (!strcmp(args[2], "djb2")) { |
| 5938 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5939 | } |
| 5940 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5941 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5942 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5943 | else if (!strcmp(args[2], "crc32")) { |
| 5944 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5945 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5946 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5947 | 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] | 5948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5949 | goto out; |
| 5950 | } |
| 5951 | |
| 5952 | /* set the hash modifier */ |
| 5953 | if (!strcmp(args[3], "avalanche")) { |
| 5954 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5955 | } |
| 5956 | else if (*args[3]) { |
| 5957 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5959 | goto out; |
| 5960 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5961 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5962 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 5963 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 5964 | if (*(args[1]) == 0) { |
| 5965 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 5966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5967 | goto out; |
| 5968 | } |
| 5969 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 5970 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 5971 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 5972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5973 | goto out; |
| 5974 | } |
| 5975 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5976 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5977 | if (!*(args[1])) { |
| 5978 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5980 | goto out; |
| 5981 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5982 | if (*(args[2])) { |
| 5983 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5985 | goto out; |
| 5986 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5987 | free(curproxy->conf.uniqueid_format_string); |
| 5988 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5989 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5990 | free(curproxy->conf.uif_file); |
| 5991 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5992 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5993 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5994 | |
| 5995 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5996 | if (!*(args[1])) { |
| 5997 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5999 | goto out; |
| 6000 | } |
| 6001 | free(curproxy->header_unique_id); |
| 6002 | curproxy->header_unique_id = strdup(args[1]); |
| 6003 | } |
| 6004 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6005 | else if (strcmp(args[0], "log-format") == 0) { |
| 6006 | if (!*(args[1])) { |
| 6007 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6009 | goto out; |
| 6010 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6011 | if (*(args[2])) { |
| 6012 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6014 | goto out; |
| 6015 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6016 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6017 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6018 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6019 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6020 | free(curproxy->conf.logformat_string); |
| 6021 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6022 | |
| 6023 | free(curproxy->conf.lfs_file); |
| 6024 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6025 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6026 | |
| 6027 | /* get a chance to improve log-format error reporting by |
| 6028 | * reporting the correct line-number when possible. |
| 6029 | */ |
| 6030 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6031 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6032 | file, linenum, curproxy->id); |
| 6033 | err_code |= ERR_WARN; |
| 6034 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6035 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6036 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6037 | if (!*(args[1])) { |
| 6038 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6040 | goto out; |
| 6041 | } |
| 6042 | if (*(args[2])) { |
| 6043 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6045 | goto out; |
| 6046 | } |
| 6047 | |
| 6048 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6049 | free(curproxy->conf.logformat_sd_string); |
| 6050 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6051 | |
| 6052 | free(curproxy->conf.lfsd_file); |
| 6053 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6054 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6055 | |
| 6056 | /* get a chance to improve log-format-sd error reporting by |
| 6057 | * reporting the correct line-number when possible. |
| 6058 | */ |
| 6059 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6060 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6061 | file, linenum, curproxy->id); |
| 6062 | err_code |= ERR_WARN; |
| 6063 | } |
| 6064 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6065 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6066 | if (*(args[1]) == 0) { |
| 6067 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 6068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6069 | goto out; |
| 6070 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6071 | chunk_destroy(&curproxy->log_tag); |
| 6072 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6073 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6074 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6075 | /* delete previous herited or defined syslog servers */ |
| 6076 | struct logsrv *back; |
| 6077 | |
| 6078 | if (*(args[1]) != 0) { |
| 6079 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6081 | goto out; |
| 6082 | } |
| 6083 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6084 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6085 | LIST_DEL(&tmplogsrv->list); |
| 6086 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6087 | } |
| 6088 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6089 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6090 | struct logsrv *logsrv; |
| 6091 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6092 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6093 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6094 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6095 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6096 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6097 | LIST_INIT(&node->list); |
| 6098 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6099 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6100 | } |
| 6101 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6102 | struct sockaddr_storage *sk; |
| 6103 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6104 | int arg = 0; |
| 6105 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6106 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6107 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6108 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6109 | /* just after the address, a length may be specified */ |
| 6110 | if (strcmp(args[arg+2], "len") == 0) { |
| 6111 | len = atoi(args[arg+3]); |
| 6112 | if (len < 80 || len > 65535) { |
| 6113 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6114 | file, linenum, args[arg+3]); |
| 6115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6116 | goto out; |
| 6117 | } |
| 6118 | logsrv->maxlen = len; |
| 6119 | |
| 6120 | /* skip these two args */ |
| 6121 | arg += 2; |
| 6122 | } |
| 6123 | else |
| 6124 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6125 | |
| 6126 | if (logsrv->maxlen > global.max_syslog_len) { |
| 6127 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 6128 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 6129 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 6130 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 6131 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6132 | } |
| 6133 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6134 | /* after the length, a format may be specified */ |
| 6135 | if (strcmp(args[arg+2], "format") == 0) { |
| 6136 | logsrv->format = get_log_format(args[arg+3]); |
| 6137 | if (logsrv->format < 0) { |
| 6138 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6140 | goto out; |
| 6141 | } |
| 6142 | |
| 6143 | /* skip these two args */ |
| 6144 | arg += 2; |
| 6145 | } |
| 6146 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6147 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6148 | goto out; |
| 6149 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6150 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6151 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6152 | 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] | 6153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6154 | goto out; |
| 6155 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6156 | } |
| 6157 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6158 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6159 | if (*(args[arg+3])) { |
| 6160 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6161 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6162 | 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] | 6163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6164 | goto out; |
| 6165 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6169 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6170 | if (*(args[arg+4])) { |
| 6171 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6172 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6173 | 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] | 6174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6175 | goto out; |
| 6176 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6177 | } |
| 6178 | } |
| 6179 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6180 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6181 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6182 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6183 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6184 | goto out; |
| 6185 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6186 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6187 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6188 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6189 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6190 | if (port1 != port2) { |
| 6191 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6192 | file, linenum, args[0], args[1]); |
| 6193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6194 | goto out; |
| 6195 | } |
| 6196 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6197 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6198 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6199 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6200 | |
| 6201 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6202 | } |
| 6203 | else { |
| 6204 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6205 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6208 | } |
| 6209 | } |
| 6210 | 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] | 6211 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6212 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6213 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6214 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6215 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6216 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6217 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6218 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6219 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6220 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6221 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6224 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6225 | |
| 6226 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6227 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6228 | free(curproxy->conn_src.iface_name); |
| 6229 | curproxy->conn_src.iface_name = NULL; |
| 6230 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6231 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6232 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6233 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6234 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6235 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6236 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6237 | goto out; |
| 6238 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6239 | |
| 6240 | proto = protocol_by_family(sk->ss_family); |
| 6241 | if (!proto || !proto->connect) { |
| 6242 | 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] | 6243 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6245 | goto out; |
| 6246 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6247 | |
| 6248 | if (port1 != port2) { |
| 6249 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6250 | file, linenum, args[0], args[1]); |
| 6251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6252 | goto out; |
| 6253 | } |
| 6254 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6255 | curproxy->conn_src.source_addr = *sk; |
| 6256 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6257 | |
| 6258 | cur_arg = 2; |
| 6259 | while (*(args[cur_arg])) { |
| 6260 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6261 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6262 | if (!*args[cur_arg + 1]) { |
| 6263 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6264 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6266 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6270 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6271 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6272 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6273 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6274 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6275 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6276 | char *name, *end; |
| 6277 | |
| 6278 | name = args[cur_arg+1] + 7; |
| 6279 | while (isspace(*name)) |
| 6280 | name++; |
| 6281 | |
| 6282 | end = name; |
| 6283 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6284 | end++; |
| 6285 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6286 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6287 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6288 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6289 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6290 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6291 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6292 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6293 | |
| 6294 | /* now look for an occurrence number */ |
| 6295 | while (isspace(*end)) |
| 6296 | end++; |
| 6297 | if (*end == ',') { |
| 6298 | end++; |
| 6299 | name = end; |
| 6300 | if (*end == '-') |
| 6301 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6302 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6303 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6304 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6305 | } |
| 6306 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6307 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6308 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6309 | " occurrences values smaller than %d.\n", |
| 6310 | file, linenum, MAX_HDR_HISTORY); |
| 6311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6312 | goto out; |
| 6313 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6314 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6315 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6316 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6317 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6318 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6319 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6320 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6321 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6322 | goto out; |
| 6323 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6324 | |
| 6325 | proto = protocol_by_family(sk->ss_family); |
| 6326 | if (!proto || !proto->connect) { |
| 6327 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6328 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6330 | goto out; |
| 6331 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6332 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6333 | if (port1 != port2) { |
| 6334 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6335 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6337 | goto out; |
| 6338 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6339 | curproxy->conn_src.tproxy_addr = *sk; |
| 6340 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6341 | } |
| 6342 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6343 | #else /* no TPROXY support */ |
| 6344 | 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] | 6345 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6347 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6348 | #endif |
| 6349 | cur_arg += 2; |
| 6350 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6353 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6354 | #ifdef SO_BINDTODEVICE |
| 6355 | if (!*args[cur_arg + 1]) { |
| 6356 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6357 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6359 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6360 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6361 | free(curproxy->conn_src.iface_name); |
| 6362 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6363 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6364 | global.last_checks |= LSTCHK_NETADM; |
| 6365 | #else |
| 6366 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6367 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6369 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6370 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6371 | cur_arg += 2; |
| 6372 | continue; |
| 6373 | } |
| 6374 | 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] | 6375 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6377 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6378 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6379 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6380 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6381 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6382 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6384 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6385 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6386 | 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] | 6387 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6388 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6389 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6391 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6392 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6393 | |
| 6394 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6395 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6396 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6397 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6398 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6399 | } |
| 6400 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6401 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6402 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6403 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6404 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6405 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6406 | } |
| 6407 | 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] | 6408 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6409 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6410 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6411 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6412 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6413 | } |
| 6414 | 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] | 6415 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6416 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6417 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6418 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6419 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6420 | } |
| 6421 | 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] | 6422 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6423 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6424 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6425 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6426 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6427 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6428 | 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] | 6429 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6430 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6431 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6432 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6433 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6434 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6435 | 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] | 6436 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6437 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6438 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6440 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6441 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6442 | |
| 6443 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6444 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6445 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6446 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6448 | } |
| 6449 | 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] | 6450 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6451 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6452 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6453 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6454 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6455 | } |
| 6456 | 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] | 6457 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6458 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6459 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6460 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6461 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6462 | } |
| 6463 | 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] | 6464 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6465 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6466 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6467 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6469 | } |
| 6470 | 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] | 6471 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6472 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6473 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6474 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6475 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6476 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6477 | 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] | 6478 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6479 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6480 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6481 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6482 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6483 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6484 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6485 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6486 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6487 | if (curproxy == &defproxy) { |
| 6488 | 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] | 6489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6490 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6491 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6492 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6493 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6494 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6495 | if (*(args[1]) == 0) { |
| 6496 | 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] | 6497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6498 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6499 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6500 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6501 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6502 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6503 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6504 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6506 | goto out; |
| 6507 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6508 | err_code |= warnif_cond_conflicts(cond, |
| 6509 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6510 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6511 | } |
| 6512 | else if (*args[2]) { |
| 6513 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6514 | file, linenum, args[0], args[2]); |
| 6515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6516 | goto out; |
| 6517 | } |
| 6518 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6519 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6520 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6521 | wl->s = strdup(args[1]); |
| 6522 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6523 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6524 | } |
| 6525 | 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] | 6526 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6527 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6528 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6530 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6531 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6532 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6533 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6534 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6535 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6536 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6537 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6538 | } |
| 6539 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6540 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6541 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6542 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6543 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6544 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6545 | } |
| 6546 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6547 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6548 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6549 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6550 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6551 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6552 | } |
| 6553 | 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] | 6554 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6555 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6556 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6558 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6559 | } |
| 6560 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6561 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6562 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6563 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6564 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6565 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6566 | } |
| 6567 | 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] | 6568 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6569 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6570 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6571 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6572 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6573 | } |
| 6574 | 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] | 6575 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6576 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6577 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6578 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6579 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6580 | } |
| 6581 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6582 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6583 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6584 | if (curproxy == &defproxy) { |
| 6585 | 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] | 6586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6587 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6588 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6589 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6590 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6591 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6592 | if (*(args[1]) == 0) { |
| 6593 | 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] | 6594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6596 | } |
| 6597 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6598 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6599 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6600 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6601 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6603 | goto out; |
| 6604 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6605 | err_code |= warnif_cond_conflicts(cond, |
| 6606 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6607 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6608 | } |
| 6609 | else if (*args[2]) { |
| 6610 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6611 | file, linenum, args[0], args[2]); |
| 6612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6613 | goto out; |
| 6614 | } |
| 6615 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6616 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6617 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6618 | wl->s = strdup(args[1]); |
| 6619 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6620 | } |
| 6621 | else if (!strcmp(args[0], "errorloc") || |
| 6622 | !strcmp(args[0], "errorloc302") || |
| 6623 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6624 | int errnum, errlen; |
| 6625 | char *err; |
| 6626 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6627 | 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] | 6628 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6629 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6630 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6631 | 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] | 6632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6633 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6634 | } |
| 6635 | |
| 6636 | errnum = atol(args[1]); |
| 6637 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6638 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6639 | err = malloc(errlen); |
| 6640 | 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] | 6641 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6642 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6643 | err = malloc(errlen); |
| 6644 | 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] | 6645 | } |
| 6646 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6647 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6648 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6649 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6650 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6651 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6652 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6653 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6654 | |
| 6655 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6656 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6657 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6658 | free(err); |
| 6659 | } |
| 6660 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6661 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6662 | int errnum, errlen, fd; |
| 6663 | char *err; |
| 6664 | struct stat stat; |
| 6665 | |
| 6666 | 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] | 6667 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6668 | |
| 6669 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6670 | 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] | 6671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6672 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | fd = open(args[2], O_RDONLY); |
| 6676 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6677 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6678 | file, linenum, args[2], args[1]); |
| 6679 | if (fd >= 0) |
| 6680 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6682 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6685 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6686 | errlen = stat.st_size; |
| 6687 | } else { |
| 6688 | 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] | 6689 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6690 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6691 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6695 | errnum = read(fd, err, errlen); |
| 6696 | if (errnum != errlen) { |
| 6697 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6698 | file, linenum, args[2], args[1]); |
| 6699 | close(fd); |
| 6700 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6702 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6703 | } |
| 6704 | close(fd); |
| 6705 | |
| 6706 | errnum = atol(args[1]); |
| 6707 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6708 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6709 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6710 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6711 | break; |
| 6712 | } |
| 6713 | } |
| 6714 | |
| 6715 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6716 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6717 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6718 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6719 | free(err); |
| 6720 | } |
| 6721 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6722 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6723 | struct cfg_kw_list *kwl; |
| 6724 | int index; |
| 6725 | |
| 6726 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6727 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6728 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6729 | continue; |
| 6730 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6731 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6732 | 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] | 6733 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6734 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6736 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6737 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6738 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6739 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6740 | err_code |= ERR_WARN; |
| 6741 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6742 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6743 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6744 | } |
| 6745 | } |
| 6746 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6747 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6748 | 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] | 6749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6750 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6751 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6752 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6753 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6754 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6755 | } |
| 6756 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6757 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6758 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6759 | { |
| 6760 | #ifdef CONFIG_HAP_NS |
| 6761 | const char *err; |
| 6762 | const char *item = args[0]; |
| 6763 | |
| 6764 | if (!strcmp(item, "namespace_list")) { |
| 6765 | return 0; |
| 6766 | } |
| 6767 | else if (!strcmp(item, "namespace")) { |
| 6768 | size_t idx = 1; |
| 6769 | const char *current; |
| 6770 | while (*(current = args[idx++])) { |
| 6771 | err = invalid_char(current); |
| 6772 | if (err) { |
| 6773 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6774 | file, linenum, *err, item, current); |
| 6775 | return ERR_ALERT | ERR_FATAL; |
| 6776 | } |
| 6777 | |
| 6778 | if (netns_store_lookup(current, strlen(current))) { |
| 6779 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6780 | file, linenum, current); |
| 6781 | return ERR_ALERT | ERR_FATAL; |
| 6782 | } |
| 6783 | if (!netns_store_insert(current)) { |
| 6784 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6785 | file, linenum, current); |
| 6786 | return ERR_ALERT | ERR_FATAL; |
| 6787 | } |
| 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | return 0; |
| 6792 | #else |
| 6793 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6794 | file, linenum); |
| 6795 | return ERR_ALERT | ERR_FATAL; |
| 6796 | #endif |
| 6797 | } |
| 6798 | |
| 6799 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6800 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6801 | { |
| 6802 | |
| 6803 | int err_code = 0; |
| 6804 | const char *err; |
| 6805 | |
| 6806 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6807 | struct userlist *newul; |
| 6808 | |
| 6809 | if (!*args[1]) { |
| 6810 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6811 | file, linenum, args[0]); |
| 6812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6813 | goto out; |
| 6814 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6815 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6816 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6817 | |
| 6818 | err = invalid_char(args[1]); |
| 6819 | if (err) { |
| 6820 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6821 | file, linenum, *err, args[0], args[1]); |
| 6822 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6823 | goto out; |
| 6824 | } |
| 6825 | |
| 6826 | for (newul = userlist; newul; newul = newul->next) |
| 6827 | if (!strcmp(newul->name, args[1])) { |
| 6828 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6829 | file, linenum, args[1]); |
| 6830 | err_code |= ERR_WARN; |
| 6831 | goto out; |
| 6832 | } |
| 6833 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6834 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6835 | if (!newul) { |
| 6836 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6837 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6838 | goto out; |
| 6839 | } |
| 6840 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6841 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6842 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6843 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6844 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6845 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6846 | goto out; |
| 6847 | } |
| 6848 | |
| 6849 | newul->next = userlist; |
| 6850 | userlist = newul; |
| 6851 | |
| 6852 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6853 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6854 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6855 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6856 | |
| 6857 | if (!*args[1]) { |
| 6858 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6859 | file, linenum, args[0]); |
| 6860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6861 | goto out; |
| 6862 | } |
| 6863 | |
| 6864 | err = invalid_char(args[1]); |
| 6865 | if (err) { |
| 6866 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6867 | file, linenum, *err, args[0], args[1]); |
| 6868 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6869 | goto out; |
| 6870 | } |
| 6871 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6872 | if (!userlist) |
| 6873 | goto out; |
| 6874 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6875 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6876 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6877 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6878 | file, linenum, args[1], userlist->name); |
| 6879 | err_code |= ERR_ALERT; |
| 6880 | goto out; |
| 6881 | } |
| 6882 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6883 | ag = calloc(1, sizeof(*ag)); |
| 6884 | if (!ag) { |
| 6885 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6886 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6887 | goto out; |
| 6888 | } |
| 6889 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6890 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6891 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6892 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6893 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6894 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6895 | goto out; |
| 6896 | } |
| 6897 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6898 | cur_arg = 2; |
| 6899 | |
| 6900 | while (*args[cur_arg]) { |
| 6901 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6902 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6903 | cur_arg += 2; |
| 6904 | continue; |
| 6905 | } else { |
| 6906 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6907 | file, linenum, args[0]); |
| 6908 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6909 | free(ag->groupusers); |
| 6910 | free(ag->name); |
| 6911 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6912 | goto out; |
| 6913 | } |
| 6914 | } |
| 6915 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6916 | ag->next = userlist->groups; |
| 6917 | userlist->groups = ag; |
| 6918 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6919 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6920 | struct auth_users *newuser; |
| 6921 | int cur_arg; |
| 6922 | |
| 6923 | if (!*args[1]) { |
| 6924 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6925 | file, linenum, args[0]); |
| 6926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6927 | goto out; |
| 6928 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6929 | if (!userlist) |
| 6930 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6931 | |
| 6932 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6933 | if (!strcmp(newuser->user, args[1])) { |
| 6934 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6935 | file, linenum, args[1], userlist->name); |
| 6936 | err_code |= ERR_ALERT; |
| 6937 | goto out; |
| 6938 | } |
| 6939 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6940 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6941 | if (!newuser) { |
| 6942 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6943 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6944 | goto out; |
| 6945 | } |
| 6946 | |
| 6947 | newuser->user = strdup(args[1]); |
| 6948 | |
| 6949 | newuser->next = userlist->users; |
| 6950 | userlist->users = newuser; |
| 6951 | |
| 6952 | cur_arg = 2; |
| 6953 | |
| 6954 | while (*args[cur_arg]) { |
| 6955 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6956 | #ifdef CONFIG_HAP_CRYPT |
| 6957 | if (!crypt("", args[cur_arg + 1])) { |
| 6958 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6959 | file, linenum, newuser->user); |
| 6960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6961 | goto out; |
| 6962 | } |
| 6963 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6964 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6965 | file, linenum); |
| 6966 | err_code |= ERR_ALERT; |
| 6967 | #endif |
| 6968 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6969 | cur_arg += 2; |
| 6970 | continue; |
| 6971 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6972 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6973 | newuser->flags |= AU_O_INSECURE; |
| 6974 | cur_arg += 2; |
| 6975 | continue; |
| 6976 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6977 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6978 | cur_arg += 2; |
| 6979 | continue; |
| 6980 | } else { |
| 6981 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6982 | file, linenum, args[0]); |
| 6983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6984 | goto out; |
| 6985 | } |
| 6986 | } |
| 6987 | } else { |
| 6988 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6990 | } |
| 6991 | |
| 6992 | out: |
| 6993 | return err_code; |
| 6994 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6995 | |
| 6996 | /* |
| 6997 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6998 | * Returns the error code, 0 if OK, or any combination of : |
| 6999 | * - ERR_ABORT: must abort ASAP |
| 7000 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7001 | * - ERR_WARN: a warning has been emitted |
| 7002 | * - ERR_ALERT: an alert has been emitted |
| 7003 | * Only the two first ones can stop processing, the two others are just |
| 7004 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7005 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7006 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7007 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7008 | char *thisline; |
| 7009 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7010 | FILE *f; |
| 7011 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7012 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7013 | struct cfg_section *cs = NULL; |
| 7014 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7015 | int readbytes = 0; |
| 7016 | |
| 7017 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7018 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7019 | return -1; |
| 7020 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7021 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7022 | if ((f=fopen(file,"r")) == NULL) { |
| 7023 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7024 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7025 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7026 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7027 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7028 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7029 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7030 | char *end; |
| 7031 | char *args[MAX_LINE_ARGS + 1]; |
| 7032 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7033 | int dquote = 0; /* double quote */ |
| 7034 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7035 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7036 | linenum++; |
| 7037 | |
| 7038 | end = line + strlen(line); |
| 7039 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7040 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7041 | /* Check if we reached the limit and the last char is not \n. |
| 7042 | * Watch out for the last line without the terminating '\n'! |
| 7043 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7044 | char *newline; |
| 7045 | int newlinesize = linesize * 2; |
| 7046 | |
| 7047 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7048 | if (newline == NULL) { |
| 7049 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7050 | file, linenum); |
| 7051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7052 | continue; |
| 7053 | } |
| 7054 | |
| 7055 | readbytes = linesize - 1; |
| 7056 | linesize = newlinesize; |
| 7057 | thisline = newline; |
| 7058 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7059 | } |
| 7060 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7061 | readbytes = 0; |
| 7062 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7063 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7064 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7065 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7066 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7067 | arg = 0; |
| 7068 | args[arg] = line; |
| 7069 | |
| 7070 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7071 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7072 | if (dquote) |
| 7073 | dquote = 0; |
| 7074 | else |
| 7075 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7076 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7077 | end--; |
| 7078 | } |
| 7079 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7080 | if (squote) |
| 7081 | squote = 0; |
| 7082 | else |
| 7083 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7084 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7085 | end--; |
| 7086 | } |
| 7087 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7088 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7089 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7090 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7091 | int skip = 0; |
| 7092 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7093 | *line = line[1]; |
| 7094 | skip = 1; |
| 7095 | } |
| 7096 | else if (line[1] == 'r') { |
| 7097 | *line = '\r'; |
| 7098 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7099 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7100 | else if (line[1] == 'n') { |
| 7101 | *line = '\n'; |
| 7102 | skip = 1; |
| 7103 | } |
| 7104 | else if (line[1] == 't') { |
| 7105 | *line = '\t'; |
| 7106 | skip = 1; |
| 7107 | } |
| 7108 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7109 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7110 | unsigned char hex1, hex2; |
| 7111 | hex1 = toupper(line[2]) - '0'; |
| 7112 | hex2 = toupper(line[3]) - '0'; |
| 7113 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7114 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7115 | *line = (hex1<<4) + hex2; |
| 7116 | skip = 3; |
| 7117 | } |
| 7118 | else { |
| 7119 | 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] | 7120 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7121 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7122 | } else if (line[1] == '"') { |
| 7123 | *line = '"'; |
| 7124 | skip = 1; |
| 7125 | } else if (line[1] == '\'') { |
| 7126 | *line = '\''; |
| 7127 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7128 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7129 | *line = '$'; |
| 7130 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7131 | } |
| 7132 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7133 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7134 | end -= skip; |
| 7135 | } |
| 7136 | line++; |
| 7137 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7138 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7139 | /* end of string, end of loop */ |
| 7140 | *line = 0; |
| 7141 | break; |
| 7142 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7143 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7144 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7145 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7146 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7147 | line++; |
| 7148 | args[++arg] = line; |
| 7149 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7150 | else if (dquote && *line == '$') { |
| 7151 | /* environment variables are evaluated inside double quotes */ |
| 7152 | char *var_beg; |
| 7153 | char *var_end; |
| 7154 | char save_char; |
| 7155 | char *value; |
| 7156 | int val_len; |
| 7157 | int newlinesize; |
| 7158 | int braces = 0; |
| 7159 | |
| 7160 | var_beg = line + 1; |
| 7161 | var_end = var_beg; |
| 7162 | |
| 7163 | if (*var_beg == '{') { |
| 7164 | var_beg++; |
| 7165 | var_end++; |
| 7166 | braces = 1; |
| 7167 | } |
| 7168 | |
| 7169 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7170 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7172 | goto next_line; /* skip current line */ |
| 7173 | } |
| 7174 | |
| 7175 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7176 | var_end++; |
| 7177 | |
| 7178 | save_char = *var_end; |
| 7179 | *var_end = '\0'; |
| 7180 | value = getenv(var_beg); |
| 7181 | *var_end = save_char; |
| 7182 | val_len = value ? strlen(value) : 0; |
| 7183 | |
| 7184 | if (braces) { |
| 7185 | if (*var_end == '}') { |
| 7186 | var_end++; |
| 7187 | braces = 0; |
| 7188 | } else { |
| 7189 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7191 | goto next_line; /* skip current line */ |
| 7192 | } |
| 7193 | } |
| 7194 | |
| 7195 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7196 | |
| 7197 | /* if not enough space in thisline */ |
| 7198 | if (newlinesize > linesize) { |
| 7199 | char *newline; |
| 7200 | |
| 7201 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7202 | if (newline == NULL) { |
| 7203 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7205 | goto next_line; /* slip current line */ |
| 7206 | } |
| 7207 | /* recompute pointers if realloc returns a new pointer */ |
| 7208 | if (newline != thisline) { |
| 7209 | int i; |
| 7210 | int diff; |
| 7211 | |
| 7212 | for (i = 0; i <= arg; i++) { |
| 7213 | diff = args[i] - thisline; |
| 7214 | args[i] = newline + diff; |
| 7215 | } |
| 7216 | |
| 7217 | diff = var_end - thisline; |
| 7218 | var_end = newline + diff; |
| 7219 | diff = end - thisline; |
| 7220 | end = newline + diff; |
| 7221 | diff = line - thisline; |
| 7222 | line = newline + diff; |
| 7223 | thisline = newline; |
| 7224 | } |
| 7225 | linesize = newlinesize; |
| 7226 | } |
| 7227 | |
| 7228 | /* insert value inside the line */ |
| 7229 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7230 | memcpy(line, value, val_len); |
| 7231 | end += val_len - (var_end - line); |
| 7232 | line += val_len; |
| 7233 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7234 | else { |
| 7235 | line++; |
| 7236 | } |
| 7237 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7238 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7239 | if (dquote) { |
| 7240 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7242 | } |
| 7243 | |
| 7244 | if (squote) { |
| 7245 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7247 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7248 | |
| 7249 | /* empty line */ |
| 7250 | if (!**args) |
| 7251 | continue; |
| 7252 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7253 | if (*line) { |
| 7254 | /* we had to stop due to too many args. |
| 7255 | * Let's terminate the string, print the offending part then cut the |
| 7256 | * last arg. |
| 7257 | */ |
| 7258 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7259 | line++; |
| 7260 | *line = '\0'; |
| 7261 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7262 | 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] | 7263 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7265 | args[arg] = line; |
| 7266 | } |
| 7267 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7268 | /* zero out remaining args and ensure that at least one entry |
| 7269 | * is zeroed out. |
| 7270 | */ |
| 7271 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7272 | args[arg] = line; |
| 7273 | } |
| 7274 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7275 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7276 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7277 | char *tmp; |
| 7278 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7279 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7280 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7281 | for (arg=0; *args[arg+1]; arg++) |
| 7282 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7283 | *tmp = '\0'; // fix the next arg to \0 |
| 7284 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7285 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7286 | else if (!strcmp(args[0], "default")) { |
| 7287 | kwm = KWM_DEF; |
| 7288 | for (arg=0; *args[arg+1]; arg++) |
| 7289 | args[arg] = args[arg+1]; // shift args after inversion |
| 7290 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7291 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7292 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7293 | strcmp(args[0], "log") != 0) { |
| 7294 | 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] | 7295 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7296 | } |
| 7297 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7298 | /* detect section start */ |
| 7299 | list_for_each_entry(ics, §ions, list) { |
| 7300 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7301 | cursection = ics->section_name; |
| 7302 | cs = ics; |
| 7303 | break; |
| 7304 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7305 | } |
| 7306 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7307 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7308 | if (cs) |
| 7309 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7310 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7311 | 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] | 7312 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7313 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7314 | |
| 7315 | if (err_code & ERR_ABORT) |
| 7316 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7317 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7318 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7319 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7320 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7321 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7322 | } |
| 7323 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7324 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7325 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7326 | * bound to all of its processes. After that, if the target is a "listen" |
| 7327 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7328 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7329 | * checked first to ensure that <to> is already bound to all processes of |
| 7330 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7331 | * path to the destination. |
| 7332 | * |
| 7333 | * It is possible to set <to> to NULL for the first call so that the function |
| 7334 | * takes care of visiting the initial frontend in <from>. |
| 7335 | * |
| 7336 | * It is important to note that the function relies on the fact that all names |
| 7337 | * have already been resolved. |
| 7338 | */ |
| 7339 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7340 | { |
| 7341 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7342 | |
| 7343 | if (to) { |
| 7344 | /* check whether we need to go down */ |
| 7345 | if (from->bind_proc && |
| 7346 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7347 | return; |
| 7348 | |
| 7349 | if (!from->bind_proc && !to->bind_proc) |
| 7350 | return; |
| 7351 | |
| 7352 | to->bind_proc = from->bind_proc ? |
| 7353 | (to->bind_proc | from->bind_proc) : 0; |
| 7354 | |
| 7355 | /* now propagate down */ |
| 7356 | from = to; |
| 7357 | } |
| 7358 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7359 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7360 | return; |
| 7361 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7362 | if (from->state == PR_STSTOPPED) |
| 7363 | return; |
| 7364 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7365 | /* default_backend */ |
| 7366 | if (from->defbe.be) |
| 7367 | propagate_processes(from, from->defbe.be); |
| 7368 | |
| 7369 | /* use_backend */ |
| 7370 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7371 | if (rule->dynamic) |
| 7372 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7373 | to = rule->be.backend; |
| 7374 | propagate_processes(from, to); |
| 7375 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7376 | } |
| 7377 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7378 | /* |
| 7379 | * Returns the error code, 0 if OK, or any combination of : |
| 7380 | * - ERR_ABORT: must abort ASAP |
| 7381 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7382 | * - ERR_WARN: a warning has been emitted |
| 7383 | * - ERR_ALERT: an alert has been emitted |
| 7384 | * Only the two first ones can stop processing, the two others are just |
| 7385 | * indicators. |
| 7386 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7387 | int check_config_validity() |
| 7388 | { |
| 7389 | int cfgerr = 0; |
| 7390 | struct proxy *curproxy = NULL; |
| 7391 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7392 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7393 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7394 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7395 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7396 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7397 | /* |
| 7398 | * Now, check for the integrity of all that we have collected. |
| 7399 | */ |
| 7400 | |
| 7401 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7402 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7403 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7404 | if (!global.tune.max_http_hdr) |
| 7405 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7406 | |
| 7407 | if (!global.tune.cookie_len) |
| 7408 | global.tune.cookie_len = CAPTURE_LEN; |
| 7409 | |
| 7410 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7411 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7412 | /* Post initialisation of the users and groups lists. */ |
| 7413 | err_code = userlist_postinit(); |
| 7414 | if (err_code != ERR_NONE) |
| 7415 | goto out; |
| 7416 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7417 | /* first, we will invert the proxy list order */ |
| 7418 | curproxy = NULL; |
| 7419 | while (proxy) { |
| 7420 | struct proxy *next; |
| 7421 | |
| 7422 | next = proxy->next; |
| 7423 | proxy->next = curproxy; |
| 7424 | curproxy = proxy; |
| 7425 | if (!next) |
| 7426 | break; |
| 7427 | proxy = next; |
| 7428 | } |
| 7429 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7430 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7431 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7432 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7433 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7434 | struct act_rule *trule; |
| 7435 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7436 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7437 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7438 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7439 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7440 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7441 | /* proxy ID not set, use automatic numbering with first |
| 7442 | * spare entry starting with next_pxid. |
| 7443 | */ |
| 7444 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7445 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7446 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7447 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7448 | next_pxid++; |
| 7449 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7450 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7451 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7452 | /* ensure we don't keep listeners uselessly bound */ |
| 7453 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7454 | free((void *)curproxy->table.peers.name); |
| 7455 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7456 | continue; |
| 7457 | } |
| 7458 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7459 | /* Check multi-process mode compatibility for the current proxy */ |
| 7460 | |
| 7461 | if (curproxy->bind_proc) { |
| 7462 | /* an explicit bind-process was specified, let's check how many |
| 7463 | * processes remain. |
| 7464 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7465 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7466 | |
| 7467 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7468 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7469 | 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); |
| 7470 | curproxy->bind_proc = 1; |
| 7471 | } |
| 7472 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7473 | 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); |
| 7474 | curproxy->bind_proc = 0; |
| 7475 | } |
| 7476 | } |
| 7477 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7478 | /* check and reduce the bind-proc of each listener */ |
| 7479 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7480 | unsigned long mask; |
| 7481 | |
| 7482 | if (!bind_conf->bind_proc) |
| 7483 | continue; |
| 7484 | |
| 7485 | mask = nbits(global.nbproc); |
| 7486 | if (curproxy->bind_proc) |
| 7487 | mask &= curproxy->bind_proc; |
| 7488 | /* mask cannot be null here thanks to the previous checks */ |
| 7489 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7490 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7491 | bind_conf->bind_proc &= mask; |
| 7492 | |
| 7493 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7494 | 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", |
| 7495 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7496 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7497 | } |
| 7498 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7499 | 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", |
| 7500 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7501 | bind_conf->bind_proc = 0; |
| 7502 | } |
| 7503 | } |
| 7504 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7505 | switch (curproxy->mode) { |
| 7506 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7507 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7508 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7509 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7510 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7511 | cfgerr++; |
| 7512 | } |
| 7513 | |
| 7514 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7515 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7516 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7517 | break; |
| 7518 | |
| 7519 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7520 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7521 | break; |
| 7522 | |
| 7523 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7524 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7525 | break; |
| 7526 | } |
| 7527 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7528 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7529 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7530 | proxy_type_str(curproxy), curproxy->id); |
| 7531 | err_code |= ERR_WARN; |
| 7532 | } |
| 7533 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7534 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7535 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7536 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7537 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7538 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7539 | cfgerr++; |
| 7540 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7541 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7542 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7543 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7544 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7545 | cfgerr++; |
| 7546 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7547 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7548 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7549 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7550 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7551 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7552 | } |
| 7553 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7554 | 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] | 7555 | /* If no LB algo is set in a backend, and we're not in |
| 7556 | * transparent mode, dispatch mode nor proxy mode, we |
| 7557 | * want to use balance roundrobin by default. |
| 7558 | */ |
| 7559 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7560 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7561 | } |
| 7562 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7563 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7564 | if (curproxy->options & PR_O_DISPATCH) |
| 7565 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7566 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7567 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7568 | else if (curproxy->options & PR_O_TRANSP) |
| 7569 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7570 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7571 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7572 | if (curproxy->options & PR_O_DISABLE404) { |
| 7573 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7574 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7575 | err_code |= ERR_WARN; |
| 7576 | curproxy->options &= ~PR_O_DISABLE404; |
| 7577 | } |
| 7578 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7579 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7580 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7581 | err_code |= ERR_WARN; |
| 7582 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7583 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7584 | } |
| 7585 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7586 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7587 | if (!global.external_check) { |
| 7588 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7589 | curproxy->id, "option external-check"); |
| 7590 | cfgerr++; |
| 7591 | } |
| 7592 | if (!curproxy->check_command) { |
| 7593 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7594 | curproxy->id, "option external-check"); |
| 7595 | cfgerr++; |
| 7596 | } |
| 7597 | } |
| 7598 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7599 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7600 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7601 | Warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of " |
Pieter Baauw | 8669e97 | 2015-08-17 00:45:05 +0200 | [diff] [blame] | 7602 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7603 | "'email-alert myhostname', or 'email-alert to' " |
| 7604 | "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' " |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7605 | "to be present).\n", |
| 7606 | proxy_type_str(curproxy), curproxy->id); |
| 7607 | err_code |= ERR_WARN; |
| 7608 | free_email_alert(curproxy); |
| 7609 | } |
| 7610 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7611 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7612 | } |
| 7613 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7614 | if (curproxy->check_command) { |
| 7615 | int clear = 0; |
| 7616 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7617 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7618 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7619 | err_code |= ERR_WARN; |
| 7620 | clear = 1; |
| 7621 | } |
| 7622 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7623 | Alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n", |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7624 | curproxy->id, "external-check command"); |
| 7625 | cfgerr++; |
| 7626 | } |
| 7627 | if (clear) { |
| 7628 | free(curproxy->check_command); |
| 7629 | curproxy->check_command = NULL; |
| 7630 | } |
| 7631 | } |
| 7632 | |
| 7633 | if (curproxy->check_path) { |
| 7634 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7635 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7636 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7637 | err_code |= ERR_WARN; |
| 7638 | free(curproxy->check_path); |
| 7639 | curproxy->check_path = NULL; |
| 7640 | } |
| 7641 | } |
| 7642 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7643 | /* if a default backend was specified, let's find it */ |
| 7644 | if (curproxy->defbe.name) { |
| 7645 | struct proxy *target; |
| 7646 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7647 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7648 | if (!target) { |
| 7649 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7650 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7651 | cfgerr++; |
| 7652 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7653 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7654 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7655 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7656 | } else if (target->mode != curproxy->mode && |
| 7657 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7658 | |
| 7659 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7660 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7661 | curproxy->conf.file, curproxy->conf.line, |
| 7662 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7663 | target->conf.file, target->conf.line); |
| 7664 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7665 | } else { |
| 7666 | free(curproxy->defbe.name); |
| 7667 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7668 | |
| 7669 | /* Emit a warning if this proxy also has some servers */ |
| 7670 | if (curproxy->srv) { |
| 7671 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7672 | curproxy->id); |
| 7673 | err_code |= ERR_WARN; |
| 7674 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7675 | } |
| 7676 | } |
| 7677 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7678 | /* find the target proxy for 'use_backend' rules */ |
| 7679 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7680 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7681 | struct logformat_node *node; |
| 7682 | char *pxname; |
| 7683 | |
| 7684 | /* Try to parse the string as a log format expression. If the result |
| 7685 | * of the parsing is only one entry containing a simple string, then |
| 7686 | * it's a standard string corresponding to a static rule, thus the |
| 7687 | * parsing is cancelled and be.name is restored to be resolved. |
| 7688 | */ |
| 7689 | pxname = rule->be.name; |
| 7690 | LIST_INIT(&rule->be.expr); |
| 7691 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 7692 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 7693 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7694 | |
| 7695 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7696 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7697 | rule->dynamic = 1; |
| 7698 | free(pxname); |
| 7699 | continue; |
| 7700 | } |
| 7701 | /* simple string: free the expression and fall back to static rule */ |
| 7702 | free(node->arg); |
| 7703 | free(node); |
| 7704 | } |
| 7705 | |
| 7706 | rule->dynamic = 0; |
| 7707 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7708 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7709 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7710 | if (!target) { |
| 7711 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7712 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7713 | cfgerr++; |
| 7714 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7715 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7716 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7717 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7718 | } else if (target->mode != curproxy->mode && |
| 7719 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7720 | |
| 7721 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7722 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7723 | curproxy->conf.file, curproxy->conf.line, |
| 7724 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7725 | target->conf.file, target->conf.line); |
| 7726 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7727 | } else { |
| 7728 | free((void *)rule->be.name); |
| 7729 | rule->be.backend = target; |
| 7730 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7731 | } |
| 7732 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7733 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7734 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7735 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7736 | |
| 7737 | if (!target) { |
| 7738 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7739 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7740 | cfgerr++; |
| 7741 | continue; |
| 7742 | } |
| 7743 | free((void *)srule->srv.name); |
| 7744 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7745 | } |
| 7746 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7747 | /* find the target table for 'stick' rules */ |
| 7748 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7749 | struct proxy *target; |
| 7750 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7751 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7752 | if (mrule->flags & STK_IS_STORE) |
| 7753 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7754 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7755 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7756 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7757 | else |
| 7758 | target = curproxy; |
| 7759 | |
| 7760 | if (!target) { |
| 7761 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7762 | curproxy->id, mrule->table.name); |
| 7763 | cfgerr++; |
| 7764 | } |
| 7765 | else if (target->table.size == 0) { |
| 7766 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7767 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7768 | cfgerr++; |
| 7769 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7770 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7771 | 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] | 7772 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7773 | cfgerr++; |
| 7774 | } |
| 7775 | else { |
| 7776 | free((void *)mrule->table.name); |
| 7777 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7778 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7779 | } |
| 7780 | } |
| 7781 | |
| 7782 | /* find the target table for 'store response' rules */ |
| 7783 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7784 | struct proxy *target; |
| 7785 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7786 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7787 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7788 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7789 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7790 | else |
| 7791 | target = curproxy; |
| 7792 | |
| 7793 | if (!target) { |
| 7794 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7795 | curproxy->id, mrule->table.name); |
| 7796 | cfgerr++; |
| 7797 | } |
| 7798 | else if (target->table.size == 0) { |
| 7799 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7800 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7801 | cfgerr++; |
| 7802 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7803 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7804 | 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] | 7805 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7806 | cfgerr++; |
| 7807 | } |
| 7808 | else { |
| 7809 | free((void *)mrule->table.name); |
| 7810 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7811 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7812 | } |
| 7813 | } |
| 7814 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7815 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7816 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7817 | struct proxy *target; |
| 7818 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7819 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7820 | continue; |
| 7821 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7822 | if (trule->arg.trk_ctr.table.n) |
| 7823 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7824 | else |
| 7825 | target = curproxy; |
| 7826 | |
| 7827 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7828 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7829 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7830 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7831 | cfgerr++; |
| 7832 | } |
| 7833 | else if (target->table.size == 0) { |
| 7834 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7835 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7836 | cfgerr++; |
| 7837 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7838 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7839 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7840 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7841 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7842 | cfgerr++; |
| 7843 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7844 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7845 | free(trule->arg.trk_ctr.table.n); |
| 7846 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7847 | /* 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] | 7848 | * to pass a list of counters to track and allocate them right here using |
| 7849 | * stktable_alloc_data_type(). |
| 7850 | */ |
| 7851 | } |
| 7852 | } |
| 7853 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7854 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7855 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7856 | struct proxy *target; |
| 7857 | |
| 7858 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7859 | continue; |
| 7860 | |
| 7861 | if (trule->arg.trk_ctr.table.n) |
| 7862 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7863 | else |
| 7864 | target = curproxy; |
| 7865 | |
| 7866 | if (!target) { |
| 7867 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7868 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7869 | tcp_trk_idx(trule->action)); |
| 7870 | cfgerr++; |
| 7871 | } |
| 7872 | else if (target->table.size == 0) { |
| 7873 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7874 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7875 | cfgerr++; |
| 7876 | } |
| 7877 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7878 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7879 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7880 | tcp_trk_idx(trule->action)); |
| 7881 | cfgerr++; |
| 7882 | } |
| 7883 | else { |
| 7884 | free(trule->arg.trk_ctr.table.n); |
| 7885 | trule->arg.trk_ctr.table.t = &target->table; |
| 7886 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7887 | * to pass a list of counters to track and allocate them right here using |
| 7888 | * stktable_alloc_data_type(). |
| 7889 | */ |
| 7890 | } |
| 7891 | } |
| 7892 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7893 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7894 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7895 | struct proxy *target; |
| 7896 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7897 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7898 | continue; |
| 7899 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7900 | if (trule->arg.trk_ctr.table.n) |
| 7901 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7902 | else |
| 7903 | target = curproxy; |
| 7904 | |
| 7905 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7906 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7907 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7908 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7909 | cfgerr++; |
| 7910 | } |
| 7911 | else if (target->table.size == 0) { |
| 7912 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7913 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7914 | cfgerr++; |
| 7915 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7916 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7917 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7918 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7919 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7920 | cfgerr++; |
| 7921 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7922 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7923 | free(trule->arg.trk_ctr.table.n); |
| 7924 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7925 | /* 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] | 7926 | * to pass a list of counters to track and allocate them right here using |
| 7927 | * stktable_alloc_data_type(). |
| 7928 | */ |
| 7929 | } |
| 7930 | } |
| 7931 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7932 | /* parse http-request capture rules to ensure id really exists */ |
| 7933 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7934 | if (hrqrule->action != ACT_CUSTOM || |
| 7935 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 7936 | continue; |
| 7937 | |
| 7938 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 7939 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 7940 | curproxy->id, hrqrule->arg.capid.idx); |
| 7941 | cfgerr++; |
| 7942 | } |
| 7943 | } |
| 7944 | |
| 7945 | /* parse http-response capture rules to ensure id really exists */ |
| 7946 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7947 | if (hrqrule->action != ACT_CUSTOM || |
| 7948 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 7949 | continue; |
| 7950 | |
| 7951 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 7952 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 7953 | curproxy->id, hrqrule->arg.capid.idx); |
| 7954 | cfgerr++; |
| 7955 | } |
| 7956 | } |
| 7957 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7958 | /* find the target table for 'http-request' layer 7 rules */ |
| 7959 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7960 | struct proxy *target; |
| 7961 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7962 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7963 | continue; |
| 7964 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7965 | if (hrqrule->arg.trk_ctr.table.n) |
| 7966 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7967 | else |
| 7968 | target = curproxy; |
| 7969 | |
| 7970 | if (!target) { |
| 7971 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7972 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7973 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7974 | cfgerr++; |
| 7975 | } |
| 7976 | else if (target->table.size == 0) { |
| 7977 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7978 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7979 | cfgerr++; |
| 7980 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7981 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7982 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7983 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7984 | http_trk_idx(hrqrule->action)); |
| 7985 | cfgerr++; |
| 7986 | } |
| 7987 | else { |
| 7988 | free(hrqrule->arg.trk_ctr.table.n); |
| 7989 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 7990 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7991 | * to pass a list of counters to track and allocate them right here using |
| 7992 | * stktable_alloc_data_type(). |
| 7993 | */ |
| 7994 | } |
| 7995 | } |
| 7996 | |
| 7997 | /* find the target table for 'http-response' layer 7 rules */ |
| 7998 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7999 | struct proxy *target; |
| 8000 | |
| 8001 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 8002 | continue; |
| 8003 | |
| 8004 | if (hrqrule->arg.trk_ctr.table.n) |
| 8005 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 8006 | else |
| 8007 | target = curproxy; |
| 8008 | |
| 8009 | if (!target) { |
| 8010 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 8011 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 8012 | http_trk_idx(hrqrule->action)); |
| 8013 | cfgerr++; |
| 8014 | } |
| 8015 | else if (target->table.size == 0) { |
| 8016 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 8017 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 8018 | cfgerr++; |
| 8019 | } |
| 8020 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 8021 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 8022 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 8023 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8024 | cfgerr++; |
| 8025 | } |
| 8026 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8027 | free(hrqrule->arg.trk_ctr.table.n); |
| 8028 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8029 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8030 | * to pass a list of counters to track and allocate them right here using |
| 8031 | * stktable_alloc_data_type(). |
| 8032 | */ |
| 8033 | } |
| 8034 | } |
| 8035 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8036 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8037 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8038 | /* insert block_rules into http_req_rules at the beginning */ |
| 8039 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8040 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8041 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8042 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8043 | LIST_INIT(&curproxy->block_rules); |
| 8044 | } |
| 8045 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8046 | if (curproxy->table.peers.name) { |
| 8047 | struct peers *curpeers = peers; |
| 8048 | |
| 8049 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 8050 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8051 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8052 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8053 | break; |
| 8054 | } |
| 8055 | } |
| 8056 | |
| 8057 | if (!curpeers) { |
| 8058 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8059 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8060 | free((void *)curproxy->table.peers.name); |
| 8061 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8062 | cfgerr++; |
| 8063 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8064 | else if (curpeers->state == PR_STSTOPPED) { |
| 8065 | /* silently disable this peers section */ |
| 8066 | curproxy->table.peers.p = NULL; |
| 8067 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8068 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8069 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8070 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8071 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8072 | cfgerr++; |
| 8073 | } |
| 8074 | } |
| 8075 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8076 | |
| 8077 | if (curproxy->email_alert.mailers.name) { |
| 8078 | struct mailers *curmailers = mailers; |
| 8079 | |
| 8080 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 8081 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8082 | free(curproxy->email_alert.mailers.name); |
| 8083 | curproxy->email_alert.mailers.m = curmailers; |
| 8084 | curmailers->users++; |
| 8085 | break; |
| 8086 | } |
| 8087 | } |
| 8088 | |
| 8089 | if (!curmailers) { |
| 8090 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8091 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8092 | free_email_alert(curproxy); |
| 8093 | cfgerr++; |
| 8094 | } |
| 8095 | } |
| 8096 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8097 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8098 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8099 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8100 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8101 | "proxy", curproxy->id); |
| 8102 | cfgerr++; |
| 8103 | goto out_uri_auth_compat; |
| 8104 | } |
| 8105 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8106 | 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] | 8107 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8108 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8109 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8110 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8111 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8112 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8113 | |
| 8114 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8115 | uri_auth_compat_req[i++] = "realm"; |
| 8116 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8117 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8118 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8119 | uri_auth_compat_req[i++] = "unless"; |
| 8120 | uri_auth_compat_req[i++] = "{"; |
| 8121 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8122 | uri_auth_compat_req[i++] = "}"; |
| 8123 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8124 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8125 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8126 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8127 | cfgerr++; |
| 8128 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8129 | } |
| 8130 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8131 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8132 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8133 | if (curproxy->uri_auth->auth_realm) { |
| 8134 | free(curproxy->uri_auth->auth_realm); |
| 8135 | curproxy->uri_auth->auth_realm = NULL; |
| 8136 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8137 | |
| 8138 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8139 | } |
| 8140 | out_uri_auth_compat: |
| 8141 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8142 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8143 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8144 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8145 | if (!curproxy->conf.logformat_sd_string) { |
| 8146 | /* set the default logformat_sd_string */ |
| 8147 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8148 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8149 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8150 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8151 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8152 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8153 | /* compile the log format */ |
| 8154 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8155 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8156 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8157 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8158 | free(curproxy->conf.logformat_string); |
| 8159 | curproxy->conf.logformat_string = NULL; |
| 8160 | free(curproxy->conf.lfs_file); |
| 8161 | curproxy->conf.lfs_file = NULL; |
| 8162 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8163 | |
| 8164 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8165 | free(curproxy->conf.logformat_sd_string); |
| 8166 | curproxy->conf.logformat_sd_string = NULL; |
| 8167 | free(curproxy->conf.lfsd_file); |
| 8168 | curproxy->conf.lfsd_file = NULL; |
| 8169 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8170 | } |
| 8171 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8172 | if (curproxy->conf.logformat_string) { |
| 8173 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8174 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8175 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 8176 | 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] | 8177 | 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] | 8178 | curproxy->conf.args.file = NULL; |
| 8179 | curproxy->conf.args.line = 0; |
| 8180 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8181 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8182 | if (curproxy->conf.logformat_sd_string) { |
| 8183 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8184 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8185 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
| 8186 | parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
| 8187 | SMP_VAL_FE_LOG_END, curproxy->conf.lfsd_file, curproxy->conf.lfsd_line); |
| 8188 | add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd); |
| 8189 | curproxy->conf.args.file = NULL; |
| 8190 | curproxy->conf.args.line = 0; |
| 8191 | } |
| 8192 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8193 | if (curproxy->conf.uniqueid_format_string) { |
| 8194 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8195 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8196 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 8197 | 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] | 8198 | (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] | 8199 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8200 | curproxy->conf.args.file = NULL; |
| 8201 | curproxy->conf.args.line = 0; |
| 8202 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8203 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8204 | /* only now we can check if some args remain unresolved. |
| 8205 | * This must be done after the users and groups resolution. |
| 8206 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8207 | cfgerr += smp_resolve_args(curproxy); |
| 8208 | if (!cfgerr) |
| 8209 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8210 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8211 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8212 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8213 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8214 | (!curproxy->timeout.connect || |
| 8215 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8216 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8217 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8218 | " | 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] | 8219 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8220 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8221 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8222 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8223 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8224 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8225 | * We must still support older configurations, so let's find out whether those |
| 8226 | * parameters have been set or must be copied from contimeouts. |
| 8227 | */ |
| 8228 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8229 | if (!curproxy->timeout.tarpit || |
| 8230 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8231 | /* tarpit timeout not set. We search in the following order: |
| 8232 | * default.tarpit, curr.connect, default.connect. |
| 8233 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8234 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8235 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8236 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8237 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8238 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8239 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8240 | } |
| 8241 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8242 | (!curproxy->timeout.queue || |
| 8243 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8244 | /* queue timeout not set. We search in the following order: |
| 8245 | * default.queue, curr.connect, default.connect. |
| 8246 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8247 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8248 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8249 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8250 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8251 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8252 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8253 | } |
| 8254 | } |
| 8255 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8256 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8257 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8258 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8259 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8260 | } |
| 8261 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8262 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8263 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8264 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8265 | proxy_type_str(curproxy), curproxy->id); |
| 8266 | err_code |= ERR_WARN; |
| 8267 | } |
| 8268 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8269 | /* ensure that cookie capture length is not too large */ |
| 8270 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8271 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8272 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8273 | err_code |= ERR_WARN; |
| 8274 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8275 | } |
| 8276 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8277 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8278 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8279 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8280 | curproxy->nb_req_cap * sizeof(char *), |
| 8281 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8285 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8286 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8287 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8288 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8289 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8290 | switch (curproxy->load_server_state_from_file) { |
| 8291 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8292 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8293 | break; |
| 8294 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8295 | if (!global.server_state_file) { |
| 8296 | Warning("config : backend '%s' configured to load server state file from global section 'server-state-file' directive. Unfortunately, 'server-state-file' is not set!\n", |
| 8297 | curproxy->id); |
| 8298 | err_code |= ERR_WARN; |
| 8299 | } |
| 8300 | break; |
| 8301 | } |
| 8302 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8303 | /* first, we will invert the servers list order */ |
| 8304 | newsrv = NULL; |
| 8305 | while (curproxy->srv) { |
| 8306 | struct server *next; |
| 8307 | |
| 8308 | next = curproxy->srv->next; |
| 8309 | curproxy->srv->next = newsrv; |
| 8310 | newsrv = curproxy->srv; |
| 8311 | if (!next) |
| 8312 | break; |
| 8313 | curproxy->srv = next; |
| 8314 | } |
| 8315 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8316 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8317 | * We only emit a warning for the first conflict affecting each server, |
| 8318 | * in order to avoid combinatory explosion if all servers have the same |
| 8319 | * name. We do that only for servers which do not have an explicit ID, |
| 8320 | * because these IDs were made also for distinguishing them and we don't |
| 8321 | * want to annoy people who correctly manage them. |
| 8322 | */ |
| 8323 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8324 | struct server *other_srv; |
| 8325 | |
| 8326 | if (newsrv->puid) |
| 8327 | continue; |
| 8328 | |
| 8329 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8330 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8331 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8332 | newsrv->conf.file, newsrv->conf.line, |
| 8333 | proxy_type_str(curproxy), curproxy->id, |
| 8334 | newsrv->id, other_srv->conf.line); |
| 8335 | break; |
| 8336 | } |
| 8337 | } |
| 8338 | } |
| 8339 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8340 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8341 | next_id = 1; |
| 8342 | newsrv = curproxy->srv; |
| 8343 | while (newsrv != NULL) { |
| 8344 | if (!newsrv->puid) { |
| 8345 | /* server ID not set, use automatic numbering with first |
| 8346 | * spare entry starting with next_svid. |
| 8347 | */ |
| 8348 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8349 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8350 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8351 | } |
| 8352 | next_id++; |
| 8353 | newsrv = newsrv->next; |
| 8354 | } |
| 8355 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8356 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8357 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8358 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8359 | /* |
| 8360 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8361 | * tasks to fill the emptied slots when a connection leaves. |
| 8362 | * Also, resolve deferred tracking dependency if needed. |
| 8363 | */ |
| 8364 | newsrv = curproxy->srv; |
| 8365 | while (newsrv != NULL) { |
| 8366 | if (newsrv->minconn > newsrv->maxconn) { |
| 8367 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8368 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8369 | * this will avoid further useless expensive computations. |
| 8370 | */ |
| 8371 | newsrv->maxconn = newsrv->minconn; |
| 8372 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8373 | /* minconn was not specified, so we set it to maxconn */ |
| 8374 | newsrv->minconn = newsrv->maxconn; |
| 8375 | } |
| 8376 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8377 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8378 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 8379 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8380 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8381 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8382 | /* set the check type on the server */ |
| 8383 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8384 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8385 | if (newsrv->trackit) { |
| 8386 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8387 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8388 | char *pname, *sname; |
| 8389 | |
| 8390 | pname = newsrv->trackit; |
| 8391 | sname = strrchr(pname, '/'); |
| 8392 | |
| 8393 | if (sname) |
| 8394 | *sname++ = '\0'; |
| 8395 | else { |
| 8396 | sname = pname; |
| 8397 | pname = NULL; |
| 8398 | } |
| 8399 | |
| 8400 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8401 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8402 | if (!px) { |
| 8403 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8404 | proxy_type_str(curproxy), curproxy->id, |
| 8405 | newsrv->id, pname); |
| 8406 | cfgerr++; |
| 8407 | goto next_srv; |
| 8408 | } |
| 8409 | } else |
| 8410 | px = curproxy; |
| 8411 | |
| 8412 | srv = findserver(px, sname); |
| 8413 | if (!srv) { |
| 8414 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8415 | proxy_type_str(curproxy), curproxy->id, |
| 8416 | newsrv->id, sname); |
| 8417 | cfgerr++; |
| 8418 | goto next_srv; |
| 8419 | } |
| 8420 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8421 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8422 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8423 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8424 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8425 | "tracking as it does not have any check nor agent enabled.\n", |
| 8426 | proxy_type_str(curproxy), curproxy->id, |
| 8427 | newsrv->id, px->id, srv->id); |
| 8428 | cfgerr++; |
| 8429 | goto next_srv; |
| 8430 | } |
| 8431 | |
| 8432 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8433 | |
| 8434 | if (loop) { |
| 8435 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8436 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8437 | proxy_type_str(curproxy), curproxy->id, |
| 8438 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8439 | cfgerr++; |
| 8440 | goto next_srv; |
| 8441 | } |
| 8442 | |
| 8443 | if (curproxy != px && |
| 8444 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8445 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8446 | "tracking: disable-on-404 option inconsistency.\n", |
| 8447 | proxy_type_str(curproxy), curproxy->id, |
| 8448 | newsrv->id, px->id, srv->id); |
| 8449 | cfgerr++; |
| 8450 | goto next_srv; |
| 8451 | } |
| 8452 | |
| 8453 | /* 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] | 8454 | if (srv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 8455 | newsrv->admin |= SRV_ADMF_IMAINT; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 8456 | newsrv->state = SRV_ST_STOPPED; |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 8457 | newsrv->check.health = 0; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8458 | } |
| 8459 | |
| 8460 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8461 | newsrv->tracknext = srv->trackers; |
| 8462 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8463 | |
| 8464 | free(newsrv->trackit); |
| 8465 | newsrv->trackit = NULL; |
| 8466 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8467 | |
| 8468 | /* |
| 8469 | * resolve server's resolvers name and update the resolvers pointer |
| 8470 | * accordingly |
| 8471 | */ |
| 8472 | if (newsrv->resolvers_id) { |
| 8473 | struct dns_resolvers *curr_resolvers; |
| 8474 | int found; |
| 8475 | |
| 8476 | found = 0; |
| 8477 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8478 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8479 | found = 1; |
| 8480 | break; |
| 8481 | } |
| 8482 | } |
| 8483 | |
| 8484 | if (!found) { |
| 8485 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8486 | proxy_type_str(curproxy), curproxy->id, |
| 8487 | newsrv->id, newsrv->resolvers_id); |
| 8488 | cfgerr++; |
| 8489 | } else { |
| 8490 | free(newsrv->resolvers_id); |
| 8491 | newsrv->resolvers_id = NULL; |
| 8492 | if (newsrv->resolution) |
| 8493 | newsrv->resolution->resolvers = curr_resolvers; |
| 8494 | } |
| 8495 | } |
| 8496 | else { |
| 8497 | /* if no resolvers section associated to this server |
| 8498 | * we can clean up the associated resolution structure |
| 8499 | */ |
| 8500 | if (newsrv->resolution) { |
| 8501 | free(newsrv->resolution->hostname_dn); |
| 8502 | newsrv->resolution->hostname_dn = NULL; |
| 8503 | free(newsrv->resolution); |
| 8504 | newsrv->resolution = NULL; |
| 8505 | } |
| 8506 | } |
| 8507 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8508 | next_srv: |
| 8509 | newsrv = newsrv->next; |
| 8510 | } |
| 8511 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8512 | /* We have to initialize the server lookup mechanism depending |
| 8513 | * on what LB algorithm was choosen. |
| 8514 | */ |
| 8515 | |
| 8516 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8517 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8518 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8519 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8520 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8521 | init_server_map(curproxy); |
| 8522 | } else { |
| 8523 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8524 | fwrr_init_server_groups(curproxy); |
| 8525 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8526 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8527 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8528 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8529 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8530 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8531 | fwlc_init_server_tree(curproxy); |
| 8532 | } else { |
| 8533 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8534 | fas_init_server_tree(curproxy); |
| 8535 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8536 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8537 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8538 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8539 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8540 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8541 | chash_init_server_tree(curproxy); |
| 8542 | } else { |
| 8543 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8544 | init_server_map(curproxy); |
| 8545 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8546 | break; |
| 8547 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8548 | |
| 8549 | if (curproxy->options & PR_O_LOGASAP) |
| 8550 | curproxy->to_log &= ~LW_BYTES; |
| 8551 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8552 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8553 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8554 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8555 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8556 | proxy_type_str(curproxy), curproxy->id); |
| 8557 | err_code |= ERR_WARN; |
| 8558 | } |
| 8559 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8560 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8561 | int optnum; |
| 8562 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8563 | if (curproxy->uri_auth) { |
| 8564 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8565 | proxy_type_str(curproxy), curproxy->id); |
| 8566 | err_code |= ERR_WARN; |
| 8567 | curproxy->uri_auth = NULL; |
| 8568 | } |
| 8569 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8570 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8571 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8572 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8573 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8574 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8575 | } |
| 8576 | |
| 8577 | if (curproxy->options & PR_O_ORGTO) { |
| 8578 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8579 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8580 | err_code |= ERR_WARN; |
| 8581 | curproxy->options &= ~PR_O_ORGTO; |
| 8582 | } |
| 8583 | |
| 8584 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8585 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8586 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8587 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8588 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8589 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8590 | err_code |= ERR_WARN; |
| 8591 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8596 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8597 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8598 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8599 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8600 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8601 | err_code |= ERR_WARN; |
| 8602 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8603 | } |
| 8604 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8605 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8606 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8607 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8608 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8609 | 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] | 8610 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8611 | err_code |= ERR_WARN; |
| 8612 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8613 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8614 | } |
| 8615 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8616 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8617 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8618 | */ |
| 8619 | newsrv = curproxy->srv; |
| 8620 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8621 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8622 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8623 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8624 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8625 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8626 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8627 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8628 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8629 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8630 | err_code |= ERR_WARN; |
| 8631 | } |
| 8632 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8633 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8634 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8635 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8636 | err_code |= ERR_WARN; |
| 8637 | } |
| 8638 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8639 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8640 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8641 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8642 | 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] | 8643 | 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] | 8644 | err_code |= ERR_WARN; |
| 8645 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8646 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8647 | newsrv = newsrv->next; |
| 8648 | } |
| 8649 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8650 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8651 | * with no inspect-delay |
| 8652 | */ |
| 8653 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8654 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8655 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8656 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8657 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8658 | if ((trule->action >= ACT_ACTION_TRK_SC0 && trule->action <= ACT_ACTION_TRK_SCMAX) && |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8659 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8660 | break; |
| 8661 | } |
| 8662 | |
| 8663 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8664 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8665 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8666 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8667 | " setting the tcp-request inspect-delay.\n", |
| 8668 | proxy_type_str(curproxy), curproxy->id); |
| 8669 | err_code |= ERR_WARN; |
| 8670 | } |
| 8671 | } |
| 8672 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8673 | /* Check filter configuration, if any */ |
| 8674 | cfgerr += flt_check(curproxy); |
| 8675 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8676 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8677 | if (!curproxy->accept) |
| 8678 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8679 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8680 | if (curproxy->tcp_req.inspect_delay || |
| 8681 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8682 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8683 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8684 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8685 | 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] | 8686 | 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] | 8687 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8688 | |
| 8689 | /* both TCP and HTTP must check switching rules */ |
| 8690 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8691 | |
| 8692 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8693 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8694 | curproxy->fe_req_ana |= AN_FLT_ALL_FE; |
| 8695 | curproxy->fe_rsp_ana |= AN_FLT_ALL_FE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8696 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8697 | curproxy->fe_req_ana |= AN_FLT_HTTP_HDRS; |
| 8698 | curproxy->fe_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8699 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8700 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8701 | } |
| 8702 | |
| 8703 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8704 | if (curproxy->tcp_req.inspect_delay || |
| 8705 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8706 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8707 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8708 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8709 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8710 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8711 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8712 | 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] | 8713 | 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] | 8714 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8715 | |
| 8716 | /* If the backend does requires RDP cookie persistence, we have to |
| 8717 | * enable the corresponding analyser. |
| 8718 | */ |
| 8719 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8720 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8721 | |
| 8722 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8723 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8724 | curproxy->be_req_ana |= AN_FLT_ALL_BE; |
| 8725 | curproxy->be_rsp_ana |= AN_FLT_ALL_BE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8726 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8727 | curproxy->be_req_ana |= AN_FLT_HTTP_HDRS; |
| 8728 | curproxy->be_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8729 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8730 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8731 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8732 | } |
| 8733 | |
| 8734 | /***********************************************************/ |
| 8735 | /* At this point, target names have already been resolved. */ |
| 8736 | /***********************************************************/ |
| 8737 | |
| 8738 | /* Check multi-process mode compatibility */ |
| 8739 | |
| 8740 | if (global.nbproc > 1 && global.stats_fe) { |
| 8741 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8742 | unsigned long mask; |
| 8743 | |
| 8744 | mask = nbits(global.nbproc); |
| 8745 | if (global.stats_fe->bind_proc) |
| 8746 | mask &= global.stats_fe->bind_proc; |
| 8747 | |
| 8748 | if (bind_conf->bind_proc) |
| 8749 | mask &= bind_conf->bind_proc; |
| 8750 | |
| 8751 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8752 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8753 | break; |
| 8754 | } |
| 8755 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8756 | 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"); |
| 8757 | } |
| 8758 | } |
| 8759 | |
| 8760 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8761 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8762 | if (curproxy->bind_proc) |
| 8763 | continue; |
| 8764 | |
| 8765 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8766 | unsigned long mask; |
| 8767 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8768 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8769 | curproxy->bind_proc |= mask; |
| 8770 | } |
| 8771 | |
| 8772 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8773 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | if (global.stats_fe) { |
| 8777 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8778 | unsigned long mask; |
| 8779 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8780 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8781 | global.stats_fe->bind_proc |= mask; |
| 8782 | } |
| 8783 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8784 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8785 | } |
| 8786 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8787 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8788 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8789 | */ |
| 8790 | if (!cfgerr) { |
| 8791 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8792 | if (curproxy->cap & PR_CAP_FE) |
| 8793 | propagate_processes(curproxy, NULL); |
| 8794 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8795 | } |
| 8796 | |
| 8797 | /* Bind each unbound backend to all processes when not specified. */ |
| 8798 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8799 | if (curproxy->bind_proc) |
| 8800 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8801 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8802 | } |
| 8803 | |
| 8804 | /*******************************************************/ |
| 8805 | /* At this step, all proxies have a non-null bind_proc */ |
| 8806 | /*******************************************************/ |
| 8807 | |
| 8808 | /* perform the final checks before creating tasks */ |
| 8809 | |
| 8810 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8811 | struct listener *listener; |
| 8812 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8813 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8814 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8815 | /* Configure SSL for each bind line. |
| 8816 | * Note: if configuration fails at some point, the ->ctx member |
| 8817 | * remains NULL so that listeners can later detach. |
| 8818 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8819 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8820 | int alloc_ctx; |
| 8821 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8822 | if (!bind_conf->is_ssl) { |
| 8823 | if (bind_conf->default_ctx) { |
| 8824 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 8825 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8826 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8827 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8828 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8829 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8830 | 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] | 8831 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8832 | cfgerr++; |
| 8833 | continue; |
| 8834 | } |
| 8835 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 8836 | 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] | 8837 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8838 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 8839 | 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"); |
| 8840 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8841 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8842 | cfgerr++; |
| 8843 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8844 | } |
| 8845 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8846 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8847 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8848 | |
| 8849 | /* initialize CA variables if the certificates generation is enabled */ |
| 8850 | cfgerr += ssl_sock_load_ca(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8851 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8852 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8853 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8854 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8855 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8856 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8857 | int nbproc; |
| 8858 | |
| 8859 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8860 | (listener->bind_conf->bind_proc ? listener->bind_conf->bind_proc : curproxy->bind_proc) & |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8861 | nbits(global.nbproc)); |
| 8862 | |
| 8863 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8864 | nbproc = 1; |
| 8865 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8866 | if (!listener->luid) { |
| 8867 | /* listener ID not set, use automatic numbering with first |
| 8868 | * spare entry starting with next_luid. |
| 8869 | */ |
| 8870 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8871 | listener->conf.id.key = listener->luid = next_id; |
| 8872 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8873 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8874 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8875 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8876 | /* enable separate counters */ |
| 8877 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8878 | listener->counters = calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8879 | if (!listener->name) |
| 8880 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8881 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8882 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8883 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8884 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8885 | if (!listener->maxconn) |
| 8886 | listener->maxconn = curproxy->maxconn; |
| 8887 | if (!listener->backlog) |
| 8888 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8889 | if (!listener->maxaccept) |
| 8890 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8891 | |
| 8892 | /* we want to have an optimal behaviour on single process mode to |
| 8893 | * maximize the work at once, but in multi-process we want to keep |
| 8894 | * some fairness between processes, so we target half of the max |
| 8895 | * number of events to be balanced over all the processes the proxy |
| 8896 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8897 | * used to disable the limit. |
| 8898 | */ |
| 8899 | if (listener->maxaccept > 0) { |
| 8900 | if (nbproc > 1) |
| 8901 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8902 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8903 | } |
| 8904 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8905 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8906 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8907 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8908 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8909 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8910 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8911 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8912 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8913 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8914 | listener->options |= LI_O_TCP_L5_RULES; |
| 8915 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8916 | if (curproxy->mon_mask.s_addr) |
| 8917 | listener->options |= LI_O_CHK_MONNET; |
| 8918 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8919 | /* smart accept mode is automatic in HTTP mode */ |
| 8920 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8921 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8922 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8923 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8924 | } |
| 8925 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8926 | /* Release unused SSL configs */ |
| 8927 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8928 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8929 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8930 | #ifdef USE_OPENSSL |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8931 | ssl_sock_free_ca(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8932 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8933 | free(bind_conf->ca_file); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8934 | free(bind_conf->ca_sign_file); |
| 8935 | free(bind_conf->ca_sign_pass); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8936 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 8937 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8938 | free(bind_conf->crl_file); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 8939 | if(bind_conf->keys_ref) { |
| 8940 | free(bind_conf->keys_ref->filename); |
| 8941 | free(bind_conf->keys_ref->tlskeys); |
William Lallemand | 7bba4cc | 2016-05-20 17:28:07 +0200 | [diff] [blame] | 8942 | LIST_DEL(&bind_conf->keys_ref->list); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 8943 | free(bind_conf->keys_ref); |
| 8944 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8945 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8946 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8947 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8948 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8949 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8950 | int count, maxproc = 0; |
| 8951 | |
| 8952 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8953 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8954 | if (count > maxproc) |
| 8955 | maxproc = count; |
| 8956 | } |
| 8957 | /* backends have 0, frontends have 1 or more */ |
| 8958 | if (maxproc != 1) |
| 8959 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 8960 | " limited to process assigned to the current request.\n", |
| 8961 | curproxy->id); |
| 8962 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8963 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 8964 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8965 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8966 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8967 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8968 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 8969 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8970 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8971 | } |
| 8972 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8973 | |
| 8974 | /* create the task associated with the proxy */ |
| 8975 | curproxy->task = task_new(); |
| 8976 | if (curproxy->task) { |
| 8977 | curproxy->task->context = curproxy; |
| 8978 | curproxy->task->process = manage_proxy; |
| 8979 | /* no need to queue, it will be done automatically if some |
| 8980 | * listener gets limited. |
| 8981 | */ |
| 8982 | curproxy->task->expire = TICK_ETERNITY; |
| 8983 | } else { |
| 8984 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8985 | curproxy->id); |
| 8986 | cfgerr++; |
| 8987 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8988 | } |
| 8989 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8990 | /* automatically compute fullconn if not set. We must not do it in the |
| 8991 | * loop above because cross-references are not yet fully resolved. |
| 8992 | */ |
| 8993 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8994 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 8995 | * the possible incoming frontend's maxconns. |
| 8996 | */ |
| 8997 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 8998 | struct proxy *fe; |
| 8999 | int total = 0; |
| 9000 | |
| 9001 | /* sum up the number of maxconns of frontends which |
| 9002 | * reference this backend at least once or which are |
| 9003 | * the same one ('listen'). |
| 9004 | */ |
| 9005 | for (fe = proxy; fe; fe = fe->next) { |
| 9006 | struct switching_rule *rule; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9007 | int found = 0; |
| 9008 | |
| 9009 | if (!(fe->cap & PR_CAP_FE)) |
| 9010 | continue; |
| 9011 | |
| 9012 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 9013 | found = 1; |
| 9014 | |
| 9015 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 9016 | found = 1; |
| 9017 | |
| 9018 | /* check if a "use_backend" rule matches */ |
| 9019 | if (!found) { |
| 9020 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9021 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9022 | found = 1; |
| 9023 | break; |
| 9024 | } |
| 9025 | } |
| 9026 | } |
| 9027 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9028 | /* now we've checked all possible ways to reference a backend |
| 9029 | * from a frontend. |
| 9030 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9031 | if (!found) |
| 9032 | continue; |
| 9033 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9034 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9035 | /* we have the sum of the maxconns in <total>. We only |
| 9036 | * keep 10% of that sum to set the default fullconn, with |
| 9037 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9038 | */ |
| 9039 | curproxy->fullconn = (total + 9) / 10; |
| 9040 | if (!curproxy->fullconn) |
| 9041 | curproxy->fullconn = 1; |
| 9042 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9043 | } |
| 9044 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9045 | /* |
| 9046 | * Recount currently required checks. |
| 9047 | */ |
| 9048 | |
| 9049 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 9050 | int optnum; |
| 9051 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9052 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9053 | if (curproxy->options & cfg_opts[optnum].val) |
| 9054 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9055 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9056 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9057 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9058 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9059 | } |
| 9060 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9061 | /* compute the required process bindings for the peers */ |
| 9062 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 9063 | if (curproxy->table.peers.p) |
| 9064 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9065 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9066 | if (peers) { |
| 9067 | struct peers *curpeers = peers, **last; |
| 9068 | struct peer *p, *pb; |
| 9069 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9070 | /* Remove all peers sections which don't have a valid listener, |
| 9071 | * which are not used by any table, or which are bound to more |
| 9072 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9073 | */ |
| 9074 | last = &peers; |
| 9075 | while (*last) { |
| 9076 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9077 | |
| 9078 | if (curpeers->state == PR_STSTOPPED) { |
| 9079 | /* the "disabled" keyword was present */ |
| 9080 | if (curpeers->peers_fe) |
| 9081 | stop_proxy(curpeers->peers_fe); |
| 9082 | curpeers->peers_fe = NULL; |
| 9083 | } |
| 9084 | else if (!curpeers->peers_fe) { |
| 9085 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9086 | curpeers->id, localpeer); |
| 9087 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9088 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9089 | /* either it's totally stopped or too much used */ |
| 9090 | if (curpeers->peers_fe->bind_proc) { |
| 9091 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 9092 | "running in different processes (%d different ones). " |
| 9093 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9094 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9095 | cfgerr++; |
| 9096 | } |
| 9097 | stop_proxy(curpeers->peers_fe); |
| 9098 | curpeers->peers_fe = NULL; |
| 9099 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9100 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9101 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9102 | last = &curpeers->next; |
| 9103 | continue; |
| 9104 | } |
| 9105 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9106 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9107 | p = curpeers->remote; |
| 9108 | while (p) { |
| 9109 | pb = p->next; |
| 9110 | free(p->id); |
| 9111 | free(p); |
| 9112 | p = pb; |
| 9113 | } |
| 9114 | |
| 9115 | /* Destroy and unlink this curpeers section. |
| 9116 | * Note: curpeers is backed up into *last. |
| 9117 | */ |
| 9118 | free(curpeers->id); |
| 9119 | curpeers = curpeers->next; |
| 9120 | free(*last); |
| 9121 | *last = curpeers; |
| 9122 | } |
| 9123 | } |
| 9124 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9125 | /* initialize stick-tables on backend capable proxies. This must not |
| 9126 | * be done earlier because the data size may be discovered while parsing |
| 9127 | * other proxies. |
| 9128 | */ |
| 9129 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9130 | if (curproxy->state == PR_STSTOPPED) |
| 9131 | continue; |
| 9132 | |
| 9133 | if (!stktable_init(&curproxy->table)) { |
| 9134 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9135 | cfgerr++; |
| 9136 | } |
| 9137 | } |
| 9138 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9139 | if (mailers) { |
| 9140 | struct mailers *curmailers = mailers, **last; |
| 9141 | struct mailer *m, *mb; |
| 9142 | |
| 9143 | /* Remove all mailers sections which don't have a valid listener. |
| 9144 | * This can happen when a mailers section is never referenced. |
| 9145 | */ |
| 9146 | last = &mailers; |
| 9147 | while (*last) { |
| 9148 | curmailers = *last; |
| 9149 | if (curmailers->users) { |
| 9150 | last = &curmailers->next; |
| 9151 | continue; |
| 9152 | } |
| 9153 | |
| 9154 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9155 | curmailers->id); |
| 9156 | |
| 9157 | m = curmailers->mailer_list; |
| 9158 | while (m) { |
| 9159 | mb = m->next; |
| 9160 | free(m->id); |
| 9161 | free(m); |
| 9162 | m = mb; |
| 9163 | } |
| 9164 | |
| 9165 | /* Destroy and unlink this curmailers section. |
| 9166 | * Note: curmailers is backed up into *last. |
| 9167 | */ |
| 9168 | free(curmailers->id); |
| 9169 | curmailers = curmailers->next; |
| 9170 | free(*last); |
| 9171 | *last = curmailers; |
| 9172 | } |
| 9173 | } |
| 9174 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9175 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9176 | * a server-state file locally defined and none has been provided */ |
| 9177 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9178 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9179 | curproxy->server_state_file_name == NULL) |
| 9180 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9181 | } |
| 9182 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9183 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9184 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9185 | MEM_F_SHARED); |
| 9186 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9187 | if (cfgerr > 0) |
| 9188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9189 | out: |
| 9190 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9191 | } |
| 9192 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9193 | /* |
| 9194 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9195 | * parsing sessions. |
| 9196 | */ |
| 9197 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9198 | { |
| 9199 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9200 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9201 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9202 | /* |
| 9203 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9204 | */ |
| 9205 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9206 | { |
| 9207 | LIST_DEL(&kwl->list); |
| 9208 | LIST_INIT(&kwl->list); |
| 9209 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9210 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9211 | /* this function register new section in the haproxy configuration file. |
| 9212 | * <section_name> is the name of this new section and <section_parser> |
| 9213 | * is the called parser. If two section declaration have the same name, |
| 9214 | * only the first declared is used. |
| 9215 | */ |
| 9216 | int cfg_register_section(char *section_name, |
| 9217 | int (*section_parser)(const char *, int, char **, int)) |
| 9218 | { |
| 9219 | struct cfg_section *cs; |
| 9220 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9221 | list_for_each_entry(cs, §ions, list) { |
| 9222 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9223 | Alert("register section '%s': already registered.\n", section_name); |
| 9224 | return 0; |
| 9225 | } |
| 9226 | } |
| 9227 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9228 | cs = calloc(1, sizeof(*cs)); |
| 9229 | if (!cs) { |
| 9230 | Alert("register section '%s': out of memory.\n", section_name); |
| 9231 | return 0; |
| 9232 | } |
| 9233 | |
| 9234 | cs->section_name = section_name; |
| 9235 | cs->section_parser = section_parser; |
| 9236 | |
| 9237 | LIST_ADDQ(§ions, &cs->list); |
| 9238 | |
| 9239 | return 1; |
| 9240 | } |
| 9241 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9242 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9243 | * free all config section entries |
| 9244 | */ |
| 9245 | void cfg_unregister_sections(void) |
| 9246 | { |
| 9247 | struct cfg_section *cs, *ics; |
| 9248 | |
| 9249 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9250 | LIST_DEL(&cs->list); |
| 9251 | free(cs); |
| 9252 | } |
| 9253 | } |
| 9254 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9255 | __attribute__((constructor)) |
| 9256 | static void cfgparse_init(void) |
| 9257 | { |
| 9258 | /* Register internal sections */ |
| 9259 | cfg_register_section("listen", cfg_parse_listen); |
| 9260 | cfg_register_section("frontend", cfg_parse_listen); |
| 9261 | cfg_register_section("backend", cfg_parse_listen); |
| 9262 | cfg_register_section("defaults", cfg_parse_listen); |
| 9263 | cfg_register_section("global", cfg_parse_global); |
| 9264 | cfg_register_section("userlist", cfg_parse_users); |
| 9265 | cfg_register_section("peers", cfg_parse_peers); |
| 9266 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9267 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9268 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9269 | } |
| 9270 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9271 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9272 | * Local variables: |
| 9273 | * c-indent-level: 8 |
| 9274 | * c-basic-offset: 8 |
| 9275 | * End: |
| 9276 | */ |