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; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2366 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2367 | curr_resolvers->hold.nx = 30000; |
| 2368 | curr_resolvers->hold.other = 30000; |
| 2369 | curr_resolvers->hold.refused = 30000; |
| 2370 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2371 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2372 | curr_resolvers->hold.valid = 10000; |
| 2373 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2374 | curr_resolvers->resolve_retries = 3; |
| 2375 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2376 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2377 | } |
| 2378 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2379 | struct sockaddr_storage *sk; |
| 2380 | int port1, port2; |
| 2381 | struct protocol *proto; |
| 2382 | |
| 2383 | if (!*args[2]) { |
| 2384 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2385 | file, linenum, args[0]); |
| 2386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2387 | goto out; |
| 2388 | } |
| 2389 | |
| 2390 | err = invalid_char(args[1]); |
| 2391 | if (err) { |
| 2392 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2393 | file, linenum, *err, args[1]); |
| 2394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2395 | goto out; |
| 2396 | } |
| 2397 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2398 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2399 | /* Error if two resolvers owns the same name */ |
| 2400 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2401 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2402 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2404 | } |
| 2405 | } |
| 2406 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2407 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2408 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2409 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2410 | goto out; |
| 2411 | } |
| 2412 | |
| 2413 | /* the nameservers are linked backward first */ |
| 2414 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2415 | curr_resolvers->count_nameservers++; |
| 2416 | newnameserver->resolvers = curr_resolvers; |
| 2417 | newnameserver->conf.file = strdup(file); |
| 2418 | newnameserver->conf.line = linenum; |
| 2419 | newnameserver->id = strdup(args[1]); |
| 2420 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2421 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2422 | if (!sk) { |
| 2423 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2425 | goto out; |
| 2426 | } |
| 2427 | |
| 2428 | proto = protocol_by_family(sk->ss_family); |
| 2429 | if (!proto || !proto->connect) { |
| 2430 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2431 | file, linenum, args[0], args[1]); |
| 2432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2433 | goto out; |
| 2434 | } |
| 2435 | |
| 2436 | if (port1 != port2) { |
| 2437 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2438 | file, linenum, args[0], args[1], args[2]); |
| 2439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2440 | goto out; |
| 2441 | } |
| 2442 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2443 | if (!port1 && !port2) { |
| 2444 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2445 | file, linenum, args[0], args[1]); |
| 2446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2447 | goto out; |
| 2448 | } |
| 2449 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2450 | newnameserver->addr = *sk; |
| 2451 | } |
| 2452 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2453 | const char *res; |
| 2454 | unsigned int time; |
| 2455 | |
| 2456 | if (!*args[2]) { |
| 2457 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2458 | file, linenum, args[0]); |
| 2459 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2461 | goto out; |
| 2462 | } |
| 2463 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2464 | if (res) { |
| 2465 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2466 | file, linenum, *res, args[0]); |
| 2467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2468 | goto out; |
| 2469 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2470 | if (strcmp(args[1], "nx") == 0) |
| 2471 | curr_resolvers->hold.nx = time; |
| 2472 | else if (strcmp(args[1], "other") == 0) |
| 2473 | curr_resolvers->hold.other = time; |
| 2474 | else if (strcmp(args[1], "refused") == 0) |
| 2475 | curr_resolvers->hold.refused = time; |
| 2476 | else if (strcmp(args[1], "timeout") == 0) |
| 2477 | curr_resolvers->hold.timeout = time; |
| 2478 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2479 | curr_resolvers->hold.valid = time; |
| 2480 | else { |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2481 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', or 'other'.\n", |
| 2482 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2484 | goto out; |
| 2485 | } |
| 2486 | |
| 2487 | } |
| 2488 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2489 | if (!*args[1]) { |
| 2490 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2491 | file, linenum, args[0]); |
| 2492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2493 | goto out; |
| 2494 | } |
| 2495 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2496 | } |
| 2497 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2498 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2499 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2500 | file, linenum, args[0]); |
| 2501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2502 | goto out; |
| 2503 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2504 | else if (strcmp(args[1], "retry") == 0) { |
| 2505 | const char *res; |
| 2506 | unsigned int timeout_retry; |
| 2507 | |
| 2508 | if (!*args[2]) { |
| 2509 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2510 | file, linenum, args[0], args[1]); |
| 2511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2512 | goto out; |
| 2513 | } |
| 2514 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2515 | if (res) { |
| 2516 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2517 | file, linenum, *res, args[0], args[1]); |
| 2518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2519 | goto out; |
| 2520 | } |
| 2521 | curr_resolvers->timeout.retry = timeout_retry; |
| 2522 | } |
| 2523 | else { |
| 2524 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2525 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2527 | goto out; |
| 2528 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2529 | } /* neither "nameserver" nor "resolvers" */ |
| 2530 | else if (*args[0] != 0) { |
| 2531 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2533 | goto out; |
| 2534 | } |
| 2535 | |
| 2536 | out: |
| 2537 | free(errmsg); |
| 2538 | return err_code; |
| 2539 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2540 | |
| 2541 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2542 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2543 | * Returns the error code, 0 if OK, or any combination of : |
| 2544 | * - ERR_ABORT: must abort ASAP |
| 2545 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2546 | * - ERR_WARN: a warning has been emitted |
| 2547 | * - ERR_ALERT: an alert has been emitted |
| 2548 | * Only the two first ones can stop processing, the two others are just |
| 2549 | * indicators. |
| 2550 | */ |
| 2551 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2552 | { |
| 2553 | static struct mailers *curmailers = NULL; |
| 2554 | struct mailer *newmailer = NULL; |
| 2555 | const char *err; |
| 2556 | int err_code = 0; |
| 2557 | char *errmsg = NULL; |
| 2558 | |
| 2559 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2560 | if (!*args[1]) { |
| 2561 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2562 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2563 | goto out; |
| 2564 | } |
| 2565 | |
| 2566 | err = invalid_char(args[1]); |
| 2567 | if (err) { |
| 2568 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2569 | file, linenum, *err, args[0], args[1]); |
| 2570 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2571 | goto out; |
| 2572 | } |
| 2573 | |
| 2574 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2575 | /* |
| 2576 | * If there are two proxies with the same name only following |
| 2577 | * combinations are allowed: |
| 2578 | */ |
| 2579 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2580 | 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] | 2581 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2582 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2586 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2587 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2588 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2589 | goto out; |
| 2590 | } |
| 2591 | |
| 2592 | curmailers->next = mailers; |
| 2593 | mailers = curmailers; |
| 2594 | curmailers->conf.file = strdup(file); |
| 2595 | curmailers->conf.line = linenum; |
| 2596 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2597 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2598 | * But need enough time so that timeouts don't occur |
| 2599 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2600 | } |
| 2601 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2602 | struct sockaddr_storage *sk; |
| 2603 | int port1, port2; |
| 2604 | struct protocol *proto; |
| 2605 | |
| 2606 | if (!*args[2]) { |
| 2607 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2608 | file, linenum, args[0]); |
| 2609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2610 | goto out; |
| 2611 | } |
| 2612 | |
| 2613 | err = invalid_char(args[1]); |
| 2614 | if (err) { |
| 2615 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2616 | file, linenum, *err, args[1]); |
| 2617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2618 | goto out; |
| 2619 | } |
| 2620 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2621 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2622 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2623 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2624 | goto out; |
| 2625 | } |
| 2626 | |
| 2627 | /* the mailers are linked backwards first */ |
| 2628 | curmailers->count++; |
| 2629 | newmailer->next = curmailers->mailer_list; |
| 2630 | curmailers->mailer_list = newmailer; |
| 2631 | newmailer->mailers = curmailers; |
| 2632 | newmailer->conf.file = strdup(file); |
| 2633 | newmailer->conf.line = linenum; |
| 2634 | |
| 2635 | newmailer->id = strdup(args[1]); |
| 2636 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2637 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2638 | if (!sk) { |
| 2639 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2641 | goto out; |
| 2642 | } |
| 2643 | |
| 2644 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2645 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2646 | 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] | 2647 | file, linenum, args[0], args[1]); |
| 2648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2649 | goto out; |
| 2650 | } |
| 2651 | |
| 2652 | if (port1 != port2) { |
| 2653 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2654 | file, linenum, args[0], args[1], args[2]); |
| 2655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2656 | goto out; |
| 2657 | } |
| 2658 | |
| 2659 | if (!port1) { |
| 2660 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2661 | file, linenum, args[0], args[1], args[2]); |
| 2662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2663 | goto out; |
| 2664 | } |
| 2665 | |
| 2666 | newmailer->addr = *sk; |
| 2667 | newmailer->proto = proto; |
| 2668 | newmailer->xprt = &raw_sock; |
| 2669 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2670 | } |
| 2671 | else if (strcmp(args[0], "timeout") == 0) { |
| 2672 | if (!*args[1]) { |
| 2673 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2674 | file, linenum, args[0]); |
| 2675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2676 | goto out; |
| 2677 | } |
| 2678 | else if (strcmp(args[1], "mail") == 0) { |
| 2679 | const char *res; |
| 2680 | unsigned int timeout_mail; |
| 2681 | if (!*args[2]) { |
| 2682 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2683 | file, linenum, args[0], args[1]); |
| 2684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2685 | goto out; |
| 2686 | } |
| 2687 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2688 | if (res) { |
| 2689 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2690 | file, linenum, *res, args[0]); |
| 2691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2692 | goto out; |
| 2693 | } |
| 2694 | if (timeout_mail <= 0) { |
| 2695 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2697 | goto out; |
| 2698 | } |
| 2699 | curmailers->timeout.mail = timeout_mail; |
| 2700 | } else { |
| 2701 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2702 | file, linenum, args[0], args[1]); |
| 2703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2704 | goto out; |
| 2705 | } |
| 2706 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2707 | else if (*args[0] != 0) { |
| 2708 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2710 | goto out; |
| 2711 | } |
| 2712 | |
| 2713 | out: |
| 2714 | free(errmsg); |
| 2715 | return err_code; |
| 2716 | } |
| 2717 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2718 | static void free_email_alert(struct proxy *p) |
| 2719 | { |
| 2720 | free(p->email_alert.mailers.name); |
| 2721 | p->email_alert.mailers.name = NULL; |
| 2722 | free(p->email_alert.from); |
| 2723 | p->email_alert.from = NULL; |
| 2724 | free(p->email_alert.to); |
| 2725 | p->email_alert.to = NULL; |
| 2726 | free(p->email_alert.myhostname); |
| 2727 | p->email_alert.myhostname = NULL; |
| 2728 | } |
| 2729 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2730 | 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] | 2731 | { |
| 2732 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2733 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2734 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2735 | int rc; |
| 2736 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2737 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2738 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2739 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2740 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2741 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2742 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2743 | if (!strcmp(args[0], "listen")) |
| 2744 | rc = PR_CAP_LISTEN; |
| 2745 | else if (!strcmp(args[0], "frontend")) |
| 2746 | rc = PR_CAP_FE | PR_CAP_RS; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2747 | else if (!strcmp(args[0], "backend")) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2748 | rc = PR_CAP_BE | PR_CAP_RS; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2749 | else |
| 2750 | rc = PR_CAP_NONE; |
| 2751 | |
| 2752 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2753 | if (!*args[1]) { |
| 2754 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2755 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2756 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2757 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2758 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2759 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2760 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2761 | err = invalid_char(args[1]); |
| 2762 | if (err) { |
| 2763 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2764 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2765 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2766 | } |
| 2767 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2768 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2769 | if (curproxy) { |
| 2770 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2771 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2772 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2773 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2774 | } |
| 2775 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2776 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2777 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2778 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2779 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2780 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2781 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2782 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2783 | curproxy->next = proxy; |
| 2784 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2785 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2786 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2787 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2788 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2789 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2790 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2791 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2792 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2793 | if (curproxy->cap & PR_CAP_FE) |
| 2794 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2795 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2799 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2800 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2801 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2802 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2803 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2804 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2805 | curproxy->no_options = defproxy.no_options; |
| 2806 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2807 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2808 | curproxy->except_net = defproxy.except_net; |
| 2809 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2810 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2811 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2812 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2813 | if (defproxy.fwdfor_hdr_len) { |
| 2814 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2815 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2816 | } |
| 2817 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2818 | if (defproxy.orgto_hdr_len) { |
| 2819 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2820 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2821 | } |
| 2822 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2823 | if (defproxy.server_id_hdr_len) { |
| 2824 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2825 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2826 | } |
| 2827 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2828 | if (curproxy->cap & PR_CAP_FE) { |
| 2829 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2830 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2831 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2832 | |
| 2833 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2834 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2835 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2836 | |
| 2837 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2838 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2839 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2840 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2841 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2842 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2843 | curproxy->fullconn = defproxy.fullconn; |
| 2844 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2845 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2846 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2847 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2848 | if (defproxy.check_req) { |
| 2849 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2850 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2851 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2852 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2853 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2854 | if (defproxy.expect_str) { |
| 2855 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2856 | if (defproxy.expect_regex) { |
| 2857 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2858 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2859 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2863 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2864 | if (defproxy.cookie_name) |
| 2865 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2866 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2867 | if (defproxy.cookie_domain) |
| 2868 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2869 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2870 | if (defproxy.cookie_maxidle) |
| 2871 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2872 | |
| 2873 | if (defproxy.cookie_maxlife) |
| 2874 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2875 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2876 | if (defproxy.rdp_cookie_name) |
| 2877 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2878 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2879 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2880 | if (defproxy.url_param_name) |
| 2881 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2882 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2883 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2884 | if (defproxy.hh_name) |
| 2885 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2886 | curproxy->hh_len = defproxy.hh_len; |
| 2887 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2888 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2889 | if (defproxy.conn_src.iface_name) |
| 2890 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2891 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2892 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2893 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2894 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2895 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2896 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2897 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2898 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2899 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2900 | if (defproxy.capture_name) |
| 2901 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2902 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2903 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2904 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2905 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2906 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2907 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2908 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2909 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2910 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2911 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2912 | curproxy->mon_net = defproxy.mon_net; |
| 2913 | curproxy->mon_mask = defproxy.mon_mask; |
| 2914 | if (defproxy.monitor_uri) |
| 2915 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2916 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2917 | if (defproxy.defbe.name) |
| 2918 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2919 | |
| 2920 | /* 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] | 2921 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2922 | if (curproxy->conf.logformat_string && |
| 2923 | curproxy->conf.logformat_string != default_http_log_format && |
| 2924 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2925 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2926 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2927 | |
| 2928 | if (defproxy.conf.lfs_file) { |
| 2929 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2930 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2931 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2932 | |
| 2933 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2934 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2935 | if (curproxy->conf.logformat_sd_string && |
| 2936 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2937 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2938 | |
| 2939 | if (defproxy.conf.lfsd_file) { |
| 2940 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2941 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2942 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2946 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2947 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2948 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2949 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2950 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2951 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2952 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2953 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2954 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2955 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2956 | } |
| 2957 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2958 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2959 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2960 | |
| 2961 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2962 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2963 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2964 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2965 | LIST_INIT(&node->list); |
| 2966 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2967 | } |
| 2968 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2969 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2970 | if (curproxy->conf.uniqueid_format_string) |
| 2971 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2972 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2973 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2974 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2975 | if (defproxy.conf.uif_file) { |
| 2976 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2977 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2978 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2979 | |
| 2980 | /* copy default header unique id */ |
| 2981 | if (defproxy.header_unique_id) |
| 2982 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2983 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2984 | /* default compression options */ |
| 2985 | if (defproxy.comp != NULL) { |
| 2986 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2987 | curproxy->comp->algos = defproxy.comp->algos; |
| 2988 | curproxy->comp->types = defproxy.comp->types; |
| 2989 | } |
| 2990 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2991 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2992 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2993 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2994 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2995 | if (defproxy.check_path) |
| 2996 | curproxy->check_path = strdup(defproxy.check_path); |
| 2997 | if (defproxy.check_command) |
| 2998 | curproxy->check_command = strdup(defproxy.check_command); |
| 2999 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3000 | if (defproxy.email_alert.mailers.name) |
| 3001 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3002 | if (defproxy.email_alert.from) |
| 3003 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3004 | if (defproxy.email_alert.to) |
| 3005 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3006 | if (defproxy.email_alert.myhostname) |
| 3007 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3008 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3009 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3010 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3011 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3012 | } |
| 3013 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3014 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3015 | /* FIXME-20070101: we should do this too at the end of the |
| 3016 | * config parsing to free all default values. |
| 3017 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3018 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3019 | err_code |= ERR_ABORT; |
| 3020 | goto out; |
| 3021 | } |
| 3022 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3023 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3024 | free(defproxy.check_command); |
| 3025 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3026 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3027 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3028 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3029 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3030 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3031 | free(defproxy.capture_name); |
| 3032 | free(defproxy.monitor_uri); |
| 3033 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3034 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3035 | free(defproxy.fwdfor_hdr_name); |
| 3036 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3037 | free(defproxy.orgto_hdr_name); |
| 3038 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3039 | free(defproxy.server_id_hdr_name); |
| 3040 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3041 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3042 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3043 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3044 | free(defproxy.expect_regex); |
| 3045 | defproxy.expect_regex = NULL; |
| 3046 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3047 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3048 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3049 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3050 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3051 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3052 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3053 | free(defproxy.conf.uniqueid_format_string); |
| 3054 | free(defproxy.conf.lfs_file); |
| 3055 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3056 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3057 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3058 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3059 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3060 | free(defproxy.conf.logformat_sd_string); |
| 3061 | free(defproxy.conf.lfsd_file); |
| 3062 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3063 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3064 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3065 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3066 | /* we cannot free uri_auth because it might already be used */ |
| 3067 | init_default_instance(); |
| 3068 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3069 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3070 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3071 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3072 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3073 | } |
| 3074 | else if (curproxy == NULL) { |
| 3075 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3077 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3078 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3079 | |
| 3080 | /* update the current file and line being parsed */ |
| 3081 | curproxy->conf.args.file = curproxy->conf.file; |
| 3082 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3083 | |
| 3084 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3085 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 3086 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3087 | if (err_code & ERR_FATAL) |
| 3088 | goto out; |
| 3089 | } |
| 3090 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3091 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3092 | int cur_arg; |
| 3093 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3094 | if (curproxy == &defproxy) { |
| 3095 | 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] | 3096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3097 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3098 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3099 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3100 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3101 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3102 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 3103 | 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] | 3104 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3106 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3107 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3108 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 3109 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 3110 | |
| 3111 | /* use default settings for unix sockets */ |
| 3112 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3113 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3114 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3115 | |
| 3116 | /* NOTE: the following line might create several listeners if there |
| 3117 | * are comma-separated IPs or port ranges. So all further processing |
| 3118 | * will have to be applied to all listeners created after last_listen. |
| 3119 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3120 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3121 | if (errmsg && *errmsg) { |
| 3122 | indent_msg(&errmsg, 2); |
| 3123 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 3124 | } |
| 3125 | else |
| 3126 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3127 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3129 | goto out; |
| 3130 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3131 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3132 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3133 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3134 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3135 | } |
| 3136 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3137 | cur_arg = 2; |
| 3138 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3139 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3140 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3141 | char *err; |
| 3142 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3143 | kw = bind_find_kw(args[cur_arg]); |
| 3144 | if (kw) { |
| 3145 | char *err = NULL; |
| 3146 | int code; |
| 3147 | |
| 3148 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3149 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3150 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3151 | cur_arg += 1 + kw->skip ; |
| 3152 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3153 | goto out; |
| 3154 | } |
| 3155 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3156 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3157 | err_code |= code; |
| 3158 | |
| 3159 | if (code) { |
| 3160 | if (err && *err) { |
| 3161 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3162 | 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] | 3163 | } |
| 3164 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3165 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3166 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3167 | if (code & ERR_FATAL) { |
| 3168 | free(err); |
| 3169 | cur_arg += 1 + kw->skip; |
| 3170 | goto out; |
| 3171 | } |
| 3172 | } |
| 3173 | free(err); |
| 3174 | cur_arg += 1 + kw->skip; |
| 3175 | continue; |
| 3176 | } |
| 3177 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3178 | err = NULL; |
| 3179 | if (!bind_dumped) { |
| 3180 | bind_dump_kws(&err); |
| 3181 | indent_msg(&err, 4); |
| 3182 | bind_dumped = 1; |
| 3183 | } |
| 3184 | |
| 3185 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3186 | file, linenum, args[0], args[1], args[cur_arg], |
| 3187 | err ? " Registered keywords :" : "", err ? err : ""); |
| 3188 | free(err); |
| 3189 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3191 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3192 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3193 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3194 | } |
| 3195 | 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] | 3196 | 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] | 3197 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3198 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3201 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3202 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3203 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3204 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3205 | /* flush useless bits */ |
| 3206 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3208 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3209 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3210 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3211 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3212 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3213 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3214 | goto out; |
| 3215 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3216 | if (!*args[1]) { |
| 3217 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3218 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3220 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3221 | } |
| 3222 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3223 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3224 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3225 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3226 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3227 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3228 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3229 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3230 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3231 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3232 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3233 | goto out; |
| 3234 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3235 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3236 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3237 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3238 | else { |
| 3239 | 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] | 3240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3241 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3242 | } |
| 3243 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3244 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3245 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3246 | |
| 3247 | if (curproxy == &defproxy) { |
| 3248 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3249 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3251 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3252 | } |
| 3253 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3254 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3255 | goto out; |
| 3256 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3257 | if (!*args[1]) { |
| 3258 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3259 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3261 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3265 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3266 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3267 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3268 | if (curproxy->uuid <= 0) { |
| 3269 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3270 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3272 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3273 | } |
| 3274 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3275 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3276 | if (node) { |
| 3277 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3278 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3279 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3280 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
| 3283 | } |
| 3284 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3285 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3286 | else if (!strcmp(args[0], "description")) { |
| 3287 | int i, len=0; |
| 3288 | char *d; |
| 3289 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3290 | if (curproxy == &defproxy) { |
| 3291 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3292 | file, linenum, args[0]); |
| 3293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3294 | goto out; |
| 3295 | } |
| 3296 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3297 | if (!*args[1]) { |
| 3298 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3299 | file, linenum, args[0]); |
| 3300 | return -1; |
| 3301 | } |
| 3302 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3303 | for (i = 1; *args[i]; i++) |
| 3304 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3305 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3306 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3307 | curproxy->desc = d; |
| 3308 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3309 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3310 | for (i = 2; *args[i]; i++) |
| 3311 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3312 | |
| 3313 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3314 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3315 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3316 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3317 | curproxy->state = PR_STSTOPPED; |
| 3318 | } |
| 3319 | 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] | 3320 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3321 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3322 | curproxy->state = PR_STNEW; |
| 3323 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3324 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3325 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3326 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3327 | |
| 3328 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3329 | unsigned int low, high; |
| 3330 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3331 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3332 | set = 0; |
| 3333 | break; |
| 3334 | } |
| 3335 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3336 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3337 | } |
| 3338 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3339 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3340 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3341 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3342 | char *dash = strchr(args[cur_arg], '-'); |
| 3343 | |
| 3344 | low = high = str2uic(args[cur_arg]); |
| 3345 | if (dash) |
| 3346 | high = str2uic(dash + 1); |
| 3347 | |
| 3348 | if (high < low) { |
| 3349 | unsigned int swap = low; |
| 3350 | low = high; |
| 3351 | high = swap; |
| 3352 | } |
| 3353 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3354 | if (low < 1 || high > LONGBITS) { |
| 3355 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3356 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3358 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3359 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3360 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3361 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3362 | } |
| 3363 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3364 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3365 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3367 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3368 | } |
| 3369 | cur_arg++; |
| 3370 | } |
| 3371 | curproxy->bind_proc = set; |
| 3372 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3373 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3374 | if (curproxy == &defproxy) { |
| 3375 | 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] | 3376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3377 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3378 | } |
| 3379 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3380 | err = invalid_char(args[1]); |
| 3381 | if (err) { |
| 3382 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3383 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3384 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3385 | } |
| 3386 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3387 | 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] | 3388 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3389 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3391 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3392 | } |
| 3393 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3394 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3395 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3396 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3397 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3398 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3399 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3400 | if (*(args[1]) == 0) { |
| 3401 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3402 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3405 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3406 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3407 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3408 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3409 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3410 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3411 | curproxy->cookie_name = strdup(args[1]); |
| 3412 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3413 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3414 | cur_arg = 2; |
| 3415 | while (*(args[cur_arg])) { |
| 3416 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3417 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3418 | } |
| 3419 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3420 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3421 | } |
| 3422 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3423 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3424 | } |
| 3425 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3426 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3427 | } |
| 3428 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3429 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3430 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3431 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3432 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3433 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3435 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3436 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3437 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3438 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3439 | } |
| 3440 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3441 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3442 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3443 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3444 | if (!*args[cur_arg + 1]) { |
| 3445 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3446 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3448 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3449 | } |
| 3450 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3451 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3452 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3453 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3454 | " dots nor does not start with a dot." |
| 3455 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3456 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3457 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3461 | if (err) { |
| 3462 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3463 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3465 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3466 | } |
| 3467 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3468 | if (!curproxy->cookie_domain) { |
| 3469 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3470 | } else { |
| 3471 | /* one domain was already specified, add another one by |
| 3472 | * building the string which will be returned along with |
| 3473 | * the cookie. |
| 3474 | */ |
| 3475 | char *new_ptr; |
| 3476 | int new_len = strlen(curproxy->cookie_domain) + |
| 3477 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3478 | new_ptr = malloc(new_len); |
| 3479 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3480 | free(curproxy->cookie_domain); |
| 3481 | curproxy->cookie_domain = new_ptr; |
| 3482 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3483 | cur_arg++; |
| 3484 | } |
| 3485 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3486 | unsigned int maxidle; |
| 3487 | const char *res; |
| 3488 | |
| 3489 | if (!*args[cur_arg + 1]) { |
| 3490 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3491 | file, linenum, args[cur_arg]); |
| 3492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3493 | goto out; |
| 3494 | } |
| 3495 | |
| 3496 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3497 | if (res) { |
| 3498 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3499 | file, linenum, *res, args[cur_arg]); |
| 3500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3501 | goto out; |
| 3502 | } |
| 3503 | curproxy->cookie_maxidle = maxidle; |
| 3504 | cur_arg++; |
| 3505 | } |
| 3506 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3507 | unsigned int maxlife; |
| 3508 | const char *res; |
| 3509 | |
| 3510 | if (!*args[cur_arg + 1]) { |
| 3511 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3512 | file, linenum, args[cur_arg]); |
| 3513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3514 | goto out; |
| 3515 | } |
| 3516 | |
| 3517 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3518 | if (res) { |
| 3519 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3520 | file, linenum, *res, args[cur_arg]); |
| 3521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3522 | goto out; |
| 3523 | } |
| 3524 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3525 | cur_arg++; |
| 3526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3527 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3528 | 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] | 3529 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3530 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3531 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3532 | } |
| 3533 | cur_arg++; |
| 3534 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3535 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3536 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3537 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3538 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3539 | } |
| 3540 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3541 | 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] | 3542 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3543 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3544 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3545 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3546 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3547 | 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] | 3548 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3549 | file, linenum); |
| 3550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3551 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3552 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3553 | else if (!strcmp(args[0], "email-alert")) { |
| 3554 | if (*(args[1]) == 0) { |
| 3555 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3556 | file, linenum, args[0]); |
| 3557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3558 | goto out; |
| 3559 | } |
| 3560 | |
| 3561 | if (!strcmp(args[1], "from")) { |
| 3562 | if (*(args[1]) == 0) { |
| 3563 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3564 | file, linenum, args[1]); |
| 3565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3566 | goto out; |
| 3567 | } |
| 3568 | free(curproxy->email_alert.from); |
| 3569 | curproxy->email_alert.from = strdup(args[2]); |
| 3570 | } |
| 3571 | else if (!strcmp(args[1], "mailers")) { |
| 3572 | if (*(args[1]) == 0) { |
| 3573 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3574 | file, linenum, args[1]); |
| 3575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3576 | goto out; |
| 3577 | } |
| 3578 | free(curproxy->email_alert.mailers.name); |
| 3579 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3580 | } |
| 3581 | else if (!strcmp(args[1], "myhostname")) { |
| 3582 | if (*(args[1]) == 0) { |
| 3583 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3584 | file, linenum, args[1]); |
| 3585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3586 | goto out; |
| 3587 | } |
| 3588 | free(curproxy->email_alert.myhostname); |
| 3589 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3590 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3591 | else if (!strcmp(args[1], "level")) { |
| 3592 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3593 | if (curproxy->email_alert.level < 0) { |
| 3594 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3595 | file, linenum, args[1], args[2]); |
| 3596 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3597 | goto out; |
| 3598 | } |
| 3599 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3600 | else if (!strcmp(args[1], "to")) { |
| 3601 | if (*(args[1]) == 0) { |
| 3602 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3603 | file, linenum, args[1]); |
| 3604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3605 | goto out; |
| 3606 | } |
| 3607 | free(curproxy->email_alert.to); |
| 3608 | curproxy->email_alert.to = strdup(args[2]); |
| 3609 | } |
| 3610 | else { |
| 3611 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3612 | file, linenum, args[1]); |
| 3613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3614 | goto out; |
| 3615 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3616 | /* Indicate that the email_alert is at least partially configured */ |
| 3617 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3618 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3619 | else if (!strcmp(args[0], "external-check")) { |
| 3620 | if (*(args[1]) == 0) { |
| 3621 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3622 | file, linenum, args[0]); |
| 3623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3624 | goto out; |
| 3625 | } |
| 3626 | |
| 3627 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3628 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3629 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3630 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3631 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3632 | file, linenum, args[1]); |
| 3633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3634 | goto out; |
| 3635 | } |
| 3636 | free(curproxy->check_command); |
| 3637 | curproxy->check_command = strdup(args[2]); |
| 3638 | } |
| 3639 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3640 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3641 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3642 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3643 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3644 | file, linenum, args[1]); |
| 3645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3646 | goto out; |
| 3647 | } |
| 3648 | free(curproxy->check_path); |
| 3649 | curproxy->check_path = strdup(args[2]); |
| 3650 | } |
| 3651 | else { |
| 3652 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3653 | file, linenum, args[1]); |
| 3654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3655 | goto out; |
| 3656 | } |
| 3657 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3658 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3659 | if (*(args[1]) == 0) { |
| 3660 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3661 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3663 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3667 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3668 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3669 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3670 | const char *beg, *end; |
| 3671 | |
| 3672 | beg = args[1] + 11; |
| 3673 | end = strchr(beg, ')'); |
| 3674 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3675 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3676 | goto out; |
| 3677 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3678 | if (!end || end == beg) { |
| 3679 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3680 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3682 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | free(curproxy->rdp_cookie_name); |
| 3686 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3687 | curproxy->rdp_cookie_len = end-beg; |
| 3688 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3689 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3690 | free(curproxy->rdp_cookie_name); |
| 3691 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3692 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3693 | } |
| 3694 | else { /* syntax */ |
| 3695 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3696 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3698 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | else { |
| 3702 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3703 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3705 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3706 | } |
| 3707 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3708 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3709 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3711 | goto out; |
| 3712 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3713 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3714 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3715 | err_code |= ERR_WARN; |
| 3716 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3717 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3718 | } |
| 3719 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3720 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3721 | } |
| 3722 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3723 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3724 | } |
| 3725 | else { |
| 3726 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3727 | file, linenum, args[0], args[1]); |
| 3728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3729 | goto out; |
| 3730 | } |
| 3731 | } |
| 3732 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3733 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3734 | err_code |= ERR_WARN; |
| 3735 | if (*(args[1]) == 0) { |
| 3736 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3737 | file, linenum, args[0]); |
| 3738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3739 | goto out; |
| 3740 | } |
| 3741 | else if (!strcmp(args[1], "use-backend-name")) |
| 3742 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3743 | else |
| 3744 | curproxy->server_state_file_name = strdup(args[1]); |
| 3745 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3746 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3747 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3748 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3749 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3750 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3751 | if (curproxy == &defproxy) { |
| 3752 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3754 | goto out; |
| 3755 | } |
| 3756 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3757 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3758 | goto out; |
| 3759 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3760 | if (*(args[4]) == 0) { |
| 3761 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3762 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3763 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3764 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3765 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3766 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3767 | curproxy->capture_name = strdup(args[2]); |
| 3768 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3769 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3770 | curproxy->to_log |= LW_COOKIE; |
| 3771 | } |
| 3772 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3773 | struct cap_hdr *hdr; |
| 3774 | |
| 3775 | if (curproxy == &defproxy) { |
| 3776 | 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] | 3777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3778 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3779 | } |
| 3780 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3781 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3782 | goto out; |
| 3783 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3784 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3785 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3786 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3788 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3789 | } |
| 3790 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3791 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3792 | hdr->next = curproxy->req_cap; |
| 3793 | hdr->name = strdup(args[3]); |
| 3794 | hdr->namelen = strlen(args[3]); |
| 3795 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3796 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3797 | hdr->index = curproxy->nb_req_cap++; |
| 3798 | curproxy->req_cap = hdr; |
| 3799 | curproxy->to_log |= LW_REQHDR; |
| 3800 | } |
| 3801 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3802 | struct cap_hdr *hdr; |
| 3803 | |
| 3804 | if (curproxy == &defproxy) { |
| 3805 | 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] | 3806 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3807 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3808 | } |
| 3809 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3810 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3811 | goto out; |
| 3812 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3813 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3814 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3815 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3817 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3818 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3819 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3820 | hdr->next = curproxy->rsp_cap; |
| 3821 | hdr->name = strdup(args[3]); |
| 3822 | hdr->namelen = strlen(args[3]); |
| 3823 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3824 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3825 | hdr->index = curproxy->nb_rsp_cap++; |
| 3826 | curproxy->rsp_cap = hdr; |
| 3827 | curproxy->to_log |= LW_RSPHDR; |
| 3828 | } |
| 3829 | else { |
| 3830 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3831 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3833 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3834 | } |
| 3835 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3836 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3837 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3838 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3839 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3840 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3841 | goto out; |
| 3842 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3843 | if (*(args[1]) == 0) { |
| 3844 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3845 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | } |
| 3849 | curproxy->conn_retries = atol(args[1]); |
| 3850 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3851 | 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] | 3852 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3853 | |
| 3854 | if (curproxy == &defproxy) { |
| 3855 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3857 | goto out; |
| 3858 | } |
| 3859 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3860 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3861 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3862 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3863 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3864 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3865 | 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] | 3866 | 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] | 3867 | file, linenum, args[0]); |
| 3868 | err_code |= ERR_WARN; |
| 3869 | } |
| 3870 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3871 | 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] | 3872 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3873 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3874 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3875 | goto out; |
| 3876 | } |
| 3877 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3878 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3879 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3880 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3881 | file, linenum); |
| 3882 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3883 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3884 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3885 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3886 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3887 | |
| 3888 | if (curproxy == &defproxy) { |
| 3889 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3891 | goto out; |
| 3892 | } |
| 3893 | |
| 3894 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3895 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3896 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3897 | 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] | 3898 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3899 | file, linenum, args[0]); |
| 3900 | err_code |= ERR_WARN; |
| 3901 | } |
| 3902 | |
| 3903 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3904 | |
| 3905 | if (!rule) { |
| 3906 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3907 | goto out; |
| 3908 | } |
| 3909 | |
| 3910 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3911 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3912 | file, linenum); |
| 3913 | |
| 3914 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3915 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3916 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3917 | /* set the header name and length into the proxy structure */ |
| 3918 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3919 | err_code |= ERR_WARN; |
| 3920 | |
| 3921 | if (!*args[1]) { |
| 3922 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3923 | file, linenum, args[0]); |
| 3924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3925 | goto out; |
| 3926 | } |
| 3927 | |
| 3928 | /* set the desired header name */ |
| 3929 | free(curproxy->server_id_hdr_name); |
| 3930 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3931 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3932 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3933 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3934 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3935 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3936 | if (curproxy == &defproxy) { |
| 3937 | 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] | 3938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3939 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3940 | } |
| 3941 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3942 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3943 | * be processed before all http-request rules, we put them into their own list |
| 3944 | * and will insert them at the end. |
| 3945 | */ |
| 3946 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3947 | if (!rule) { |
| 3948 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3949 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3950 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3951 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3952 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3953 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3954 | file, linenum); |
| 3955 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3956 | |
| 3957 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3958 | 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]); |
| 3959 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3960 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3961 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3962 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3963 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3964 | if (curproxy == &defproxy) { |
| 3965 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3967 | goto out; |
| 3968 | } |
| 3969 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3970 | 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] | 3971 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3972 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3974 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3975 | } |
| 3976 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3977 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3978 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3979 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3980 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3981 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3982 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3983 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3984 | struct switching_rule *rule; |
| 3985 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3986 | if (curproxy == &defproxy) { |
| 3987 | 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] | 3988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3989 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3990 | } |
| 3991 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3992 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3993 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3994 | |
| 3995 | if (*(args[1]) == 0) { |
| 3996 | 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] | 3997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3998 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3999 | } |
| 4000 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4001 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 4002 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4003 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4004 | file, linenum, errmsg); |
| 4005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4006 | goto out; |
| 4007 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4008 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4009 | 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] | 4010 | } |
| 4011 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4012 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4013 | rule->cond = cond; |
| 4014 | rule->be.name = strdup(args[1]); |
| 4015 | LIST_INIT(&rule->list); |
| 4016 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4017 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4018 | else if (strcmp(args[0], "use-server") == 0) { |
| 4019 | struct server_rule *rule; |
| 4020 | |
| 4021 | if (curproxy == &defproxy) { |
| 4022 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4024 | goto out; |
| 4025 | } |
| 4026 | |
| 4027 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4028 | err_code |= ERR_WARN; |
| 4029 | |
| 4030 | if (*(args[1]) == 0) { |
| 4031 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 4032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4033 | goto out; |
| 4034 | } |
| 4035 | |
| 4036 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4037 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4038 | file, linenum, args[0]); |
| 4039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4040 | goto out; |
| 4041 | } |
| 4042 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4043 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4044 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4045 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4047 | goto out; |
| 4048 | } |
| 4049 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4050 | 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] | 4051 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4052 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4053 | rule->cond = cond; |
| 4054 | rule->srv.name = strdup(args[1]); |
| 4055 | LIST_INIT(&rule->list); |
| 4056 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4057 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4058 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4059 | else if ((!strcmp(args[0], "force-persist")) || |
| 4060 | (!strcmp(args[0], "ignore-persist"))) { |
| 4061 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4062 | |
| 4063 | if (curproxy == &defproxy) { |
| 4064 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4066 | goto out; |
| 4067 | } |
| 4068 | |
| 4069 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4070 | err_code |= ERR_WARN; |
| 4071 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4072 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4073 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4074 | file, linenum, args[0]); |
| 4075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4076 | goto out; |
| 4077 | } |
| 4078 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4079 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 4080 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4081 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4083 | goto out; |
| 4084 | } |
| 4085 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4086 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4087 | * where force-persist is applied. |
| 4088 | */ |
| 4089 | 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] | 4090 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4091 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4092 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4093 | if (!strcmp(args[0], "force-persist")) { |
| 4094 | rule->type = PERSIST_TYPE_FORCE; |
| 4095 | } else { |
| 4096 | rule->type = PERSIST_TYPE_IGNORE; |
| 4097 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4098 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4099 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4100 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4101 | else if (!strcmp(args[0], "stick-table")) { |
| 4102 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4103 | struct proxy *other; |
| 4104 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4105 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4106 | if (other) { |
| 4107 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4108 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 4109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4110 | goto out; |
| 4111 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4112 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4113 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4114 | curproxy->table.type = (unsigned int)-1; |
| 4115 | while (*args[myidx]) { |
| 4116 | const char *err; |
| 4117 | |
| 4118 | if (strcmp(args[myidx], "size") == 0) { |
| 4119 | myidx++; |
| 4120 | if (!*(args[myidx])) { |
| 4121 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4122 | file, linenum, args[myidx-1]); |
| 4123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4124 | goto out; |
| 4125 | } |
| 4126 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 4127 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4128 | file, linenum, *err, args[myidx-1]); |
| 4129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4130 | goto out; |
| 4131 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4132 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4133 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4134 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4135 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4136 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4137 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4138 | file, linenum, args[myidx-1]); |
| 4139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4140 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4141 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4142 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4143 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4144 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4145 | myidx++; |
| 4146 | if (!*(args[myidx])) { |
| 4147 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4148 | file, linenum, args[myidx-1]); |
| 4149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4150 | goto out; |
| 4151 | } |
| 4152 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4153 | if (err) { |
| 4154 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4155 | file, linenum, *err, args[myidx-1]); |
| 4156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4157 | goto out; |
| 4158 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4159 | if (val > INT_MAX) { |
| 4160 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4161 | file, linenum, val); |
| 4162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4163 | goto out; |
| 4164 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4165 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4166 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4167 | } |
| 4168 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4169 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4170 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4171 | } |
| 4172 | else if (strcmp(args[myidx], "type") == 0) { |
| 4173 | myidx++; |
| 4174 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4175 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4176 | file, linenum, args[myidx]); |
| 4177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4178 | goto out; |
| 4179 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4180 | /* myidx already points to next arg */ |
| 4181 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4182 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4183 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4184 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4185 | |
| 4186 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4187 | nw = args[myidx]; |
| 4188 | while (*nw) { |
| 4189 | /* the "store" keyword supports a comma-separated list */ |
| 4190 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4191 | sa = NULL; /* store arg */ |
| 4192 | while (*nw && *nw != ',') { |
| 4193 | if (*nw == '(') { |
| 4194 | *nw = 0; |
| 4195 | sa = ++nw; |
| 4196 | while (*nw != ')') { |
| 4197 | if (!*nw) { |
| 4198 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4199 | file, linenum, args[0], cw); |
| 4200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4201 | goto out; |
| 4202 | } |
| 4203 | nw++; |
| 4204 | } |
| 4205 | *nw = '\0'; |
| 4206 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4207 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4208 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4209 | if (*nw) |
| 4210 | *nw++ = '\0'; |
| 4211 | type = stktable_get_data_type(cw); |
| 4212 | if (type < 0) { |
| 4213 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4214 | file, linenum, args[0], cw); |
| 4215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4216 | goto out; |
| 4217 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4218 | |
| 4219 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4220 | switch (err) { |
| 4221 | case PE_NONE: break; |
| 4222 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4223 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4224 | file, linenum, args[0], cw); |
| 4225 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4226 | break; |
| 4227 | |
| 4228 | case PE_ARG_MISSING: |
| 4229 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4230 | file, linenum, args[0], cw); |
| 4231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4232 | goto out; |
| 4233 | |
| 4234 | case PE_ARG_NOT_USED: |
| 4235 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4236 | file, linenum, args[0], cw); |
| 4237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4238 | goto out; |
| 4239 | |
| 4240 | default: |
| 4241 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4242 | file, linenum, args[0], cw); |
| 4243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4244 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4245 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4246 | } |
| 4247 | myidx++; |
| 4248 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4249 | else { |
| 4250 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4251 | file, linenum, args[myidx]); |
| 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4254 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | if (!curproxy->table.size) { |
| 4258 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4259 | file, linenum); |
| 4260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4261 | goto out; |
| 4262 | } |
| 4263 | |
| 4264 | if (curproxy->table.type == (unsigned int)-1) { |
| 4265 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4266 | file, linenum); |
| 4267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4268 | goto out; |
| 4269 | } |
| 4270 | } |
| 4271 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4272 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4273 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4274 | int myidx = 0; |
| 4275 | const char *name = NULL; |
| 4276 | int flags; |
| 4277 | |
| 4278 | if (curproxy == &defproxy) { |
| 4279 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4281 | goto out; |
| 4282 | } |
| 4283 | |
| 4284 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4285 | err_code |= ERR_WARN; |
| 4286 | goto out; |
| 4287 | } |
| 4288 | |
| 4289 | myidx++; |
| 4290 | if ((strcmp(args[myidx], "store") == 0) || |
| 4291 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4292 | myidx++; |
| 4293 | flags = STK_IS_STORE; |
| 4294 | } |
| 4295 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4296 | myidx++; |
| 4297 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4298 | } |
| 4299 | else if (strcmp(args[myidx], "match") == 0) { |
| 4300 | myidx++; |
| 4301 | flags = STK_IS_MATCH; |
| 4302 | } |
| 4303 | else if (strcmp(args[myidx], "on") == 0) { |
| 4304 | myidx++; |
| 4305 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4306 | } |
| 4307 | else { |
| 4308 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4310 | goto out; |
| 4311 | } |
| 4312 | |
| 4313 | if (*(args[myidx]) == 0) { |
| 4314 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4316 | goto out; |
| 4317 | } |
| 4318 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4319 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4320 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4321 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4322 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4324 | goto out; |
| 4325 | } |
| 4326 | |
| 4327 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4328 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4329 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4330 | 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] | 4331 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4332 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4333 | goto out; |
| 4334 | } |
| 4335 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4336 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4337 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4338 | 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] | 4339 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4340 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4341 | goto out; |
| 4342 | } |
| 4343 | } |
| 4344 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4345 | /* 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] | 4346 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4347 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4348 | if (strcmp(args[myidx], "table") == 0) { |
| 4349 | myidx++; |
| 4350 | name = args[myidx++]; |
| 4351 | } |
| 4352 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4353 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4354 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4355 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4356 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4357 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4358 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4359 | goto out; |
| 4360 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4361 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4362 | else if (*(args[myidx])) { |
| 4363 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4364 | file, linenum, args[0], args[myidx]); |
| 4365 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4366 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4367 | goto out; |
| 4368 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4369 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4370 | 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] | 4371 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4372 | 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] | 4373 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4374 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4375 | rule->cond = cond; |
| 4376 | rule->expr = expr; |
| 4377 | rule->flags = flags; |
| 4378 | rule->table.name = name ? strdup(name) : NULL; |
| 4379 | LIST_INIT(&rule->list); |
| 4380 | if (flags & STK_ON_RSP) |
| 4381 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4382 | else |
| 4383 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4384 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4385 | else if (!strcmp(args[0], "stats")) { |
| 4386 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4387 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4388 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4389 | if (!*args[1]) { |
| 4390 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4391 | } else if (!strcmp(args[1], "admin")) { |
| 4392 | struct stats_admin_rule *rule; |
| 4393 | |
| 4394 | if (curproxy == &defproxy) { |
| 4395 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
| 4399 | |
| 4400 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4401 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4402 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4403 | goto out; |
| 4404 | } |
| 4405 | |
| 4406 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4407 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4408 | file, linenum, args[0], args[1]); |
| 4409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4410 | goto out; |
| 4411 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4412 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4413 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4414 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4416 | goto out; |
| 4417 | } |
| 4418 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4419 | err_code |= warnif_cond_conflicts(cond, |
| 4420 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4421 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4422 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4423 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4424 | rule->cond = cond; |
| 4425 | LIST_INIT(&rule->list); |
| 4426 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4427 | } else if (!strcmp(args[1], "uri")) { |
| 4428 | if (*(args[2]) == 0) { |
| 4429 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4431 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4432 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4433 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4434 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4435 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4436 | } |
| 4437 | } else if (!strcmp(args[1], "realm")) { |
| 4438 | if (*(args[2]) == 0) { |
| 4439 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4442 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4443 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4444 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4445 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4446 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4447 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4448 | unsigned interval; |
| 4449 | |
| 4450 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4451 | if (err) { |
| 4452 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4453 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4455 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4456 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4457 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4458 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4459 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4460 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4461 | } 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] | 4462 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4463 | |
| 4464 | if (curproxy == &defproxy) { |
| 4465 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4467 | goto out; |
| 4468 | } |
| 4469 | |
| 4470 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4471 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4472 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4473 | goto out; |
| 4474 | } |
| 4475 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4476 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4477 | !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] | 4478 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4479 | file, linenum, args[0]); |
| 4480 | err_code |= ERR_WARN; |
| 4481 | } |
| 4482 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4483 | 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] | 4484 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4485 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4486 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4487 | goto out; |
| 4488 | } |
| 4489 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4490 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4491 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4492 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4493 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4494 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4495 | } else if (!strcmp(args[1], "auth")) { |
| 4496 | if (*(args[2]) == 0) { |
| 4497 | 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] | 4498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4499 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4500 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4501 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4502 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4503 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4504 | } |
| 4505 | } else if (!strcmp(args[1], "scope")) { |
| 4506 | if (*(args[2]) == 0) { |
| 4507 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4509 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4510 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4511 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4512 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4513 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4514 | } |
| 4515 | } else if (!strcmp(args[1], "enable")) { |
| 4516 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4517 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4518 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4519 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4520 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4521 | } else if (!strcmp(args[1], "hide-version")) { |
| 4522 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4523 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4524 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4525 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4526 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4527 | } else if (!strcmp(args[1], "show-legends")) { |
| 4528 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4529 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4530 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4531 | goto out; |
| 4532 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4533 | } else if (!strcmp(args[1], "show-node")) { |
| 4534 | |
| 4535 | if (*args[2]) { |
| 4536 | int i; |
| 4537 | char c; |
| 4538 | |
| 4539 | for (i=0; args[2][i]; i++) { |
| 4540 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4541 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4542 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4543 | break; |
| 4544 | } |
| 4545 | |
| 4546 | if (!i || args[2][i]) { |
| 4547 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4548 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4549 | file, linenum, args[0], args[1]); |
| 4550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4551 | goto out; |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4556 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4557 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4558 | goto out; |
| 4559 | } |
| 4560 | } else if (!strcmp(args[1], "show-desc")) { |
| 4561 | char *desc = NULL; |
| 4562 | |
| 4563 | if (*args[2]) { |
| 4564 | int i, len=0; |
| 4565 | char *d; |
| 4566 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4567 | for (i = 2; *args[i]; i++) |
| 4568 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4569 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4570 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4571 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4572 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4573 | for (i = 3; *args[i]; i++) |
| 4574 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | if (!*args[2] && !global.desc) |
| 4578 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4579 | file, linenum, args[1]); |
| 4580 | else { |
| 4581 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4582 | free(desc); |
| 4583 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4584 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4585 | goto out; |
| 4586 | } |
| 4587 | free(desc); |
| 4588 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4589 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4590 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4591 | 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] | 4592 | 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] | 4593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4594 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4598 | int optnum; |
| 4599 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4600 | if (*(args[1]) == '\0') { |
| 4601 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4602 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4605 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4606 | |
| 4607 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4608 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4609 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4610 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4611 | file, linenum, cfg_opts[optnum].name); |
| 4612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4613 | goto out; |
| 4614 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4615 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4616 | goto out; |
| 4617 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4618 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4619 | err_code |= ERR_WARN; |
| 4620 | goto out; |
| 4621 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4622 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4623 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4624 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4625 | |
| 4626 | switch (kwm) { |
| 4627 | case KWM_STD: |
| 4628 | curproxy->options |= cfg_opts[optnum].val; |
| 4629 | break; |
| 4630 | case KWM_NO: |
| 4631 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4632 | break; |
| 4633 | case KWM_DEF: /* already cleared */ |
| 4634 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4635 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4636 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4637 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4638 | } |
| 4639 | } |
| 4640 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4641 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4642 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4643 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4644 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4645 | file, linenum, cfg_opts2[optnum].name); |
| 4646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4647 | goto out; |
| 4648 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4649 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4650 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4651 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4652 | err_code |= ERR_WARN; |
| 4653 | goto out; |
| 4654 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4655 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4656 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4657 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4658 | |
| 4659 | switch (kwm) { |
| 4660 | case KWM_STD: |
| 4661 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4662 | break; |
| 4663 | case KWM_NO: |
| 4664 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4665 | break; |
| 4666 | case KWM_DEF: /* already cleared */ |
| 4667 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4668 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4669 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4673 | /* HTTP options override each other. They can be cancelled using |
| 4674 | * "no option xxx" which only switches to default mode if the mode |
| 4675 | * was this one (useful for cancelling options set in defaults |
| 4676 | * sections). |
| 4677 | */ |
| 4678 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4679 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4680 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4681 | if (kwm == KWM_STD) { |
| 4682 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4683 | curproxy->options |= PR_O_HTTP_PCL; |
| 4684 | goto out; |
| 4685 | } |
| 4686 | else if (kwm == KWM_NO) { |
| 4687 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4688 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4689 | goto out; |
| 4690 | } |
| 4691 | } |
| 4692 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4693 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4694 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4695 | if (kwm == KWM_STD) { |
| 4696 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4697 | curproxy->options |= PR_O_HTTP_FCL; |
| 4698 | goto out; |
| 4699 | } |
| 4700 | else if (kwm == KWM_NO) { |
| 4701 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4702 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4703 | goto out; |
| 4704 | } |
| 4705 | } |
| 4706 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4707 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4708 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4709 | if (kwm == KWM_STD) { |
| 4710 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4711 | curproxy->options |= PR_O_HTTP_SCL; |
| 4712 | goto out; |
| 4713 | } |
| 4714 | else if (kwm == KWM_NO) { |
| 4715 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4716 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4717 | goto out; |
| 4718 | } |
| 4719 | } |
| 4720 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4721 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4722 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4723 | if (kwm == KWM_STD) { |
| 4724 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4725 | curproxy->options |= PR_O_HTTP_KAL; |
| 4726 | goto out; |
| 4727 | } |
| 4728 | else if (kwm == KWM_NO) { |
| 4729 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4730 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4731 | goto out; |
| 4732 | } |
| 4733 | } |
| 4734 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4735 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4736 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4737 | if (kwm == KWM_STD) { |
| 4738 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4739 | curproxy->options |= PR_O_HTTP_TUN; |
| 4740 | goto out; |
| 4741 | } |
| 4742 | else if (kwm == KWM_NO) { |
| 4743 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4744 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4745 | goto out; |
| 4746 | } |
| 4747 | } |
| 4748 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4749 | /* Redispatch can take an integer argument that control when the |
| 4750 | * resispatch occurs. All values are relative to the retries option. |
| 4751 | * This can be cancelled using "no option xxx". |
| 4752 | */ |
| 4753 | if (strcmp(args[1], "redispatch") == 0) { |
| 4754 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4755 | err_code |= ERR_WARN; |
| 4756 | goto out; |
| 4757 | } |
| 4758 | |
| 4759 | curproxy->no_options &= ~PR_O_REDISP; |
| 4760 | curproxy->options &= ~PR_O_REDISP; |
| 4761 | |
| 4762 | switch (kwm) { |
| 4763 | case KWM_STD: |
| 4764 | curproxy->options |= PR_O_REDISP; |
| 4765 | curproxy->redispatch_after = -1; |
| 4766 | if(*args[2]) { |
| 4767 | curproxy->redispatch_after = atol(args[2]); |
| 4768 | } |
| 4769 | break; |
| 4770 | case KWM_NO: |
| 4771 | curproxy->no_options |= PR_O_REDISP; |
| 4772 | curproxy->redispatch_after = 0; |
| 4773 | break; |
| 4774 | case KWM_DEF: /* already cleared */ |
| 4775 | break; |
| 4776 | } |
| 4777 | goto out; |
| 4778 | } |
| 4779 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4780 | if (kwm != KWM_STD) { |
| 4781 | 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] | 4782 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4784 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4785 | } |
| 4786 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4787 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4788 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4789 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4790 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4791 | if (*(args[2]) != '\0') { |
| 4792 | if (!strcmp(args[2], "clf")) { |
| 4793 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4794 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4795 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4796 | 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] | 4797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4798 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4799 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4800 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4801 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4802 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4803 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4804 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4805 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4806 | free(curproxy->conf.logformat_string); |
| 4807 | curproxy->conf.logformat_string = logformat; |
| 4808 | |
| 4809 | free(curproxy->conf.lfs_file); |
| 4810 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4811 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4812 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4813 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4814 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4815 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4816 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4817 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4818 | free(curproxy->conf.logformat_string); |
| 4819 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4820 | |
| 4821 | free(curproxy->conf.lfs_file); |
| 4822 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4823 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4824 | |
| 4825 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4826 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4827 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4828 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4829 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4830 | 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] | 4831 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4832 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4833 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4834 | goto out; |
| 4835 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4836 | if (curproxy->cap & PR_CAP_FE) |
| 4837 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4838 | if (curproxy->cap & PR_CAP_BE) |
| 4839 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4840 | } |
| 4841 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4842 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4843 | err_code |= ERR_WARN; |
| 4844 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4845 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4846 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4847 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4848 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4849 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4850 | if (!*args[2]) { /* no argument */ |
| 4851 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4852 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4853 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4854 | 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] | 4855 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4856 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4857 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4858 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4859 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4860 | if (*args[4]) |
| 4861 | reqlen += strlen(args[4]); |
| 4862 | else |
| 4863 | reqlen += strlen("HTTP/1.0"); |
| 4864 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4865 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4866 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4867 | "%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] | 4868 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4869 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4870 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4871 | } |
| 4872 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4873 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4874 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4875 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4876 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4877 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4878 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4879 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4880 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4881 | |
| 4882 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4883 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4884 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4885 | else if (!strcmp(args[1], "smtpchk")) { |
| 4886 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4887 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4888 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4889 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4890 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4891 | |
| 4892 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4893 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4894 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4895 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4896 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4897 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4898 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4899 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4900 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4901 | } else { |
| 4902 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4903 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4904 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4905 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4906 | } |
| 4907 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4908 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4909 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4910 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4911 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4912 | /* use PostgreSQL request to check servers' health */ |
| 4913 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4914 | err_code |= ERR_WARN; |
| 4915 | |
| 4916 | free(curproxy->check_req); |
| 4917 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4918 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4919 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4920 | |
| 4921 | if (*(args[2])) { |
| 4922 | int cur_arg = 2; |
| 4923 | |
| 4924 | while (*(args[cur_arg])) { |
| 4925 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4926 | char * packet; |
| 4927 | uint32_t packet_len; |
| 4928 | uint32_t pv; |
| 4929 | |
| 4930 | /* suboption header - needs additional argument for it */ |
| 4931 | if (*(args[cur_arg+1]) == 0) { |
| 4932 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4933 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4935 | goto out; |
| 4936 | } |
| 4937 | |
| 4938 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4939 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4940 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4941 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4942 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4943 | |
| 4944 | memcpy(packet + 4, &pv, 4); |
| 4945 | |
| 4946 | /* copy "user" */ |
| 4947 | memcpy(packet + 8, "user", 4); |
| 4948 | |
| 4949 | /* copy username */ |
| 4950 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4951 | |
| 4952 | free(curproxy->check_req); |
| 4953 | curproxy->check_req = packet; |
| 4954 | curproxy->check_len = packet_len; |
| 4955 | |
| 4956 | packet_len = htonl(packet_len); |
| 4957 | memcpy(packet, &packet_len, 4); |
| 4958 | cur_arg += 2; |
| 4959 | } else { |
| 4960 | /* unknown suboption - catchall */ |
| 4961 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4962 | file, linenum, args[0], args[1]); |
| 4963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4964 | goto out; |
| 4965 | } |
| 4966 | } /* end while loop */ |
| 4967 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4968 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4969 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4970 | } |
| 4971 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4972 | else if (!strcmp(args[1], "redis-check")) { |
| 4973 | /* use REDIS PING request to check servers' health */ |
| 4974 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4975 | err_code |= ERR_WARN; |
| 4976 | |
| 4977 | free(curproxy->check_req); |
| 4978 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4979 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4980 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4981 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4982 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4983 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4984 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4985 | |
| 4986 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4987 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4988 | } |
| 4989 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4990 | else if (!strcmp(args[1], "mysql-check")) { |
| 4991 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4992 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4993 | err_code |= ERR_WARN; |
| 4994 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4995 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4996 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4997 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4998 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4999 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5000 | /* 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] | 5001 | * const char mysql40_client_auth_pkt[] = { |
| 5002 | * "\x0e\x00\x00" // packet length |
| 5003 | * "\x01" // packet number |
| 5004 | * "\x00\x00" // client capabilities |
| 5005 | * "\x00\x00\x01" // max packet |
| 5006 | * "haproxy\x00" // username (null terminated string) |
| 5007 | * "\x00" // filler (always 0x00) |
| 5008 | * "\x01\x00\x00" // packet length |
| 5009 | * "\x00" // packet number |
| 5010 | * "\x01" // COM_QUIT command |
| 5011 | * }; |
| 5012 | */ |
| 5013 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5014 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5015 | * const char mysql41_client_auth_pkt[] = { |
| 5016 | * "\x0e\x00\x00\" // packet length |
| 5017 | * "\x01" // packet number |
| 5018 | * "\x00\x00\x00\x00" // client capabilities |
| 5019 | * "\x00\x00\x00\x01" // max packet |
| 5020 | * "\x21" // character set (UTF-8) |
| 5021 | * char[23] // All zeroes |
| 5022 | * "haproxy\x00" // username (null terminated string) |
| 5023 | * "\x00" // filler (always 0x00) |
| 5024 | * "\x01\x00\x00" // packet length |
| 5025 | * "\x00" // packet number |
| 5026 | * "\x01" // COM_QUIT command |
| 5027 | * }; |
| 5028 | */ |
| 5029 | |
| 5030 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5031 | if (*(args[2])) { |
| 5032 | int cur_arg = 2; |
| 5033 | |
| 5034 | while (*(args[cur_arg])) { |
| 5035 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5036 | char *mysqluser; |
| 5037 | int packetlen, reqlen, userlen; |
| 5038 | |
| 5039 | /* suboption header - needs additional argument for it */ |
| 5040 | if (*(args[cur_arg+1]) == 0) { |
| 5041 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5042 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5044 | goto out; |
| 5045 | } |
| 5046 | mysqluser = args[cur_arg + 1]; |
| 5047 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5048 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5049 | if (*(args[cur_arg+2])) { |
| 5050 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5051 | packetlen = userlen + 7 + 27; |
| 5052 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5053 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5054 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5055 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5056 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5057 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5058 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5059 | ((unsigned char) packetlen & 0xff), |
| 5060 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5061 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5062 | |
| 5063 | curproxy->check_req[3] = 1; |
| 5064 | curproxy->check_req[5] = 130; |
| 5065 | curproxy->check_req[11] = 1; |
| 5066 | curproxy->check_req[12] = 33; |
| 5067 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5068 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5069 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5070 | cur_arg += 3; |
| 5071 | } else { |
| 5072 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 5073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5074 | goto out; |
| 5075 | } |
| 5076 | } else { |
| 5077 | packetlen = userlen + 7; |
| 5078 | reqlen = packetlen + 9; |
| 5079 | |
| 5080 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5081 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5082 | curproxy->check_len = reqlen; |
| 5083 | |
| 5084 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5085 | ((unsigned char) packetlen & 0xff), |
| 5086 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5087 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5088 | |
| 5089 | curproxy->check_req[3] = 1; |
| 5090 | curproxy->check_req[5] = 128; |
| 5091 | curproxy->check_req[8] = 1; |
| 5092 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5093 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5094 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5095 | cur_arg += 2; |
| 5096 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5097 | } else { |
| 5098 | /* unknown suboption - catchall */ |
| 5099 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5100 | file, linenum, args[0], args[1]); |
| 5101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5102 | goto out; |
| 5103 | } |
| 5104 | } /* end while loop */ |
| 5105 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5106 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5107 | else if (!strcmp(args[1], "ldap-check")) { |
| 5108 | /* use LDAP request to check servers' health */ |
| 5109 | free(curproxy->check_req); |
| 5110 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5111 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5112 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5113 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5114 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5115 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5116 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5117 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5118 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5119 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5120 | else if (!strcmp(args[1], "tcp-check")) { |
| 5121 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5122 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5123 | err_code |= ERR_WARN; |
| 5124 | |
| 5125 | free(curproxy->check_req); |
| 5126 | curproxy->check_req = NULL; |
| 5127 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5128 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5129 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5130 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5131 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5132 | else if (!strcmp(args[1], "external-check")) { |
| 5133 | /* excute an external command to check servers' health */ |
| 5134 | free(curproxy->check_req); |
| 5135 | curproxy->check_req = NULL; |
| 5136 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5137 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5138 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5139 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5140 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5141 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5142 | int cur_arg; |
| 5143 | |
| 5144 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5145 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5146 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5147 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5148 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5149 | |
| 5150 | free(curproxy->fwdfor_hdr_name); |
| 5151 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5152 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5153 | |
| 5154 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5155 | cur_arg = 2; |
| 5156 | while (*(args[cur_arg])) { |
| 5157 | if (!strcmp(args[cur_arg], "except")) { |
| 5158 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5159 | 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] | 5160 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5161 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5163 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5164 | } |
| 5165 | /* flush useless bits */ |
| 5166 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5167 | cur_arg += 2; |
| 5168 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5169 | /* suboption header - needs additional argument for it */ |
| 5170 | if (*(args[cur_arg+1]) == 0) { |
| 5171 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5172 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5173 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5174 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5175 | } |
| 5176 | free(curproxy->fwdfor_hdr_name); |
| 5177 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5178 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5179 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5180 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5181 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5182 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5183 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5184 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5185 | 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] | 5186 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5188 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5189 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5190 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5191 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5192 | else if (!strcmp(args[1], "originalto")) { |
| 5193 | int cur_arg; |
| 5194 | |
| 5195 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5196 | * set default options (ie: bitfield, header name, etc) |
| 5197 | */ |
| 5198 | |
| 5199 | curproxy->options |= PR_O_ORGTO; |
| 5200 | |
| 5201 | free(curproxy->orgto_hdr_name); |
| 5202 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5203 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5204 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5205 | /* 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] | 5206 | cur_arg = 2; |
| 5207 | while (*(args[cur_arg])) { |
| 5208 | if (!strcmp(args[cur_arg], "except")) { |
| 5209 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5210 | 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] | 5211 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5212 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5214 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5215 | } |
| 5216 | /* flush useless bits */ |
| 5217 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5218 | cur_arg += 2; |
| 5219 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5220 | /* suboption header - needs additional argument for it */ |
| 5221 | if (*(args[cur_arg+1]) == 0) { |
| 5222 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5223 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5225 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5226 | } |
| 5227 | free(curproxy->orgto_hdr_name); |
| 5228 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5229 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5230 | cur_arg += 2; |
| 5231 | } else { |
| 5232 | /* unknown suboption - catchall */ |
| 5233 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5234 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5236 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5237 | } |
| 5238 | } /* end while loop */ |
| 5239 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5240 | else { |
| 5241 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5243 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5244 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5245 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5246 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5247 | else if (!strcmp(args[0], "default_backend")) { |
| 5248 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5249 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5250 | |
| 5251 | if (*(args[1]) == 0) { |
| 5252 | 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] | 5253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5254 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5255 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5256 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5257 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5258 | |
| 5259 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5260 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5261 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5262 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5263 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5264 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5265 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5266 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5267 | 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] | 5268 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5269 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5270 | /* enable reconnections to dispatch */ |
| 5271 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5272 | |
| 5273 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5276 | else if (!strcmp(args[0], "http-reuse")) { |
| 5277 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5278 | err_code |= ERR_WARN; |
| 5279 | |
| 5280 | if (strcmp(args[1], "never") == 0) { |
| 5281 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5282 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5283 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5284 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5285 | goto out; |
| 5286 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5287 | else if (strcmp(args[1], "safe") == 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_SAFE; |
| 5291 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5292 | goto out; |
| 5293 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5294 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5295 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5296 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5297 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5298 | goto out; |
| 5299 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5300 | else if (strcmp(args[1], "always") == 0) { |
| 5301 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5302 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5303 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5304 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5305 | goto out; |
| 5306 | } |
| 5307 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5308 | 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] | 5309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5310 | goto out; |
| 5311 | } |
| 5312 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5313 | else if (!strcmp(args[0], "http-check")) { |
| 5314 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5315 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5316 | |
| 5317 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5318 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5319 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5320 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5321 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5322 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5323 | else if (strcmp(args[1], "send-state") == 0) { |
| 5324 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5325 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5326 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5327 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5328 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5329 | else if (strcmp(args[1], "expect") == 0) { |
| 5330 | const char *ptr_arg; |
| 5331 | int cur_arg; |
| 5332 | |
| 5333 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5334 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5336 | goto out; |
| 5337 | } |
| 5338 | |
| 5339 | cur_arg = 2; |
| 5340 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5341 | while (*(ptr_arg = args[cur_arg])) { |
| 5342 | while (*ptr_arg == '!') { |
| 5343 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5344 | ptr_arg++; |
| 5345 | } |
| 5346 | if (*ptr_arg) |
| 5347 | break; |
| 5348 | cur_arg++; |
| 5349 | } |
| 5350 | /* now ptr_arg points to the beginning of a word past any possible |
| 5351 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5352 | */ |
| 5353 | if (strcmp(ptr_arg, "status") == 0) { |
| 5354 | if (!*(args[cur_arg + 1])) { |
| 5355 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5356 | file, linenum, args[0], args[1], ptr_arg); |
| 5357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5358 | goto out; |
| 5359 | } |
| 5360 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5361 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5362 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5363 | } |
| 5364 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5365 | if (!*(args[cur_arg + 1])) { |
| 5366 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5367 | file, linenum, args[0], args[1], ptr_arg); |
| 5368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5369 | goto out; |
| 5370 | } |
| 5371 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5372 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5373 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5374 | } |
| 5375 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5376 | if (!*(args[cur_arg + 1])) { |
| 5377 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5378 | file, linenum, args[0], args[1], ptr_arg); |
| 5379 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5380 | goto out; |
| 5381 | } |
| 5382 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5383 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5384 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5385 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5386 | free(curproxy->expect_regex); |
| 5387 | curproxy->expect_regex = NULL; |
| 5388 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5389 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5390 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5391 | error = NULL; |
| 5392 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5393 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5394 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5395 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5397 | goto out; |
| 5398 | } |
| 5399 | } |
| 5400 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5401 | if (!*(args[cur_arg + 1])) { |
| 5402 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5403 | file, linenum, args[0], args[1], ptr_arg); |
| 5404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5405 | goto out; |
| 5406 | } |
| 5407 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5408 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5409 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5410 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5411 | free(curproxy->expect_regex); |
| 5412 | curproxy->expect_regex = NULL; |
| 5413 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5414 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5415 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5416 | error = NULL; |
| 5417 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5418 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5419 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5420 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5421 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5422 | goto out; |
| 5423 | } |
| 5424 | } |
| 5425 | else { |
| 5426 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5427 | file, linenum, args[0], args[1], ptr_arg); |
| 5428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5429 | goto out; |
| 5430 | } |
| 5431 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5432 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5433 | 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] | 5434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5435 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5436 | } |
| 5437 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5438 | else if (!strcmp(args[0], "tcp-check")) { |
| 5439 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5440 | err_code |= ERR_WARN; |
| 5441 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5442 | if (strcmp(args[1], "comment") == 0) { |
| 5443 | int cur_arg; |
| 5444 | struct tcpcheck_rule *tcpcheck; |
| 5445 | |
| 5446 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5447 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5448 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5449 | |
| 5450 | if (!*args[cur_arg + 1]) { |
| 5451 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5452 | file, linenum, args[cur_arg]); |
| 5453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5454 | goto out; |
| 5455 | } |
| 5456 | |
| 5457 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5458 | |
| 5459 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5460 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5461 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5462 | } |
| 5463 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5464 | const char *ptr_arg; |
| 5465 | int cur_arg; |
| 5466 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5467 | |
| 5468 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5469 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5470 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5471 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5472 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5473 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5474 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5475 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5476 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5477 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5478 | file, linenum); |
| 5479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5480 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5484 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5485 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5486 | |
| 5487 | /* parsing each parameters to fill up the rule */ |
| 5488 | while (*(ptr_arg = args[cur_arg])) { |
| 5489 | /* tcp port */ |
| 5490 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5491 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5492 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5493 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5494 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5496 | goto out; |
| 5497 | } |
| 5498 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5499 | cur_arg += 2; |
| 5500 | } |
| 5501 | /* send proxy protocol */ |
| 5502 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5503 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5504 | cur_arg++; |
| 5505 | } |
| 5506 | #ifdef USE_OPENSSL |
| 5507 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5508 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5509 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5510 | cur_arg++; |
| 5511 | } |
| 5512 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5513 | /* comment for this tcpcheck line */ |
| 5514 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5515 | if (!*args[cur_arg + 1]) { |
| 5516 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5517 | file, linenum, args[cur_arg]); |
| 5518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5519 | goto out; |
| 5520 | } |
| 5521 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5522 | cur_arg += 2; |
| 5523 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5524 | else { |
| 5525 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5526 | 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] | 5527 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5528 | 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] | 5529 | #endif /* USE_OPENSSL */ |
| 5530 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5532 | goto out; |
| 5533 | } |
| 5534 | |
| 5535 | } |
| 5536 | |
| 5537 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5538 | } |
| 5539 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5540 | if (! *(args[2]) ) { |
| 5541 | /* SEND string expected */ |
| 5542 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5543 | file, linenum, args[0], args[1], args[2]); |
| 5544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5545 | goto out; |
| 5546 | } else { |
| 5547 | struct tcpcheck_rule *tcpcheck; |
| 5548 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5549 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5550 | |
| 5551 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5552 | tcpcheck->string_len = strlen(args[2]); |
| 5553 | tcpcheck->string = strdup(args[2]); |
| 5554 | tcpcheck->expect_regex = NULL; |
| 5555 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5556 | /* comment for this tcpcheck line */ |
| 5557 | if (strcmp(args[3], "comment") == 0) { |
| 5558 | if (!*args[4]) { |
| 5559 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5560 | file, linenum, args[3]); |
| 5561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5562 | goto out; |
| 5563 | } |
| 5564 | tcpcheck->comment = strdup(args[4]); |
| 5565 | } |
| 5566 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5567 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5568 | } |
| 5569 | } |
| 5570 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5571 | if (! *(args[2]) ) { |
| 5572 | /* SEND binary string expected */ |
| 5573 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5574 | file, linenum, args[0], args[1], args[2]); |
| 5575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5576 | goto out; |
| 5577 | } else { |
| 5578 | struct tcpcheck_rule *tcpcheck; |
| 5579 | char *err = NULL; |
| 5580 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5581 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5582 | |
| 5583 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5584 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5585 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5586 | file, linenum, args[0], args[1], args[2], err); |
| 5587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5588 | goto out; |
| 5589 | } |
| 5590 | tcpcheck->expect_regex = NULL; |
| 5591 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5592 | /* comment for this tcpcheck line */ |
| 5593 | if (strcmp(args[3], "comment") == 0) { |
| 5594 | if (!*args[4]) { |
| 5595 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5596 | file, linenum, args[3]); |
| 5597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5598 | goto out; |
| 5599 | } |
| 5600 | tcpcheck->comment = strdup(args[4]); |
| 5601 | } |
| 5602 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5603 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5604 | } |
| 5605 | } |
| 5606 | else if (strcmp(args[1], "expect") == 0) { |
| 5607 | const char *ptr_arg; |
| 5608 | int cur_arg; |
| 5609 | int inverse = 0; |
| 5610 | |
| 5611 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5612 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5614 | goto out; |
| 5615 | } |
| 5616 | |
| 5617 | cur_arg = 2; |
| 5618 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5619 | while (*(ptr_arg = args[cur_arg])) { |
| 5620 | while (*ptr_arg == '!') { |
| 5621 | inverse = !inverse; |
| 5622 | ptr_arg++; |
| 5623 | } |
| 5624 | if (*ptr_arg) |
| 5625 | break; |
| 5626 | cur_arg++; |
| 5627 | } |
| 5628 | /* now ptr_arg points to the beginning of a word past any possible |
| 5629 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5630 | */ |
| 5631 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5632 | struct tcpcheck_rule *tcpcheck; |
| 5633 | char *err = NULL; |
| 5634 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5635 | if (!*(args[cur_arg + 1])) { |
| 5636 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5637 | file, linenum, args[0], args[1], ptr_arg); |
| 5638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5639 | goto out; |
| 5640 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5641 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5642 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5643 | |
| 5644 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5645 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5646 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5647 | file, linenum, args[0], args[1], args[2], err); |
| 5648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5649 | goto out; |
| 5650 | } |
| 5651 | tcpcheck->expect_regex = NULL; |
| 5652 | tcpcheck->inverse = inverse; |
| 5653 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5654 | /* tcpcheck comment */ |
| 5655 | cur_arg += 2; |
| 5656 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5657 | if (!*args[cur_arg + 1]) { |
| 5658 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5659 | file, linenum, args[cur_arg + 1]); |
| 5660 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5661 | goto out; |
| 5662 | } |
| 5663 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5664 | } |
| 5665 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5666 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5667 | } |
| 5668 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5669 | struct tcpcheck_rule *tcpcheck; |
| 5670 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5671 | if (!*(args[cur_arg + 1])) { |
| 5672 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5673 | file, linenum, args[0], args[1], ptr_arg); |
| 5674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5675 | goto out; |
| 5676 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5677 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5678 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5679 | |
| 5680 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5681 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5682 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5683 | tcpcheck->expect_regex = NULL; |
| 5684 | tcpcheck->inverse = inverse; |
| 5685 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5686 | /* tcpcheck comment */ |
| 5687 | cur_arg += 2; |
| 5688 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5689 | if (!*args[cur_arg + 1]) { |
| 5690 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5691 | file, linenum, args[cur_arg + 1]); |
| 5692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5693 | goto out; |
| 5694 | } |
| 5695 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5696 | } |
| 5697 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5698 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5699 | } |
| 5700 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5701 | struct tcpcheck_rule *tcpcheck; |
| 5702 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5703 | if (!*(args[cur_arg + 1])) { |
| 5704 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5705 | file, linenum, args[0], args[1], ptr_arg); |
| 5706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5707 | goto out; |
| 5708 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5709 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5710 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5711 | |
| 5712 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5713 | tcpcheck->string_len = 0; |
| 5714 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5715 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5716 | error = NULL; |
| 5717 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5718 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5719 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5720 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5722 | goto out; |
| 5723 | } |
| 5724 | tcpcheck->inverse = inverse; |
| 5725 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5726 | /* tcpcheck comment */ |
| 5727 | cur_arg += 2; |
| 5728 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5729 | if (!*args[cur_arg + 1]) { |
| 5730 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5731 | file, linenum, args[cur_arg + 1]); |
| 5732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5733 | goto out; |
| 5734 | } |
| 5735 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5736 | } |
| 5737 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5738 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5739 | } |
| 5740 | else { |
| 5741 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5742 | file, linenum, args[0], args[1], ptr_arg); |
| 5743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5744 | goto out; |
| 5745 | } |
| 5746 | } |
| 5747 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5748 | 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] | 5749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5750 | goto out; |
| 5751 | } |
| 5752 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5753 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5754 | if (curproxy == &defproxy) { |
| 5755 | 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] | 5756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5757 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5758 | } |
| 5759 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5760 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5761 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5762 | |
| 5763 | if (strcmp(args[1], "fail") == 0) { |
| 5764 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5765 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5766 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5767 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5769 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5770 | } |
| 5771 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5772 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5773 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5774 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5776 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5777 | } |
| 5778 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5779 | } |
| 5780 | else { |
| 5781 | 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] | 5782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5783 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5784 | } |
| 5785 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5786 | #ifdef TPROXY |
| 5787 | else if (!strcmp(args[0], "transparent")) { |
| 5788 | /* enable transparent proxy connections */ |
| 5789 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5790 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5791 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5792 | } |
| 5793 | #endif |
| 5794 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5795 | 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] | 5796 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5797 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5802 | } |
| 5803 | curproxy->maxconn = 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5806 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5807 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5808 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5809 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5810 | |
| 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 | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5815 | } |
| 5816 | curproxy->backlog = 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 | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5819 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5820 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5821 | 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] | 5822 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5823 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5824 | if (*(args[1]) == 0) { |
| 5825 | 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] | 5826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5827 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5828 | } |
| 5829 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5830 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5831 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5832 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5833 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5834 | if (*(args[1]) == 0) { |
| 5835 | 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] | 5836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5837 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5838 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5839 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5840 | if (err) { |
| 5841 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5842 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5844 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5845 | } |
| 5846 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5847 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5848 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5849 | } |
| 5850 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5851 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5852 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5853 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5854 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5855 | if (curproxy == &defproxy) { |
| 5856 | 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] | 5857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5858 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5859 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5860 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5861 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5862 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 5863 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5864 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5865 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5866 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5867 | goto out; |
| 5868 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5869 | |
| 5870 | proto = protocol_by_family(sk->ss_family); |
| 5871 | if (!proto || !proto->connect) { |
| 5872 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5873 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5874 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5875 | goto out; |
| 5876 | } |
| 5877 | |
| 5878 | if (port1 != port2) { |
| 5879 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5880 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5882 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5883 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5884 | |
| 5885 | if (!port1) { |
| 5886 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5887 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5889 | goto out; |
| 5890 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5891 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5892 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5893 | goto out; |
| 5894 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5895 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5896 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5897 | } |
| 5898 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5899 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5900 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5901 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5902 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5903 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5905 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5906 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5907 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5908 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5909 | /** |
| 5910 | * The syntax for hash-type config element is |
| 5911 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5912 | * |
| 5913 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5914 | */ |
| 5915 | 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] | 5916 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5917 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5918 | err_code |= ERR_WARN; |
| 5919 | |
| 5920 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5921 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5922 | } |
| 5923 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5924 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5925 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5926 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5927 | 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]); |
| 5928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5929 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5930 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5931 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5932 | 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] | 5933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5934 | goto out; |
| 5935 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5936 | |
| 5937 | /* set the hash function to use */ |
| 5938 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5939 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5940 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5941 | |
| 5942 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5943 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5944 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5945 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5946 | /* set the hash function */ |
| 5947 | if (!strcmp(args[2], "sdbm")) { |
| 5948 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5949 | } |
| 5950 | else if (!strcmp(args[2], "djb2")) { |
| 5951 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5952 | } |
| 5953 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5954 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5955 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5956 | else if (!strcmp(args[2], "crc32")) { |
| 5957 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5958 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5959 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5960 | 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] | 5961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5962 | goto out; |
| 5963 | } |
| 5964 | |
| 5965 | /* set the hash modifier */ |
| 5966 | if (!strcmp(args[3], "avalanche")) { |
| 5967 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5968 | } |
| 5969 | else if (*args[3]) { |
| 5970 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5972 | goto out; |
| 5973 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5974 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5975 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 5976 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 5977 | if (*(args[1]) == 0) { |
| 5978 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 5979 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5980 | goto out; |
| 5981 | } |
| 5982 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 5983 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 5984 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 5985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5986 | goto out; |
| 5987 | } |
| 5988 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5989 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5990 | if (!*(args[1])) { |
| 5991 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5993 | goto out; |
| 5994 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5995 | if (*(args[2])) { |
| 5996 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5998 | goto out; |
| 5999 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6000 | free(curproxy->conf.uniqueid_format_string); |
| 6001 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6002 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6003 | free(curproxy->conf.uif_file); |
| 6004 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6005 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6006 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6007 | |
| 6008 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6009 | if (!*(args[1])) { |
| 6010 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6012 | goto out; |
| 6013 | } |
| 6014 | free(curproxy->header_unique_id); |
| 6015 | curproxy->header_unique_id = strdup(args[1]); |
| 6016 | } |
| 6017 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6018 | else if (strcmp(args[0], "log-format") == 0) { |
| 6019 | if (!*(args[1])) { |
| 6020 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6022 | goto out; |
| 6023 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6024 | if (*(args[2])) { |
| 6025 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6027 | goto out; |
| 6028 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6029 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6030 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6031 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6032 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6033 | free(curproxy->conf.logformat_string); |
| 6034 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6035 | |
| 6036 | free(curproxy->conf.lfs_file); |
| 6037 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6038 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6039 | |
| 6040 | /* get a chance to improve log-format error reporting by |
| 6041 | * reporting the correct line-number when possible. |
| 6042 | */ |
| 6043 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6044 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6045 | file, linenum, curproxy->id); |
| 6046 | err_code |= ERR_WARN; |
| 6047 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6048 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6049 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6050 | if (!*(args[1])) { |
| 6051 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6053 | goto out; |
| 6054 | } |
| 6055 | if (*(args[2])) { |
| 6056 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6058 | goto out; |
| 6059 | } |
| 6060 | |
| 6061 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6062 | free(curproxy->conf.logformat_sd_string); |
| 6063 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6064 | |
| 6065 | free(curproxy->conf.lfsd_file); |
| 6066 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6067 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6068 | |
| 6069 | /* get a chance to improve log-format-sd error reporting by |
| 6070 | * reporting the correct line-number when possible. |
| 6071 | */ |
| 6072 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6073 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6074 | file, linenum, curproxy->id); |
| 6075 | err_code |= ERR_WARN; |
| 6076 | } |
| 6077 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6078 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6079 | if (*(args[1]) == 0) { |
| 6080 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 6081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6082 | goto out; |
| 6083 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6084 | chunk_destroy(&curproxy->log_tag); |
| 6085 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6086 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6087 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6088 | /* delete previous herited or defined syslog servers */ |
| 6089 | struct logsrv *back; |
| 6090 | |
| 6091 | if (*(args[1]) != 0) { |
| 6092 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6094 | goto out; |
| 6095 | } |
| 6096 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6097 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6098 | LIST_DEL(&tmplogsrv->list); |
| 6099 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6100 | } |
| 6101 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6102 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6103 | struct logsrv *logsrv; |
| 6104 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6105 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6106 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6107 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6108 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6109 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6110 | LIST_INIT(&node->list); |
| 6111 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6112 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6113 | } |
| 6114 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6115 | struct sockaddr_storage *sk; |
| 6116 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6117 | int arg = 0; |
| 6118 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6119 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6120 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6121 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6122 | /* just after the address, a length may be specified */ |
| 6123 | if (strcmp(args[arg+2], "len") == 0) { |
| 6124 | len = atoi(args[arg+3]); |
| 6125 | if (len < 80 || len > 65535) { |
| 6126 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6127 | file, linenum, args[arg+3]); |
| 6128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6129 | goto out; |
| 6130 | } |
| 6131 | logsrv->maxlen = len; |
| 6132 | |
| 6133 | /* skip these two args */ |
| 6134 | arg += 2; |
| 6135 | } |
| 6136 | else |
| 6137 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6138 | |
| 6139 | if (logsrv->maxlen > global.max_syslog_len) { |
| 6140 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 6141 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 6142 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 6143 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 6144 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6145 | } |
| 6146 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6147 | /* after the length, a format may be specified */ |
| 6148 | if (strcmp(args[arg+2], "format") == 0) { |
| 6149 | logsrv->format = get_log_format(args[arg+3]); |
| 6150 | if (logsrv->format < 0) { |
| 6151 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6152 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6153 | goto out; |
| 6154 | } |
| 6155 | |
| 6156 | /* skip these two args */ |
| 6157 | arg += 2; |
| 6158 | } |
| 6159 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6160 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6161 | goto out; |
| 6162 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6163 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6164 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6165 | 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] | 6166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6167 | goto out; |
| 6168 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6169 | } |
| 6170 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6171 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6172 | if (*(args[arg+3])) { |
| 6173 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6174 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6175 | 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] | 6176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6177 | goto out; |
| 6178 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6182 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6183 | if (*(args[arg+4])) { |
| 6184 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6185 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6186 | 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] | 6187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6188 | goto out; |
| 6189 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6190 | } |
| 6191 | } |
| 6192 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6193 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6194 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6195 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6196 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6197 | goto out; |
| 6198 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6199 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6200 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6201 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6202 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6203 | if (port1 != port2) { |
| 6204 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6205 | file, linenum, args[0], args[1]); |
| 6206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6207 | goto out; |
| 6208 | } |
| 6209 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6210 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6211 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6212 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6213 | |
| 6214 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6215 | } |
| 6216 | else { |
| 6217 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6218 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6220 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | 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] | 6224 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6225 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6226 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6227 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6228 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6229 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6230 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6231 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6232 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6233 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6234 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6236 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6237 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6238 | |
| 6239 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6240 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6241 | free(curproxy->conn_src.iface_name); |
| 6242 | curproxy->conn_src.iface_name = NULL; |
| 6243 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6244 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6245 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6246 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6247 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6248 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6249 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6250 | goto out; |
| 6251 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6252 | |
| 6253 | proto = protocol_by_family(sk->ss_family); |
| 6254 | if (!proto || !proto->connect) { |
| 6255 | 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] | 6256 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6258 | goto out; |
| 6259 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6260 | |
| 6261 | if (port1 != port2) { |
| 6262 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6263 | file, linenum, args[0], args[1]); |
| 6264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6265 | goto out; |
| 6266 | } |
| 6267 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6268 | curproxy->conn_src.source_addr = *sk; |
| 6269 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6270 | |
| 6271 | cur_arg = 2; |
| 6272 | while (*(args[cur_arg])) { |
| 6273 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6274 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6275 | if (!*args[cur_arg + 1]) { |
| 6276 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6277 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6278 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6279 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6283 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6284 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6285 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
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_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6288 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6289 | char *name, *end; |
| 6290 | |
| 6291 | name = args[cur_arg+1] + 7; |
| 6292 | while (isspace(*name)) |
| 6293 | name++; |
| 6294 | |
| 6295 | end = name; |
| 6296 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6297 | end++; |
| 6298 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6299 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6300 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6301 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6302 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6303 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6304 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6305 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6306 | |
| 6307 | /* now look for an occurrence number */ |
| 6308 | while (isspace(*end)) |
| 6309 | end++; |
| 6310 | if (*end == ',') { |
| 6311 | end++; |
| 6312 | name = end; |
| 6313 | if (*end == '-') |
| 6314 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6315 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6316 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6317 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6318 | } |
| 6319 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6320 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6321 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6322 | " occurrences values smaller than %d.\n", |
| 6323 | file, linenum, MAX_HDR_HISTORY); |
| 6324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6325 | goto out; |
| 6326 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6327 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6328 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6329 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6330 | 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] | 6331 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6332 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6333 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6334 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6335 | goto out; |
| 6336 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6337 | |
| 6338 | proto = protocol_by_family(sk->ss_family); |
| 6339 | if (!proto || !proto->connect) { |
| 6340 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6341 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6343 | goto out; |
| 6344 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6345 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6346 | if (port1 != port2) { |
| 6347 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6348 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6350 | goto out; |
| 6351 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6352 | curproxy->conn_src.tproxy_addr = *sk; |
| 6353 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6354 | } |
| 6355 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6356 | #else /* no TPROXY support */ |
| 6357 | 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] | 6358 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6360 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6361 | #endif |
| 6362 | cur_arg += 2; |
| 6363 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6364 | } |
| 6365 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6366 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6367 | #ifdef SO_BINDTODEVICE |
| 6368 | if (!*args[cur_arg + 1]) { |
| 6369 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6370 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6372 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6373 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6374 | free(curproxy->conn_src.iface_name); |
| 6375 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6376 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6377 | global.last_checks |= LSTCHK_NETADM; |
| 6378 | #else |
| 6379 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6380 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6382 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6383 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6384 | cur_arg += 2; |
| 6385 | continue; |
| 6386 | } |
| 6387 | 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] | 6388 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6390 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6392 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6393 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6394 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6395 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6397 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6398 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6399 | 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] | 6400 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6401 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6402 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6405 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6406 | |
| 6407 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6408 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6409 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6410 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6411 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6412 | } |
| 6413 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6414 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6415 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6416 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6417 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6418 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6419 | } |
| 6420 | 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] | 6421 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6422 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6423 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6424 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6425 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6426 | } |
| 6427 | 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] | 6428 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6429 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6430 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6431 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6432 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6433 | } |
| 6434 | 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] | 6435 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6436 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6437 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6438 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6439 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6440 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6441 | 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] | 6442 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6443 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6444 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6445 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6446 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6447 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6448 | 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] | 6449 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6450 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6451 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6453 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6454 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6455 | |
| 6456 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6457 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6458 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6459 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6460 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6461 | } |
| 6462 | 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] | 6463 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6464 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6465 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6466 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6467 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6468 | } |
| 6469 | 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] | 6470 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6471 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6472 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6473 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6474 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6475 | } |
| 6476 | 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] | 6477 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6478 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6479 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6480 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6481 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6482 | } |
| 6483 | 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] | 6484 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6485 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6486 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6487 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6488 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6489 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6490 | 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] | 6491 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6492 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6493 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6494 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6495 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6496 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6497 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6498 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6499 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6500 | if (curproxy == &defproxy) { |
| 6501 | 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] | 6502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6503 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6504 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6505 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6506 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6507 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6508 | if (*(args[1]) == 0) { |
| 6509 | 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] | 6510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6512 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6513 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6514 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6515 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6516 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6517 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6519 | goto out; |
| 6520 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6521 | err_code |= warnif_cond_conflicts(cond, |
| 6522 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6523 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6524 | } |
| 6525 | else if (*args[2]) { |
| 6526 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6527 | file, linenum, args[0], args[2]); |
| 6528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6529 | goto out; |
| 6530 | } |
| 6531 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6532 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6533 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6534 | wl->s = strdup(args[1]); |
| 6535 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6536 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6537 | } |
| 6538 | 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] | 6539 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6540 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6541 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6542 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6544 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6545 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6546 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6547 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6548 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6549 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6551 | } |
| 6552 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6553 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6554 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6555 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6556 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6557 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6558 | } |
| 6559 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6560 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6561 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6562 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6563 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6564 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6565 | } |
| 6566 | 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] | 6567 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6568 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6569 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6571 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6572 | } |
| 6573 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6574 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6575 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6576 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6577 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6578 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6579 | } |
| 6580 | 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] | 6581 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6582 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6583 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6584 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6585 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6586 | } |
| 6587 | 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] | 6588 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6589 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6590 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6591 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6593 | } |
| 6594 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6595 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6596 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6597 | if (curproxy == &defproxy) { |
| 6598 | 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] | 6599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6600 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6601 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6602 | else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6603 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6604 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6605 | if (*(args[1]) == 0) { |
| 6606 | 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] | 6607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6609 | } |
| 6610 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6611 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6612 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6613 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6614 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6616 | goto out; |
| 6617 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6618 | err_code |= warnif_cond_conflicts(cond, |
| 6619 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6620 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6621 | } |
| 6622 | else if (*args[2]) { |
| 6623 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6624 | file, linenum, args[0], args[2]); |
| 6625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6626 | goto out; |
| 6627 | } |
| 6628 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6629 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6630 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6631 | wl->s = strdup(args[1]); |
| 6632 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6633 | } |
| 6634 | else if (!strcmp(args[0], "errorloc") || |
| 6635 | !strcmp(args[0], "errorloc302") || |
| 6636 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6637 | int errnum, errlen; |
| 6638 | char *err; |
| 6639 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6640 | 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] | 6641 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6642 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6643 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6644 | 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] | 6645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6646 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | errnum = atol(args[1]); |
| 6650 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6651 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6652 | err = malloc(errlen); |
| 6653 | 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] | 6654 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6655 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6656 | err = malloc(errlen); |
| 6657 | 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] | 6658 | } |
| 6659 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6660 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6661 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6662 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6663 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6664 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6666 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6667 | |
| 6668 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6669 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6670 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6671 | free(err); |
| 6672 | } |
| 6673 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6674 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6675 | int errnum, errlen, fd; |
| 6676 | char *err; |
| 6677 | struct stat stat; |
| 6678 | |
| 6679 | 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] | 6680 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6681 | |
| 6682 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6683 | 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] | 6684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6685 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | fd = open(args[2], O_RDONLY); |
| 6689 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6690 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6691 | file, linenum, args[2], args[1]); |
| 6692 | if (fd >= 0) |
| 6693 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6695 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6696 | } |
| 6697 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6698 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6699 | errlen = stat.st_size; |
| 6700 | } else { |
| 6701 | 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] | 6702 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6703 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6704 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6708 | errnum = read(fd, err, errlen); |
| 6709 | if (errnum != errlen) { |
| 6710 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6711 | file, linenum, args[2], args[1]); |
| 6712 | close(fd); |
| 6713 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6715 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6716 | } |
| 6717 | close(fd); |
| 6718 | |
| 6719 | errnum = atol(args[1]); |
| 6720 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6721 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6722 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6723 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6724 | break; |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6729 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6730 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6731 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6732 | free(err); |
| 6733 | } |
| 6734 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6735 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6736 | struct cfg_kw_list *kwl; |
| 6737 | int index; |
| 6738 | |
| 6739 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6740 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6741 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6742 | continue; |
| 6743 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6744 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6745 | 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] | 6746 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6747 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6749 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6750 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6751 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6752 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6753 | err_code |= ERR_WARN; |
| 6754 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6755 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6756 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6760 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6761 | 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] | 6762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6764 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6765 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6766 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6767 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6768 | } |
| 6769 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6770 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6771 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6772 | { |
| 6773 | #ifdef CONFIG_HAP_NS |
| 6774 | const char *err; |
| 6775 | const char *item = args[0]; |
| 6776 | |
| 6777 | if (!strcmp(item, "namespace_list")) { |
| 6778 | return 0; |
| 6779 | } |
| 6780 | else if (!strcmp(item, "namespace")) { |
| 6781 | size_t idx = 1; |
| 6782 | const char *current; |
| 6783 | while (*(current = args[idx++])) { |
| 6784 | err = invalid_char(current); |
| 6785 | if (err) { |
| 6786 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6787 | file, linenum, *err, item, current); |
| 6788 | return ERR_ALERT | ERR_FATAL; |
| 6789 | } |
| 6790 | |
| 6791 | if (netns_store_lookup(current, strlen(current))) { |
| 6792 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6793 | file, linenum, current); |
| 6794 | return ERR_ALERT | ERR_FATAL; |
| 6795 | } |
| 6796 | if (!netns_store_insert(current)) { |
| 6797 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6798 | file, linenum, current); |
| 6799 | return ERR_ALERT | ERR_FATAL; |
| 6800 | } |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | return 0; |
| 6805 | #else |
| 6806 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6807 | file, linenum); |
| 6808 | return ERR_ALERT | ERR_FATAL; |
| 6809 | #endif |
| 6810 | } |
| 6811 | |
| 6812 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6813 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6814 | { |
| 6815 | |
| 6816 | int err_code = 0; |
| 6817 | const char *err; |
| 6818 | |
| 6819 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6820 | struct userlist *newul; |
| 6821 | |
| 6822 | if (!*args[1]) { |
| 6823 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6824 | file, linenum, args[0]); |
| 6825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6826 | goto out; |
| 6827 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6828 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6829 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6830 | |
| 6831 | err = invalid_char(args[1]); |
| 6832 | if (err) { |
| 6833 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6834 | file, linenum, *err, args[0], args[1]); |
| 6835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6836 | goto out; |
| 6837 | } |
| 6838 | |
| 6839 | for (newul = userlist; newul; newul = newul->next) |
| 6840 | if (!strcmp(newul->name, args[1])) { |
| 6841 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6842 | file, linenum, args[1]); |
| 6843 | err_code |= ERR_WARN; |
| 6844 | goto out; |
| 6845 | } |
| 6846 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6847 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6848 | if (!newul) { |
| 6849 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6850 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6851 | goto out; |
| 6852 | } |
| 6853 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6854 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6855 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6856 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6857 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6858 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6859 | goto out; |
| 6860 | } |
| 6861 | |
| 6862 | newul->next = userlist; |
| 6863 | userlist = newul; |
| 6864 | |
| 6865 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6866 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6867 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6868 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6869 | |
| 6870 | if (!*args[1]) { |
| 6871 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6872 | file, linenum, args[0]); |
| 6873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6874 | goto out; |
| 6875 | } |
| 6876 | |
| 6877 | err = invalid_char(args[1]); |
| 6878 | if (err) { |
| 6879 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6880 | file, linenum, *err, args[0], args[1]); |
| 6881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6882 | goto out; |
| 6883 | } |
| 6884 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6885 | if (!userlist) |
| 6886 | goto out; |
| 6887 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6888 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6889 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6890 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6891 | file, linenum, args[1], userlist->name); |
| 6892 | err_code |= ERR_ALERT; |
| 6893 | goto out; |
| 6894 | } |
| 6895 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6896 | ag = calloc(1, sizeof(*ag)); |
| 6897 | if (!ag) { |
| 6898 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6899 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6900 | goto out; |
| 6901 | } |
| 6902 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6903 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6904 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6905 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6906 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6907 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6908 | goto out; |
| 6909 | } |
| 6910 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6911 | cur_arg = 2; |
| 6912 | |
| 6913 | while (*args[cur_arg]) { |
| 6914 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6915 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6916 | cur_arg += 2; |
| 6917 | continue; |
| 6918 | } else { |
| 6919 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6920 | file, linenum, args[0]); |
| 6921 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6922 | free(ag->groupusers); |
| 6923 | free(ag->name); |
| 6924 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6925 | goto out; |
| 6926 | } |
| 6927 | } |
| 6928 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6929 | ag->next = userlist->groups; |
| 6930 | userlist->groups = ag; |
| 6931 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6932 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6933 | struct auth_users *newuser; |
| 6934 | int cur_arg; |
| 6935 | |
| 6936 | if (!*args[1]) { |
| 6937 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6938 | file, linenum, args[0]); |
| 6939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6940 | goto out; |
| 6941 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6942 | if (!userlist) |
| 6943 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6944 | |
| 6945 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6946 | if (!strcmp(newuser->user, args[1])) { |
| 6947 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6948 | file, linenum, args[1], userlist->name); |
| 6949 | err_code |= ERR_ALERT; |
| 6950 | goto out; |
| 6951 | } |
| 6952 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6953 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6954 | if (!newuser) { |
| 6955 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6956 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6957 | goto out; |
| 6958 | } |
| 6959 | |
| 6960 | newuser->user = strdup(args[1]); |
| 6961 | |
| 6962 | newuser->next = userlist->users; |
| 6963 | userlist->users = newuser; |
| 6964 | |
| 6965 | cur_arg = 2; |
| 6966 | |
| 6967 | while (*args[cur_arg]) { |
| 6968 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6969 | #ifdef CONFIG_HAP_CRYPT |
| 6970 | if (!crypt("", args[cur_arg + 1])) { |
| 6971 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6972 | file, linenum, newuser->user); |
| 6973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6974 | goto out; |
| 6975 | } |
| 6976 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6977 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6978 | file, linenum); |
| 6979 | err_code |= ERR_ALERT; |
| 6980 | #endif |
| 6981 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6982 | cur_arg += 2; |
| 6983 | continue; |
| 6984 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6985 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6986 | newuser->flags |= AU_O_INSECURE; |
| 6987 | cur_arg += 2; |
| 6988 | continue; |
| 6989 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6990 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6991 | cur_arg += 2; |
| 6992 | continue; |
| 6993 | } else { |
| 6994 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6995 | file, linenum, args[0]); |
| 6996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6997 | goto out; |
| 6998 | } |
| 6999 | } |
| 7000 | } else { |
| 7001 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 7002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7003 | } |
| 7004 | |
| 7005 | out: |
| 7006 | return err_code; |
| 7007 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7008 | |
| 7009 | /* |
| 7010 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7011 | * Returns the error code, 0 if OK, or any combination of : |
| 7012 | * - ERR_ABORT: must abort ASAP |
| 7013 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7014 | * - ERR_WARN: a warning has been emitted |
| 7015 | * - ERR_ALERT: an alert has been emitted |
| 7016 | * Only the two first ones can stop processing, the two others are just |
| 7017 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7018 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7019 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7020 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7021 | char *thisline; |
| 7022 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7023 | FILE *f; |
| 7024 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7025 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7026 | struct cfg_section *cs = NULL; |
| 7027 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7028 | int readbytes = 0; |
| 7029 | |
| 7030 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7031 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7032 | return -1; |
| 7033 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7034 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7035 | if ((f=fopen(file,"r")) == NULL) { |
| 7036 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7037 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7038 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7039 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7040 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7041 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7042 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7043 | char *end; |
| 7044 | char *args[MAX_LINE_ARGS + 1]; |
| 7045 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7046 | int dquote = 0; /* double quote */ |
| 7047 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7048 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7049 | linenum++; |
| 7050 | |
| 7051 | end = line + strlen(line); |
| 7052 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7053 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7054 | /* Check if we reached the limit and the last char is not \n. |
| 7055 | * Watch out for the last line without the terminating '\n'! |
| 7056 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7057 | char *newline; |
| 7058 | int newlinesize = linesize * 2; |
| 7059 | |
| 7060 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7061 | if (newline == NULL) { |
| 7062 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7063 | file, linenum); |
| 7064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7065 | continue; |
| 7066 | } |
| 7067 | |
| 7068 | readbytes = linesize - 1; |
| 7069 | linesize = newlinesize; |
| 7070 | thisline = newline; |
| 7071 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7072 | } |
| 7073 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7074 | readbytes = 0; |
| 7075 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7076 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7077 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7078 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7079 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7080 | arg = 0; |
| 7081 | args[arg] = line; |
| 7082 | |
| 7083 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7084 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7085 | if (dquote) |
| 7086 | dquote = 0; |
| 7087 | else |
| 7088 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7089 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7090 | end--; |
| 7091 | } |
| 7092 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7093 | if (squote) |
| 7094 | squote = 0; |
| 7095 | else |
| 7096 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7097 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7098 | end--; |
| 7099 | } |
| 7100 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7101 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7102 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7103 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7104 | int skip = 0; |
| 7105 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7106 | *line = line[1]; |
| 7107 | skip = 1; |
| 7108 | } |
| 7109 | else if (line[1] == 'r') { |
| 7110 | *line = '\r'; |
| 7111 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7112 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7113 | else if (line[1] == 'n') { |
| 7114 | *line = '\n'; |
| 7115 | skip = 1; |
| 7116 | } |
| 7117 | else if (line[1] == 't') { |
| 7118 | *line = '\t'; |
| 7119 | skip = 1; |
| 7120 | } |
| 7121 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7122 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7123 | unsigned char hex1, hex2; |
| 7124 | hex1 = toupper(line[2]) - '0'; |
| 7125 | hex2 = toupper(line[3]) - '0'; |
| 7126 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7127 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7128 | *line = (hex1<<4) + hex2; |
| 7129 | skip = 3; |
| 7130 | } |
| 7131 | else { |
| 7132 | 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] | 7133 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7134 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7135 | } else if (line[1] == '"') { |
| 7136 | *line = '"'; |
| 7137 | skip = 1; |
| 7138 | } else if (line[1] == '\'') { |
| 7139 | *line = '\''; |
| 7140 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7141 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7142 | *line = '$'; |
| 7143 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7144 | } |
| 7145 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7146 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7147 | end -= skip; |
| 7148 | } |
| 7149 | line++; |
| 7150 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7151 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7152 | /* end of string, end of loop */ |
| 7153 | *line = 0; |
| 7154 | break; |
| 7155 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7156 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7157 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7158 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7159 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7160 | line++; |
| 7161 | args[++arg] = line; |
| 7162 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7163 | else if (dquote && *line == '$') { |
| 7164 | /* environment variables are evaluated inside double quotes */ |
| 7165 | char *var_beg; |
| 7166 | char *var_end; |
| 7167 | char save_char; |
| 7168 | char *value; |
| 7169 | int val_len; |
| 7170 | int newlinesize; |
| 7171 | int braces = 0; |
| 7172 | |
| 7173 | var_beg = line + 1; |
| 7174 | var_end = var_beg; |
| 7175 | |
| 7176 | if (*var_beg == '{') { |
| 7177 | var_beg++; |
| 7178 | var_end++; |
| 7179 | braces = 1; |
| 7180 | } |
| 7181 | |
| 7182 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7183 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7185 | goto next_line; /* skip current line */ |
| 7186 | } |
| 7187 | |
| 7188 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7189 | var_end++; |
| 7190 | |
| 7191 | save_char = *var_end; |
| 7192 | *var_end = '\0'; |
| 7193 | value = getenv(var_beg); |
| 7194 | *var_end = save_char; |
| 7195 | val_len = value ? strlen(value) : 0; |
| 7196 | |
| 7197 | if (braces) { |
| 7198 | if (*var_end == '}') { |
| 7199 | var_end++; |
| 7200 | braces = 0; |
| 7201 | } else { |
| 7202 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7204 | goto next_line; /* skip current line */ |
| 7205 | } |
| 7206 | } |
| 7207 | |
| 7208 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7209 | |
| 7210 | /* if not enough space in thisline */ |
| 7211 | if (newlinesize > linesize) { |
| 7212 | char *newline; |
| 7213 | |
| 7214 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7215 | if (newline == NULL) { |
| 7216 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7218 | goto next_line; /* slip current line */ |
| 7219 | } |
| 7220 | /* recompute pointers if realloc returns a new pointer */ |
| 7221 | if (newline != thisline) { |
| 7222 | int i; |
| 7223 | int diff; |
| 7224 | |
| 7225 | for (i = 0; i <= arg; i++) { |
| 7226 | diff = args[i] - thisline; |
| 7227 | args[i] = newline + diff; |
| 7228 | } |
| 7229 | |
| 7230 | diff = var_end - thisline; |
| 7231 | var_end = newline + diff; |
| 7232 | diff = end - thisline; |
| 7233 | end = newline + diff; |
| 7234 | diff = line - thisline; |
| 7235 | line = newline + diff; |
| 7236 | thisline = newline; |
| 7237 | } |
| 7238 | linesize = newlinesize; |
| 7239 | } |
| 7240 | |
| 7241 | /* insert value inside the line */ |
| 7242 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7243 | memcpy(line, value, val_len); |
| 7244 | end += val_len - (var_end - line); |
| 7245 | line += val_len; |
| 7246 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7247 | else { |
| 7248 | line++; |
| 7249 | } |
| 7250 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7251 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7252 | if (dquote) { |
| 7253 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7255 | } |
| 7256 | |
| 7257 | if (squote) { |
| 7258 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7260 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7261 | |
| 7262 | /* empty line */ |
| 7263 | if (!**args) |
| 7264 | continue; |
| 7265 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7266 | if (*line) { |
| 7267 | /* we had to stop due to too many args. |
| 7268 | * Let's terminate the string, print the offending part then cut the |
| 7269 | * last arg. |
| 7270 | */ |
| 7271 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7272 | line++; |
| 7273 | *line = '\0'; |
| 7274 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7275 | 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] | 7276 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7278 | args[arg] = line; |
| 7279 | } |
| 7280 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7281 | /* zero out remaining args and ensure that at least one entry |
| 7282 | * is zeroed out. |
| 7283 | */ |
| 7284 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7285 | args[arg] = line; |
| 7286 | } |
| 7287 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7288 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7289 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7290 | char *tmp; |
| 7291 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7292 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7293 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7294 | for (arg=0; *args[arg+1]; arg++) |
| 7295 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7296 | *tmp = '\0'; // fix the next arg to \0 |
| 7297 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7298 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7299 | else if (!strcmp(args[0], "default")) { |
| 7300 | kwm = KWM_DEF; |
| 7301 | for (arg=0; *args[arg+1]; arg++) |
| 7302 | args[arg] = args[arg+1]; // shift args after inversion |
| 7303 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7304 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7305 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7306 | strcmp(args[0], "log") != 0) { |
| 7307 | 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] | 7308 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7309 | } |
| 7310 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7311 | /* detect section start */ |
| 7312 | list_for_each_entry(ics, §ions, list) { |
| 7313 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7314 | cursection = ics->section_name; |
| 7315 | cs = ics; |
| 7316 | break; |
| 7317 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7318 | } |
| 7319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7320 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7321 | if (cs) |
| 7322 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7323 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7324 | 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] | 7325 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7326 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7327 | |
| 7328 | if (err_code & ERR_ABORT) |
| 7329 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7330 | } |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7331 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7332 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7333 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7334 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7335 | } |
| 7336 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7337 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7338 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7339 | * bound to all of its processes. After that, if the target is a "listen" |
| 7340 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7341 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7342 | * checked first to ensure that <to> is already bound to all processes of |
| 7343 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7344 | * path to the destination. |
| 7345 | * |
| 7346 | * It is possible to set <to> to NULL for the first call so that the function |
| 7347 | * takes care of visiting the initial frontend in <from>. |
| 7348 | * |
| 7349 | * It is important to note that the function relies on the fact that all names |
| 7350 | * have already been resolved. |
| 7351 | */ |
| 7352 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7353 | { |
| 7354 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7355 | |
| 7356 | if (to) { |
| 7357 | /* check whether we need to go down */ |
| 7358 | if (from->bind_proc && |
| 7359 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7360 | return; |
| 7361 | |
| 7362 | if (!from->bind_proc && !to->bind_proc) |
| 7363 | return; |
| 7364 | |
| 7365 | to->bind_proc = from->bind_proc ? |
| 7366 | (to->bind_proc | from->bind_proc) : 0; |
| 7367 | |
| 7368 | /* now propagate down */ |
| 7369 | from = to; |
| 7370 | } |
| 7371 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7372 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7373 | return; |
| 7374 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7375 | if (from->state == PR_STSTOPPED) |
| 7376 | return; |
| 7377 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7378 | /* default_backend */ |
| 7379 | if (from->defbe.be) |
| 7380 | propagate_processes(from, from->defbe.be); |
| 7381 | |
| 7382 | /* use_backend */ |
| 7383 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7384 | if (rule->dynamic) |
| 7385 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7386 | to = rule->be.backend; |
| 7387 | propagate_processes(from, to); |
| 7388 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7389 | } |
| 7390 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7391 | /* |
| 7392 | * Returns the error code, 0 if OK, or any combination of : |
| 7393 | * - ERR_ABORT: must abort ASAP |
| 7394 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7395 | * - ERR_WARN: a warning has been emitted |
| 7396 | * - ERR_ALERT: an alert has been emitted |
| 7397 | * Only the two first ones can stop processing, the two others are just |
| 7398 | * indicators. |
| 7399 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7400 | int check_config_validity() |
| 7401 | { |
| 7402 | int cfgerr = 0; |
| 7403 | struct proxy *curproxy = NULL; |
| 7404 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7405 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7406 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7407 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7408 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7409 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7410 | /* |
| 7411 | * Now, check for the integrity of all that we have collected. |
| 7412 | */ |
| 7413 | |
| 7414 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7415 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7416 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7417 | if (!global.tune.max_http_hdr) |
| 7418 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7419 | |
| 7420 | if (!global.tune.cookie_len) |
| 7421 | global.tune.cookie_len = CAPTURE_LEN; |
| 7422 | |
| 7423 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7424 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7425 | /* Post initialisation of the users and groups lists. */ |
| 7426 | err_code = userlist_postinit(); |
| 7427 | if (err_code != ERR_NONE) |
| 7428 | goto out; |
| 7429 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7430 | /* first, we will invert the proxy list order */ |
| 7431 | curproxy = NULL; |
| 7432 | while (proxy) { |
| 7433 | struct proxy *next; |
| 7434 | |
| 7435 | next = proxy->next; |
| 7436 | proxy->next = curproxy; |
| 7437 | curproxy = proxy; |
| 7438 | if (!next) |
| 7439 | break; |
| 7440 | proxy = next; |
| 7441 | } |
| 7442 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7443 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7444 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7445 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7446 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7447 | struct act_rule *trule; |
| 7448 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7449 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7450 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7451 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7452 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7453 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7454 | /* proxy ID not set, use automatic numbering with first |
| 7455 | * spare entry starting with next_pxid. |
| 7456 | */ |
| 7457 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7458 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7459 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7460 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7461 | next_pxid++; |
| 7462 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7463 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7464 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7465 | /* ensure we don't keep listeners uselessly bound */ |
| 7466 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7467 | free((void *)curproxy->table.peers.name); |
| 7468 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7469 | continue; |
| 7470 | } |
| 7471 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7472 | /* Check multi-process mode compatibility for the current proxy */ |
| 7473 | |
| 7474 | if (curproxy->bind_proc) { |
| 7475 | /* an explicit bind-process was specified, let's check how many |
| 7476 | * processes remain. |
| 7477 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7478 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7479 | |
| 7480 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7481 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7482 | 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); |
| 7483 | curproxy->bind_proc = 1; |
| 7484 | } |
| 7485 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7486 | 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); |
| 7487 | curproxy->bind_proc = 0; |
| 7488 | } |
| 7489 | } |
| 7490 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7491 | /* check and reduce the bind-proc of each listener */ |
| 7492 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7493 | unsigned long mask; |
| 7494 | |
| 7495 | if (!bind_conf->bind_proc) |
| 7496 | continue; |
| 7497 | |
| 7498 | mask = nbits(global.nbproc); |
| 7499 | if (curproxy->bind_proc) |
| 7500 | mask &= curproxy->bind_proc; |
| 7501 | /* mask cannot be null here thanks to the previous checks */ |
| 7502 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7503 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7504 | bind_conf->bind_proc &= mask; |
| 7505 | |
| 7506 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7507 | 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", |
| 7508 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7509 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7510 | } |
| 7511 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7512 | 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", |
| 7513 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7514 | bind_conf->bind_proc = 0; |
| 7515 | } |
| 7516 | } |
| 7517 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7518 | switch (curproxy->mode) { |
| 7519 | case PR_MODE_HEALTH: |
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 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7522 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7523 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7524 | cfgerr++; |
| 7525 | } |
| 7526 | |
| 7527 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7528 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7529 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7530 | break; |
| 7531 | |
| 7532 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7533 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7534 | break; |
| 7535 | |
| 7536 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7537 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7538 | break; |
| 7539 | } |
| 7540 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7541 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7542 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7543 | proxy_type_str(curproxy), curproxy->id); |
| 7544 | err_code |= ERR_WARN; |
| 7545 | } |
| 7546 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7547 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7548 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7549 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7550 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7551 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7552 | cfgerr++; |
| 7553 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7554 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7555 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7556 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7557 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7558 | cfgerr++; |
| 7559 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7560 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7561 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7562 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7563 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7564 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7565 | } |
| 7566 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7567 | 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] | 7568 | /* If no LB algo is set in a backend, and we're not in |
| 7569 | * transparent mode, dispatch mode nor proxy mode, we |
| 7570 | * want to use balance roundrobin by default. |
| 7571 | */ |
| 7572 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7573 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7574 | } |
| 7575 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7576 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7577 | if (curproxy->options & PR_O_DISPATCH) |
| 7578 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7579 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7580 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7581 | else if (curproxy->options & PR_O_TRANSP) |
| 7582 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7583 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7584 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7585 | if (curproxy->options & PR_O_DISABLE404) { |
| 7586 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7587 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7588 | err_code |= ERR_WARN; |
| 7589 | curproxy->options &= ~PR_O_DISABLE404; |
| 7590 | } |
| 7591 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7592 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7593 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7594 | err_code |= ERR_WARN; |
| 7595 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7596 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7597 | } |
| 7598 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7599 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7600 | if (!global.external_check) { |
| 7601 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7602 | curproxy->id, "option external-check"); |
| 7603 | cfgerr++; |
| 7604 | } |
| 7605 | if (!curproxy->check_command) { |
| 7606 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7607 | curproxy->id, "option external-check"); |
| 7608 | cfgerr++; |
| 7609 | } |
| 7610 | } |
| 7611 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7612 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7613 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7614 | 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] | 7615 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7616 | "'email-alert myhostname', or 'email-alert to' " |
| 7617 | "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] | 7618 | "to be present).\n", |
| 7619 | proxy_type_str(curproxy), curproxy->id); |
| 7620 | err_code |= ERR_WARN; |
| 7621 | free_email_alert(curproxy); |
| 7622 | } |
| 7623 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7624 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7625 | } |
| 7626 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7627 | if (curproxy->check_command) { |
| 7628 | int clear = 0; |
| 7629 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7630 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7631 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7632 | err_code |= ERR_WARN; |
| 7633 | clear = 1; |
| 7634 | } |
| 7635 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7636 | 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] | 7637 | curproxy->id, "external-check command"); |
| 7638 | cfgerr++; |
| 7639 | } |
| 7640 | if (clear) { |
| 7641 | free(curproxy->check_command); |
| 7642 | curproxy->check_command = NULL; |
| 7643 | } |
| 7644 | } |
| 7645 | |
| 7646 | if (curproxy->check_path) { |
| 7647 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7648 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7649 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7650 | err_code |= ERR_WARN; |
| 7651 | free(curproxy->check_path); |
| 7652 | curproxy->check_path = NULL; |
| 7653 | } |
| 7654 | } |
| 7655 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7656 | /* if a default backend was specified, let's find it */ |
| 7657 | if (curproxy->defbe.name) { |
| 7658 | struct proxy *target; |
| 7659 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7660 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7661 | if (!target) { |
| 7662 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7663 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7664 | cfgerr++; |
| 7665 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7666 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7667 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7668 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7669 | } else if (target->mode != curproxy->mode && |
| 7670 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7671 | |
| 7672 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7673 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7674 | curproxy->conf.file, curproxy->conf.line, |
| 7675 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7676 | target->conf.file, target->conf.line); |
| 7677 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7678 | } else { |
| 7679 | free(curproxy->defbe.name); |
| 7680 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7681 | |
| 7682 | /* Emit a warning if this proxy also has some servers */ |
| 7683 | if (curproxy->srv) { |
| 7684 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7685 | curproxy->id); |
| 7686 | err_code |= ERR_WARN; |
| 7687 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7688 | } |
| 7689 | } |
| 7690 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7691 | /* find the target proxy for 'use_backend' rules */ |
| 7692 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7693 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7694 | struct logformat_node *node; |
| 7695 | char *pxname; |
| 7696 | |
| 7697 | /* Try to parse the string as a log format expression. If the result |
| 7698 | * of the parsing is only one entry containing a simple string, then |
| 7699 | * it's a standard string corresponding to a static rule, thus the |
| 7700 | * parsing is cancelled and be.name is restored to be resolved. |
| 7701 | */ |
| 7702 | pxname = rule->be.name; |
| 7703 | LIST_INIT(&rule->be.expr); |
| 7704 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 7705 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 7706 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7707 | |
| 7708 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7709 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7710 | rule->dynamic = 1; |
| 7711 | free(pxname); |
| 7712 | continue; |
| 7713 | } |
| 7714 | /* simple string: free the expression and fall back to static rule */ |
| 7715 | free(node->arg); |
| 7716 | free(node); |
| 7717 | } |
| 7718 | |
| 7719 | rule->dynamic = 0; |
| 7720 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7721 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7722 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7723 | if (!target) { |
| 7724 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7725 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7726 | cfgerr++; |
| 7727 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7728 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7729 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7730 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7731 | } else if (target->mode != curproxy->mode && |
| 7732 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7733 | |
| 7734 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7735 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7736 | curproxy->conf.file, curproxy->conf.line, |
| 7737 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7738 | target->conf.file, target->conf.line); |
| 7739 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7740 | } else { |
| 7741 | free((void *)rule->be.name); |
| 7742 | rule->be.backend = target; |
| 7743 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7744 | } |
| 7745 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7746 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7747 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7748 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7749 | |
| 7750 | if (!target) { |
| 7751 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7752 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7753 | cfgerr++; |
| 7754 | continue; |
| 7755 | } |
| 7756 | free((void *)srule->srv.name); |
| 7757 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7758 | } |
| 7759 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7760 | /* find the target table for 'stick' rules */ |
| 7761 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7762 | struct proxy *target; |
| 7763 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7764 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7765 | if (mrule->flags & STK_IS_STORE) |
| 7766 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7767 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7768 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7769 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7770 | else |
| 7771 | target = curproxy; |
| 7772 | |
| 7773 | if (!target) { |
| 7774 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7775 | curproxy->id, mrule->table.name); |
| 7776 | cfgerr++; |
| 7777 | } |
| 7778 | else if (target->table.size == 0) { |
| 7779 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7780 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7781 | cfgerr++; |
| 7782 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7783 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7784 | 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] | 7785 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7786 | cfgerr++; |
| 7787 | } |
| 7788 | else { |
| 7789 | free((void *)mrule->table.name); |
| 7790 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7791 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7792 | } |
| 7793 | } |
| 7794 | |
| 7795 | /* find the target table for 'store response' rules */ |
| 7796 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7797 | struct proxy *target; |
| 7798 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7799 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7800 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7801 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7802 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7803 | else |
| 7804 | target = curproxy; |
| 7805 | |
| 7806 | if (!target) { |
| 7807 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7808 | curproxy->id, mrule->table.name); |
| 7809 | cfgerr++; |
| 7810 | } |
| 7811 | else if (target->table.size == 0) { |
| 7812 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7813 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7814 | cfgerr++; |
| 7815 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7816 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7817 | 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] | 7818 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7819 | cfgerr++; |
| 7820 | } |
| 7821 | else { |
| 7822 | free((void *)mrule->table.name); |
| 7823 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7824 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7828 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7829 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7830 | struct proxy *target; |
| 7831 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7832 | 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] | 7833 | continue; |
| 7834 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7835 | if (trule->arg.trk_ctr.table.n) |
| 7836 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7837 | else |
| 7838 | target = curproxy; |
| 7839 | |
| 7840 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7841 | 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] | 7842 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7843 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7844 | cfgerr++; |
| 7845 | } |
| 7846 | else if (target->table.size == 0) { |
| 7847 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7848 | 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] | 7849 | cfgerr++; |
| 7850 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7851 | 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] | 7852 | 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] | 7853 | 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] | 7854 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7855 | cfgerr++; |
| 7856 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7857 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7858 | free(trule->arg.trk_ctr.table.n); |
| 7859 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7860 | /* 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] | 7861 | * to pass a list of counters to track and allocate them right here using |
| 7862 | * stktable_alloc_data_type(). |
| 7863 | */ |
| 7864 | } |
| 7865 | } |
| 7866 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7867 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7868 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7869 | struct proxy *target; |
| 7870 | |
| 7871 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7872 | continue; |
| 7873 | |
| 7874 | if (trule->arg.trk_ctr.table.n) |
| 7875 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7876 | else |
| 7877 | target = curproxy; |
| 7878 | |
| 7879 | if (!target) { |
| 7880 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7881 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7882 | tcp_trk_idx(trule->action)); |
| 7883 | cfgerr++; |
| 7884 | } |
| 7885 | else if (target->table.size == 0) { |
| 7886 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7887 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7888 | cfgerr++; |
| 7889 | } |
| 7890 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7891 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7892 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7893 | tcp_trk_idx(trule->action)); |
| 7894 | cfgerr++; |
| 7895 | } |
| 7896 | else { |
| 7897 | free(trule->arg.trk_ctr.table.n); |
| 7898 | trule->arg.trk_ctr.table.t = &target->table; |
| 7899 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7900 | * to pass a list of counters to track and allocate them right here using |
| 7901 | * stktable_alloc_data_type(). |
| 7902 | */ |
| 7903 | } |
| 7904 | } |
| 7905 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7906 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7907 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7908 | struct proxy *target; |
| 7909 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7910 | 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] | 7911 | continue; |
| 7912 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7913 | if (trule->arg.trk_ctr.table.n) |
| 7914 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7915 | else |
| 7916 | target = curproxy; |
| 7917 | |
| 7918 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7919 | 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] | 7920 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7921 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7922 | cfgerr++; |
| 7923 | } |
| 7924 | else if (target->table.size == 0) { |
| 7925 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7926 | 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] | 7927 | cfgerr++; |
| 7928 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7929 | 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] | 7930 | 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] | 7931 | 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] | 7932 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7933 | cfgerr++; |
| 7934 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7935 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7936 | free(trule->arg.trk_ctr.table.n); |
| 7937 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7938 | /* 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] | 7939 | * to pass a list of counters to track and allocate them right here using |
| 7940 | * stktable_alloc_data_type(). |
| 7941 | */ |
| 7942 | } |
| 7943 | } |
| 7944 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7945 | /* parse http-request capture rules to ensure id really exists */ |
| 7946 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7947 | if (hrqrule->action != ACT_CUSTOM || |
| 7948 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 7949 | continue; |
| 7950 | |
| 7951 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 7952 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 7953 | curproxy->id, hrqrule->arg.capid.idx); |
| 7954 | cfgerr++; |
| 7955 | } |
| 7956 | } |
| 7957 | |
| 7958 | /* parse http-response capture rules to ensure id really exists */ |
| 7959 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7960 | if (hrqrule->action != ACT_CUSTOM || |
| 7961 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 7962 | continue; |
| 7963 | |
| 7964 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 7965 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 7966 | curproxy->id, hrqrule->arg.capid.idx); |
| 7967 | cfgerr++; |
| 7968 | } |
| 7969 | } |
| 7970 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7971 | /* find the target table for 'http-request' layer 7 rules */ |
| 7972 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7973 | struct proxy *target; |
| 7974 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7975 | 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] | 7976 | continue; |
| 7977 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7978 | if (hrqrule->arg.trk_ctr.table.n) |
| 7979 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7980 | else |
| 7981 | target = curproxy; |
| 7982 | |
| 7983 | if (!target) { |
| 7984 | 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] | 7985 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7986 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7987 | cfgerr++; |
| 7988 | } |
| 7989 | else if (target->table.size == 0) { |
| 7990 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7991 | 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] | 7992 | cfgerr++; |
| 7993 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7994 | 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] | 7995 | 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] | 7996 | 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] | 7997 | http_trk_idx(hrqrule->action)); |
| 7998 | cfgerr++; |
| 7999 | } |
| 8000 | else { |
| 8001 | free(hrqrule->arg.trk_ctr.table.n); |
| 8002 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 8003 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8004 | * to pass a list of counters to track and allocate them right here using |
| 8005 | * stktable_alloc_data_type(). |
| 8006 | */ |
| 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | /* find the target table for 'http-response' layer 7 rules */ |
| 8011 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8012 | struct proxy *target; |
| 8013 | |
| 8014 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 8015 | continue; |
| 8016 | |
| 8017 | if (hrqrule->arg.trk_ctr.table.n) |
| 8018 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 8019 | else |
| 8020 | target = curproxy; |
| 8021 | |
| 8022 | if (!target) { |
| 8023 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 8024 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 8025 | http_trk_idx(hrqrule->action)); |
| 8026 | cfgerr++; |
| 8027 | } |
| 8028 | else if (target->table.size == 0) { |
| 8029 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 8030 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 8031 | cfgerr++; |
| 8032 | } |
| 8033 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 8034 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 8035 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 8036 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8037 | cfgerr++; |
| 8038 | } |
| 8039 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8040 | free(hrqrule->arg.trk_ctr.table.n); |
| 8041 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8042 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8043 | * to pass a list of counters to track and allocate them right here using |
| 8044 | * stktable_alloc_data_type(). |
| 8045 | */ |
| 8046 | } |
| 8047 | } |
| 8048 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8049 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8050 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8051 | /* insert block_rules into http_req_rules at the beginning */ |
| 8052 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8053 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8054 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8055 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8056 | LIST_INIT(&curproxy->block_rules); |
| 8057 | } |
| 8058 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8059 | if (curproxy->table.peers.name) { |
| 8060 | struct peers *curpeers = peers; |
| 8061 | |
| 8062 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 8063 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8064 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8065 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8066 | break; |
| 8067 | } |
| 8068 | } |
| 8069 | |
| 8070 | if (!curpeers) { |
| 8071 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8072 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8073 | free((void *)curproxy->table.peers.name); |
| 8074 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8075 | cfgerr++; |
| 8076 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8077 | else if (curpeers->state == PR_STSTOPPED) { |
| 8078 | /* silently disable this peers section */ |
| 8079 | curproxy->table.peers.p = NULL; |
| 8080 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8081 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8082 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8083 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8084 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8085 | cfgerr++; |
| 8086 | } |
| 8087 | } |
| 8088 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8089 | |
| 8090 | if (curproxy->email_alert.mailers.name) { |
| 8091 | struct mailers *curmailers = mailers; |
| 8092 | |
| 8093 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 8094 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8095 | free(curproxy->email_alert.mailers.name); |
| 8096 | curproxy->email_alert.mailers.m = curmailers; |
| 8097 | curmailers->users++; |
| 8098 | break; |
| 8099 | } |
| 8100 | } |
| 8101 | |
| 8102 | if (!curmailers) { |
| 8103 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8104 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8105 | free_email_alert(curproxy); |
| 8106 | cfgerr++; |
| 8107 | } |
| 8108 | } |
| 8109 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8110 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8111 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8112 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8113 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8114 | "proxy", curproxy->id); |
| 8115 | cfgerr++; |
| 8116 | goto out_uri_auth_compat; |
| 8117 | } |
| 8118 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8119 | 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] | 8120 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8121 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8122 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8123 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8124 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8125 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8126 | |
| 8127 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8128 | uri_auth_compat_req[i++] = "realm"; |
| 8129 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8130 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8131 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8132 | uri_auth_compat_req[i++] = "unless"; |
| 8133 | uri_auth_compat_req[i++] = "{"; |
| 8134 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8135 | uri_auth_compat_req[i++] = "}"; |
| 8136 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8137 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8138 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8139 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8140 | cfgerr++; |
| 8141 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8142 | } |
| 8143 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8144 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8145 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8146 | if (curproxy->uri_auth->auth_realm) { |
| 8147 | free(curproxy->uri_auth->auth_realm); |
| 8148 | curproxy->uri_auth->auth_realm = NULL; |
| 8149 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8150 | |
| 8151 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8152 | } |
| 8153 | out_uri_auth_compat: |
| 8154 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8155 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8156 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8157 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8158 | if (!curproxy->conf.logformat_sd_string) { |
| 8159 | /* set the default logformat_sd_string */ |
| 8160 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8161 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8162 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8163 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8164 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8165 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8166 | /* compile the log format */ |
| 8167 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8168 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8169 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8170 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8171 | free(curproxy->conf.logformat_string); |
| 8172 | curproxy->conf.logformat_string = NULL; |
| 8173 | free(curproxy->conf.lfs_file); |
| 8174 | curproxy->conf.lfs_file = NULL; |
| 8175 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8176 | |
| 8177 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8178 | free(curproxy->conf.logformat_sd_string); |
| 8179 | curproxy->conf.logformat_sd_string = NULL; |
| 8180 | free(curproxy->conf.lfsd_file); |
| 8181 | curproxy->conf.lfsd_file = NULL; |
| 8182 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8183 | } |
| 8184 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8185 | if (curproxy->conf.logformat_string) { |
| 8186 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8187 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8188 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 8189 | 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] | 8190 | 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] | 8191 | curproxy->conf.args.file = NULL; |
| 8192 | curproxy->conf.args.line = 0; |
| 8193 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8194 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8195 | if (curproxy->conf.logformat_sd_string) { |
| 8196 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8197 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8198 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
| 8199 | parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
| 8200 | SMP_VAL_FE_LOG_END, curproxy->conf.lfsd_file, curproxy->conf.lfsd_line); |
| 8201 | add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd); |
| 8202 | curproxy->conf.args.file = NULL; |
| 8203 | curproxy->conf.args.line = 0; |
| 8204 | } |
| 8205 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8206 | if (curproxy->conf.uniqueid_format_string) { |
| 8207 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8208 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8209 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 8210 | 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] | 8211 | (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] | 8212 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8213 | curproxy->conf.args.file = NULL; |
| 8214 | curproxy->conf.args.line = 0; |
| 8215 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8216 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8217 | /* only now we can check if some args remain unresolved. |
| 8218 | * This must be done after the users and groups resolution. |
| 8219 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8220 | cfgerr += smp_resolve_args(curproxy); |
| 8221 | if (!cfgerr) |
| 8222 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8223 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8224 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8225 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8226 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8227 | (!curproxy->timeout.connect || |
| 8228 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8229 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8230 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8231 | " | 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] | 8232 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8233 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8234 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8235 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8236 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8237 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8238 | * We must still support older configurations, so let's find out whether those |
| 8239 | * parameters have been set or must be copied from contimeouts. |
| 8240 | */ |
| 8241 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8242 | if (!curproxy->timeout.tarpit || |
| 8243 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8244 | /* tarpit timeout not set. We search in the following order: |
| 8245 | * default.tarpit, curr.connect, default.connect. |
| 8246 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8247 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8248 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
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.tarpit = 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.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8253 | } |
| 8254 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8255 | (!curproxy->timeout.queue || |
| 8256 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8257 | /* queue timeout not set. We search in the following order: |
| 8258 | * default.queue, curr.connect, default.connect. |
| 8259 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8260 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8261 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8262 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8263 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8264 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8265 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8266 | } |
| 8267 | } |
| 8268 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8269 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8270 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8271 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8272 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8273 | } |
| 8274 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8275 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8276 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8277 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8278 | proxy_type_str(curproxy), curproxy->id); |
| 8279 | err_code |= ERR_WARN; |
| 8280 | } |
| 8281 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8282 | /* ensure that cookie capture length is not too large */ |
| 8283 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8284 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8285 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8286 | err_code |= ERR_WARN; |
| 8287 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8288 | } |
| 8289 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8290 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8291 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8292 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8293 | curproxy->nb_req_cap * sizeof(char *), |
| 8294 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8295 | } |
| 8296 | |
| 8297 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8298 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8299 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8300 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8301 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8302 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8303 | switch (curproxy->load_server_state_from_file) { |
| 8304 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8305 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8306 | break; |
| 8307 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8308 | if (!global.server_state_file) { |
| 8309 | 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", |
| 8310 | curproxy->id); |
| 8311 | err_code |= ERR_WARN; |
| 8312 | } |
| 8313 | break; |
| 8314 | } |
| 8315 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8316 | /* first, we will invert the servers list order */ |
| 8317 | newsrv = NULL; |
| 8318 | while (curproxy->srv) { |
| 8319 | struct server *next; |
| 8320 | |
| 8321 | next = curproxy->srv->next; |
| 8322 | curproxy->srv->next = newsrv; |
| 8323 | newsrv = curproxy->srv; |
| 8324 | if (!next) |
| 8325 | break; |
| 8326 | curproxy->srv = next; |
| 8327 | } |
| 8328 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8329 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8330 | * We only emit a warning for the first conflict affecting each server, |
| 8331 | * in order to avoid combinatory explosion if all servers have the same |
| 8332 | * name. We do that only for servers which do not have an explicit ID, |
| 8333 | * because these IDs were made also for distinguishing them and we don't |
| 8334 | * want to annoy people who correctly manage them. |
| 8335 | */ |
| 8336 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8337 | struct server *other_srv; |
| 8338 | |
| 8339 | if (newsrv->puid) |
| 8340 | continue; |
| 8341 | |
| 8342 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8343 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8344 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8345 | newsrv->conf.file, newsrv->conf.line, |
| 8346 | proxy_type_str(curproxy), curproxy->id, |
| 8347 | newsrv->id, other_srv->conf.line); |
| 8348 | break; |
| 8349 | } |
| 8350 | } |
| 8351 | } |
| 8352 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8353 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8354 | next_id = 1; |
| 8355 | newsrv = curproxy->srv; |
| 8356 | while (newsrv != NULL) { |
| 8357 | if (!newsrv->puid) { |
| 8358 | /* server ID not set, use automatic numbering with first |
| 8359 | * spare entry starting with next_svid. |
| 8360 | */ |
| 8361 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8362 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8363 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8364 | } |
| 8365 | next_id++; |
| 8366 | newsrv = newsrv->next; |
| 8367 | } |
| 8368 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8369 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8370 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8371 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8372 | /* |
| 8373 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8374 | * tasks to fill the emptied slots when a connection leaves. |
| 8375 | * Also, resolve deferred tracking dependency if needed. |
| 8376 | */ |
| 8377 | newsrv = curproxy->srv; |
| 8378 | while (newsrv != NULL) { |
| 8379 | if (newsrv->minconn > newsrv->maxconn) { |
| 8380 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8381 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8382 | * this will avoid further useless expensive computations. |
| 8383 | */ |
| 8384 | newsrv->maxconn = newsrv->minconn; |
| 8385 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8386 | /* minconn was not specified, so we set it to maxconn */ |
| 8387 | newsrv->minconn = newsrv->maxconn; |
| 8388 | } |
| 8389 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8390 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8391 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 8392 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8393 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8394 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8395 | /* set the check type on the server */ |
| 8396 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8397 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8398 | if (newsrv->trackit) { |
| 8399 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8400 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8401 | char *pname, *sname; |
| 8402 | |
| 8403 | pname = newsrv->trackit; |
| 8404 | sname = strrchr(pname, '/'); |
| 8405 | |
| 8406 | if (sname) |
| 8407 | *sname++ = '\0'; |
| 8408 | else { |
| 8409 | sname = pname; |
| 8410 | pname = NULL; |
| 8411 | } |
| 8412 | |
| 8413 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8414 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8415 | if (!px) { |
| 8416 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8417 | proxy_type_str(curproxy), curproxy->id, |
| 8418 | newsrv->id, pname); |
| 8419 | cfgerr++; |
| 8420 | goto next_srv; |
| 8421 | } |
| 8422 | } else |
| 8423 | px = curproxy; |
| 8424 | |
| 8425 | srv = findserver(px, sname); |
| 8426 | if (!srv) { |
| 8427 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8428 | proxy_type_str(curproxy), curproxy->id, |
| 8429 | newsrv->id, sname); |
| 8430 | cfgerr++; |
| 8431 | goto next_srv; |
| 8432 | } |
| 8433 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8434 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8435 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8436 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8437 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8438 | "tracking as it does not have any check nor agent enabled.\n", |
| 8439 | proxy_type_str(curproxy), curproxy->id, |
| 8440 | newsrv->id, px->id, srv->id); |
| 8441 | cfgerr++; |
| 8442 | goto next_srv; |
| 8443 | } |
| 8444 | |
| 8445 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8446 | |
| 8447 | if (loop) { |
| 8448 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8449 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8450 | proxy_type_str(curproxy), curproxy->id, |
| 8451 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8452 | cfgerr++; |
| 8453 | goto next_srv; |
| 8454 | } |
| 8455 | |
| 8456 | if (curproxy != px && |
| 8457 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8458 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8459 | "tracking: disable-on-404 option inconsistency.\n", |
| 8460 | proxy_type_str(curproxy), curproxy->id, |
| 8461 | newsrv->id, px->id, srv->id); |
| 8462 | cfgerr++; |
| 8463 | goto next_srv; |
| 8464 | } |
| 8465 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8466 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8467 | newsrv->tracknext = srv->trackers; |
| 8468 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8469 | |
| 8470 | free(newsrv->trackit); |
| 8471 | newsrv->trackit = NULL; |
| 8472 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8473 | |
| 8474 | /* |
| 8475 | * resolve server's resolvers name and update the resolvers pointer |
| 8476 | * accordingly |
| 8477 | */ |
| 8478 | if (newsrv->resolvers_id) { |
| 8479 | struct dns_resolvers *curr_resolvers; |
| 8480 | int found; |
| 8481 | |
| 8482 | found = 0; |
| 8483 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8484 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8485 | found = 1; |
| 8486 | break; |
| 8487 | } |
| 8488 | } |
| 8489 | |
| 8490 | if (!found) { |
| 8491 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8492 | proxy_type_str(curproxy), curproxy->id, |
| 8493 | newsrv->id, newsrv->resolvers_id); |
| 8494 | cfgerr++; |
| 8495 | } else { |
| 8496 | free(newsrv->resolvers_id); |
| 8497 | newsrv->resolvers_id = NULL; |
| 8498 | if (newsrv->resolution) |
| 8499 | newsrv->resolution->resolvers = curr_resolvers; |
| 8500 | } |
| 8501 | } |
| 8502 | else { |
| 8503 | /* if no resolvers section associated to this server |
| 8504 | * we can clean up the associated resolution structure |
| 8505 | */ |
| 8506 | if (newsrv->resolution) { |
| 8507 | free(newsrv->resolution->hostname_dn); |
| 8508 | newsrv->resolution->hostname_dn = NULL; |
| 8509 | free(newsrv->resolution); |
| 8510 | newsrv->resolution = NULL; |
| 8511 | } |
| 8512 | } |
| 8513 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8514 | next_srv: |
| 8515 | newsrv = newsrv->next; |
| 8516 | } |
| 8517 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8518 | /* We have to initialize the server lookup mechanism depending |
| 8519 | * on what LB algorithm was choosen. |
| 8520 | */ |
| 8521 | |
| 8522 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8523 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8524 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8525 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8526 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8527 | init_server_map(curproxy); |
| 8528 | } else { |
| 8529 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8530 | fwrr_init_server_groups(curproxy); |
| 8531 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8532 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8533 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8534 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8535 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8536 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8537 | fwlc_init_server_tree(curproxy); |
| 8538 | } else { |
| 8539 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8540 | fas_init_server_tree(curproxy); |
| 8541 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8542 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8543 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8544 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8545 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8546 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8547 | chash_init_server_tree(curproxy); |
| 8548 | } else { |
| 8549 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8550 | init_server_map(curproxy); |
| 8551 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8552 | break; |
| 8553 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8554 | |
| 8555 | if (curproxy->options & PR_O_LOGASAP) |
| 8556 | curproxy->to_log &= ~LW_BYTES; |
| 8557 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8558 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8559 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8560 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8561 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8562 | proxy_type_str(curproxy), curproxy->id); |
| 8563 | err_code |= ERR_WARN; |
| 8564 | } |
| 8565 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8566 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8567 | int optnum; |
| 8568 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8569 | if (curproxy->uri_auth) { |
| 8570 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8571 | proxy_type_str(curproxy), curproxy->id); |
| 8572 | err_code |= ERR_WARN; |
| 8573 | curproxy->uri_auth = NULL; |
| 8574 | } |
| 8575 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8576 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8577 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8578 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8579 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8580 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8581 | } |
| 8582 | |
| 8583 | if (curproxy->options & PR_O_ORGTO) { |
| 8584 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8585 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8586 | err_code |= ERR_WARN; |
| 8587 | curproxy->options &= ~PR_O_ORGTO; |
| 8588 | } |
| 8589 | |
| 8590 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8591 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8592 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8593 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8594 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8595 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8596 | err_code |= ERR_WARN; |
| 8597 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8602 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8603 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8604 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8605 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8606 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8607 | err_code |= ERR_WARN; |
| 8608 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8609 | } |
| 8610 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8611 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8612 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8613 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8614 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8615 | 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] | 8616 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8617 | err_code |= ERR_WARN; |
| 8618 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8619 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8620 | } |
| 8621 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8622 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8623 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8624 | */ |
| 8625 | newsrv = curproxy->srv; |
| 8626 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8627 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8628 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8629 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8630 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8631 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8632 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8633 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8634 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8635 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8636 | err_code |= ERR_WARN; |
| 8637 | } |
| 8638 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8639 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8640 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8641 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8642 | err_code |= ERR_WARN; |
| 8643 | } |
| 8644 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8645 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8646 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8647 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8648 | 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] | 8649 | 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] | 8650 | err_code |= ERR_WARN; |
| 8651 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8652 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8653 | newsrv = newsrv->next; |
| 8654 | } |
| 8655 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8656 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8657 | * with no inspect-delay |
| 8658 | */ |
| 8659 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8660 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8661 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8662 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8663 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8664 | 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] | 8665 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8666 | break; |
| 8667 | } |
| 8668 | |
| 8669 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8670 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8671 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8672 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8673 | " setting the tcp-request inspect-delay.\n", |
| 8674 | proxy_type_str(curproxy), curproxy->id); |
| 8675 | err_code |= ERR_WARN; |
| 8676 | } |
| 8677 | } |
| 8678 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8679 | /* Check filter configuration, if any */ |
| 8680 | cfgerr += flt_check(curproxy); |
| 8681 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8682 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8683 | if (!curproxy->accept) |
| 8684 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8685 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8686 | if (curproxy->tcp_req.inspect_delay || |
| 8687 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8688 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8689 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8690 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8691 | 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] | 8692 | 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] | 8693 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8694 | |
| 8695 | /* both TCP and HTTP must check switching rules */ |
| 8696 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8697 | |
| 8698 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8699 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8700 | curproxy->fe_req_ana |= AN_FLT_ALL_FE; |
| 8701 | curproxy->fe_rsp_ana |= AN_FLT_ALL_FE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8702 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8703 | curproxy->fe_req_ana |= AN_FLT_HTTP_HDRS; |
| 8704 | curproxy->fe_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8705 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8706 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8707 | } |
| 8708 | |
| 8709 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8710 | if (curproxy->tcp_req.inspect_delay || |
| 8711 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8712 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8713 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8714 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8715 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8716 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8717 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8718 | 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] | 8719 | 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] | 8720 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8721 | |
| 8722 | /* If the backend does requires RDP cookie persistence, we have to |
| 8723 | * enable the corresponding analyser. |
| 8724 | */ |
| 8725 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8726 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8727 | |
| 8728 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8729 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8730 | curproxy->be_req_ana |= AN_FLT_ALL_BE; |
| 8731 | curproxy->be_rsp_ana |= AN_FLT_ALL_BE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8732 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8733 | curproxy->be_req_ana |= AN_FLT_HTTP_HDRS; |
| 8734 | curproxy->be_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8735 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8736 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8737 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8738 | } |
| 8739 | |
| 8740 | /***********************************************************/ |
| 8741 | /* At this point, target names have already been resolved. */ |
| 8742 | /***********************************************************/ |
| 8743 | |
| 8744 | /* Check multi-process mode compatibility */ |
| 8745 | |
| 8746 | if (global.nbproc > 1 && global.stats_fe) { |
| 8747 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8748 | unsigned long mask; |
| 8749 | |
| 8750 | mask = nbits(global.nbproc); |
| 8751 | if (global.stats_fe->bind_proc) |
| 8752 | mask &= global.stats_fe->bind_proc; |
| 8753 | |
| 8754 | if (bind_conf->bind_proc) |
| 8755 | mask &= bind_conf->bind_proc; |
| 8756 | |
| 8757 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8758 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8759 | break; |
| 8760 | } |
| 8761 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8762 | 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"); |
| 8763 | } |
| 8764 | } |
| 8765 | |
| 8766 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8767 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8768 | if (curproxy->bind_proc) |
| 8769 | continue; |
| 8770 | |
| 8771 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8772 | unsigned long mask; |
| 8773 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8774 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8775 | curproxy->bind_proc |= mask; |
| 8776 | } |
| 8777 | |
| 8778 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8779 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8780 | } |
| 8781 | |
| 8782 | if (global.stats_fe) { |
| 8783 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8784 | unsigned long mask; |
| 8785 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8786 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8787 | global.stats_fe->bind_proc |= mask; |
| 8788 | } |
| 8789 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8790 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8791 | } |
| 8792 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8793 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8794 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8795 | */ |
| 8796 | if (!cfgerr) { |
| 8797 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8798 | if (curproxy->cap & PR_CAP_FE) |
| 8799 | propagate_processes(curproxy, NULL); |
| 8800 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | /* Bind each unbound backend to all processes when not specified. */ |
| 8804 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8805 | if (curproxy->bind_proc) |
| 8806 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8807 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8808 | } |
| 8809 | |
| 8810 | /*******************************************************/ |
| 8811 | /* At this step, all proxies have a non-null bind_proc */ |
| 8812 | /*******************************************************/ |
| 8813 | |
| 8814 | /* perform the final checks before creating tasks */ |
| 8815 | |
| 8816 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8817 | struct listener *listener; |
| 8818 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8819 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8820 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8821 | /* Configure SSL for each bind line. |
| 8822 | * Note: if configuration fails at some point, the ->ctx member |
| 8823 | * remains NULL so that listeners can later detach. |
| 8824 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8825 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8826 | int alloc_ctx; |
| 8827 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8828 | if (!bind_conf->is_ssl) { |
| 8829 | if (bind_conf->default_ctx) { |
| 8830 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 8831 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8832 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8833 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8834 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8835 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8836 | 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] | 8837 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8838 | cfgerr++; |
| 8839 | continue; |
| 8840 | } |
| 8841 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 8842 | 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] | 8843 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8844 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 8845 | 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"); |
| 8846 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8847 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8848 | cfgerr++; |
| 8849 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8850 | } |
| 8851 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8852 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8853 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8854 | |
| 8855 | /* initialize CA variables if the certificates generation is enabled */ |
| 8856 | cfgerr += ssl_sock_load_ca(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8857 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8858 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8859 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8860 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8861 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8862 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8863 | int nbproc; |
| 8864 | |
| 8865 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8866 | (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] | 8867 | nbits(global.nbproc)); |
| 8868 | |
| 8869 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8870 | nbproc = 1; |
| 8871 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8872 | if (!listener->luid) { |
| 8873 | /* listener ID not set, use automatic numbering with first |
| 8874 | * spare entry starting with next_luid. |
| 8875 | */ |
| 8876 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8877 | listener->conf.id.key = listener->luid = next_id; |
| 8878 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8879 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8880 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8881 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8882 | /* enable separate counters */ |
| 8883 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8884 | listener->counters = calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8885 | if (!listener->name) |
| 8886 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8887 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8888 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8889 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8890 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8891 | if (!listener->maxconn) |
| 8892 | listener->maxconn = curproxy->maxconn; |
| 8893 | if (!listener->backlog) |
| 8894 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8895 | if (!listener->maxaccept) |
| 8896 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8897 | |
| 8898 | /* we want to have an optimal behaviour on single process mode to |
| 8899 | * maximize the work at once, but in multi-process we want to keep |
| 8900 | * some fairness between processes, so we target half of the max |
| 8901 | * number of events to be balanced over all the processes the proxy |
| 8902 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8903 | * used to disable the limit. |
| 8904 | */ |
| 8905 | if (listener->maxaccept > 0) { |
| 8906 | if (nbproc > 1) |
| 8907 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8908 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8909 | } |
| 8910 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8911 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8912 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8913 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8914 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8915 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8916 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8917 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8918 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8919 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8920 | listener->options |= LI_O_TCP_L5_RULES; |
| 8921 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8922 | if (curproxy->mon_mask.s_addr) |
| 8923 | listener->options |= LI_O_CHK_MONNET; |
| 8924 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8925 | /* smart accept mode is automatic in HTTP mode */ |
| 8926 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8927 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8928 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8929 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8930 | } |
| 8931 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8932 | /* Release unused SSL configs */ |
| 8933 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8934 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8935 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8936 | #ifdef USE_OPENSSL |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8937 | ssl_sock_free_ca(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8938 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8939 | free(bind_conf->ca_file); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8940 | free(bind_conf->ca_sign_file); |
| 8941 | free(bind_conf->ca_sign_pass); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8942 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 8943 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 8944 | free(bind_conf->crl_file); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 8945 | if(bind_conf->keys_ref) { |
| 8946 | free(bind_conf->keys_ref->filename); |
| 8947 | free(bind_conf->keys_ref->tlskeys); |
William Lallemand | 7bba4cc | 2016-05-20 17:28:07 +0200 | [diff] [blame] | 8948 | LIST_DEL(&bind_conf->keys_ref->list); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 8949 | free(bind_conf->keys_ref); |
| 8950 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8951 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8952 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8953 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8954 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8955 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8956 | int count, maxproc = 0; |
| 8957 | |
| 8958 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8959 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8960 | if (count > maxproc) |
| 8961 | maxproc = count; |
| 8962 | } |
| 8963 | /* backends have 0, frontends have 1 or more */ |
| 8964 | if (maxproc != 1) |
| 8965 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 8966 | " limited to process assigned to the current request.\n", |
| 8967 | curproxy->id); |
| 8968 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8969 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 8970 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8971 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8972 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8973 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8974 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 8975 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8976 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8977 | } |
| 8978 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8979 | |
| 8980 | /* create the task associated with the proxy */ |
| 8981 | curproxy->task = task_new(); |
| 8982 | if (curproxy->task) { |
| 8983 | curproxy->task->context = curproxy; |
| 8984 | curproxy->task->process = manage_proxy; |
| 8985 | /* no need to queue, it will be done automatically if some |
| 8986 | * listener gets limited. |
| 8987 | */ |
| 8988 | curproxy->task->expire = TICK_ETERNITY; |
| 8989 | } else { |
| 8990 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8991 | curproxy->id); |
| 8992 | cfgerr++; |
| 8993 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8994 | } |
| 8995 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8996 | /* automatically compute fullconn if not set. We must not do it in the |
| 8997 | * loop above because cross-references are not yet fully resolved. |
| 8998 | */ |
| 8999 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9000 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9001 | * the possible incoming frontend's maxconns. |
| 9002 | */ |
| 9003 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 9004 | struct proxy *fe; |
| 9005 | int total = 0; |
| 9006 | |
| 9007 | /* sum up the number of maxconns of frontends which |
| 9008 | * reference this backend at least once or which are |
| 9009 | * the same one ('listen'). |
| 9010 | */ |
| 9011 | for (fe = proxy; fe; fe = fe->next) { |
| 9012 | struct switching_rule *rule; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9013 | int found = 0; |
| 9014 | |
| 9015 | if (!(fe->cap & PR_CAP_FE)) |
| 9016 | continue; |
| 9017 | |
| 9018 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 9019 | found = 1; |
| 9020 | |
| 9021 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 9022 | found = 1; |
| 9023 | |
| 9024 | /* check if a "use_backend" rule matches */ |
| 9025 | if (!found) { |
| 9026 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9027 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9028 | found = 1; |
| 9029 | break; |
| 9030 | } |
| 9031 | } |
| 9032 | } |
| 9033 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9034 | /* now we've checked all possible ways to reference a backend |
| 9035 | * from a frontend. |
| 9036 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9037 | if (!found) |
| 9038 | continue; |
| 9039 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9040 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9041 | /* we have the sum of the maxconns in <total>. We only |
| 9042 | * keep 10% of that sum to set the default fullconn, with |
| 9043 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9044 | */ |
| 9045 | curproxy->fullconn = (total + 9) / 10; |
| 9046 | if (!curproxy->fullconn) |
| 9047 | curproxy->fullconn = 1; |
| 9048 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9049 | } |
| 9050 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9051 | /* |
| 9052 | * Recount currently required checks. |
| 9053 | */ |
| 9054 | |
| 9055 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 9056 | int optnum; |
| 9057 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9058 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9059 | if (curproxy->options & cfg_opts[optnum].val) |
| 9060 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9061 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9062 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9063 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9064 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9065 | } |
| 9066 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9067 | /* compute the required process bindings for the peers */ |
| 9068 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 9069 | if (curproxy->table.peers.p) |
| 9070 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9071 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9072 | if (peers) { |
| 9073 | struct peers *curpeers = peers, **last; |
| 9074 | struct peer *p, *pb; |
| 9075 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9076 | /* Remove all peers sections which don't have a valid listener, |
| 9077 | * which are not used by any table, or which are bound to more |
| 9078 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9079 | */ |
| 9080 | last = &peers; |
| 9081 | while (*last) { |
| 9082 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9083 | |
| 9084 | if (curpeers->state == PR_STSTOPPED) { |
| 9085 | /* the "disabled" keyword was present */ |
| 9086 | if (curpeers->peers_fe) |
| 9087 | stop_proxy(curpeers->peers_fe); |
| 9088 | curpeers->peers_fe = NULL; |
| 9089 | } |
| 9090 | else if (!curpeers->peers_fe) { |
| 9091 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9092 | curpeers->id, localpeer); |
| 9093 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9094 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9095 | /* either it's totally stopped or too much used */ |
| 9096 | if (curpeers->peers_fe->bind_proc) { |
| 9097 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 9098 | "running in different processes (%d different ones). " |
| 9099 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9100 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9101 | cfgerr++; |
| 9102 | } |
| 9103 | stop_proxy(curpeers->peers_fe); |
| 9104 | curpeers->peers_fe = NULL; |
| 9105 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9106 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9107 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9108 | last = &curpeers->next; |
| 9109 | continue; |
| 9110 | } |
| 9111 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9112 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9113 | p = curpeers->remote; |
| 9114 | while (p) { |
| 9115 | pb = p->next; |
| 9116 | free(p->id); |
| 9117 | free(p); |
| 9118 | p = pb; |
| 9119 | } |
| 9120 | |
| 9121 | /* Destroy and unlink this curpeers section. |
| 9122 | * Note: curpeers is backed up into *last. |
| 9123 | */ |
| 9124 | free(curpeers->id); |
| 9125 | curpeers = curpeers->next; |
| 9126 | free(*last); |
| 9127 | *last = curpeers; |
| 9128 | } |
| 9129 | } |
| 9130 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9131 | /* initialize stick-tables on backend capable proxies. This must not |
| 9132 | * be done earlier because the data size may be discovered while parsing |
| 9133 | * other proxies. |
| 9134 | */ |
| 9135 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9136 | if (curproxy->state == PR_STSTOPPED) |
| 9137 | continue; |
| 9138 | |
| 9139 | if (!stktable_init(&curproxy->table)) { |
| 9140 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9141 | cfgerr++; |
| 9142 | } |
| 9143 | } |
| 9144 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9145 | if (mailers) { |
| 9146 | struct mailers *curmailers = mailers, **last; |
| 9147 | struct mailer *m, *mb; |
| 9148 | |
| 9149 | /* Remove all mailers sections which don't have a valid listener. |
| 9150 | * This can happen when a mailers section is never referenced. |
| 9151 | */ |
| 9152 | last = &mailers; |
| 9153 | while (*last) { |
| 9154 | curmailers = *last; |
| 9155 | if (curmailers->users) { |
| 9156 | last = &curmailers->next; |
| 9157 | continue; |
| 9158 | } |
| 9159 | |
| 9160 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9161 | curmailers->id); |
| 9162 | |
| 9163 | m = curmailers->mailer_list; |
| 9164 | while (m) { |
| 9165 | mb = m->next; |
| 9166 | free(m->id); |
| 9167 | free(m); |
| 9168 | m = mb; |
| 9169 | } |
| 9170 | |
| 9171 | /* Destroy and unlink this curmailers section. |
| 9172 | * Note: curmailers is backed up into *last. |
| 9173 | */ |
| 9174 | free(curmailers->id); |
| 9175 | curmailers = curmailers->next; |
| 9176 | free(*last); |
| 9177 | *last = curmailers; |
| 9178 | } |
| 9179 | } |
| 9180 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9181 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9182 | * a server-state file locally defined and none has been provided */ |
| 9183 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9184 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9185 | curproxy->server_state_file_name == NULL) |
| 9186 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9187 | } |
| 9188 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9189 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9190 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9191 | MEM_F_SHARED); |
| 9192 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9193 | if (cfgerr > 0) |
| 9194 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9195 | out: |
| 9196 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9197 | } |
| 9198 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9199 | /* |
| 9200 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9201 | * parsing sessions. |
| 9202 | */ |
| 9203 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9204 | { |
| 9205 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9206 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9207 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9208 | /* |
| 9209 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9210 | */ |
| 9211 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9212 | { |
| 9213 | LIST_DEL(&kwl->list); |
| 9214 | LIST_INIT(&kwl->list); |
| 9215 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9216 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9217 | /* this function register new section in the haproxy configuration file. |
| 9218 | * <section_name> is the name of this new section and <section_parser> |
| 9219 | * is the called parser. If two section declaration have the same name, |
| 9220 | * only the first declared is used. |
| 9221 | */ |
| 9222 | int cfg_register_section(char *section_name, |
| 9223 | int (*section_parser)(const char *, int, char **, int)) |
| 9224 | { |
| 9225 | struct cfg_section *cs; |
| 9226 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9227 | list_for_each_entry(cs, §ions, list) { |
| 9228 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9229 | Alert("register section '%s': already registered.\n", section_name); |
| 9230 | return 0; |
| 9231 | } |
| 9232 | } |
| 9233 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9234 | cs = calloc(1, sizeof(*cs)); |
| 9235 | if (!cs) { |
| 9236 | Alert("register section '%s': out of memory.\n", section_name); |
| 9237 | return 0; |
| 9238 | } |
| 9239 | |
| 9240 | cs->section_name = section_name; |
| 9241 | cs->section_parser = section_parser; |
| 9242 | |
| 9243 | LIST_ADDQ(§ions, &cs->list); |
| 9244 | |
| 9245 | return 1; |
| 9246 | } |
| 9247 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9248 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9249 | * free all config section entries |
| 9250 | */ |
| 9251 | void cfg_unregister_sections(void) |
| 9252 | { |
| 9253 | struct cfg_section *cs, *ics; |
| 9254 | |
| 9255 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9256 | LIST_DEL(&cs->list); |
| 9257 | free(cs); |
| 9258 | } |
| 9259 | } |
| 9260 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9261 | __attribute__((constructor)) |
| 9262 | static void cfgparse_init(void) |
| 9263 | { |
| 9264 | /* Register internal sections */ |
| 9265 | cfg_register_section("listen", cfg_parse_listen); |
| 9266 | cfg_register_section("frontend", cfg_parse_listen); |
| 9267 | cfg_register_section("backend", cfg_parse_listen); |
| 9268 | cfg_register_section("defaults", cfg_parse_listen); |
| 9269 | cfg_register_section("global", cfg_parse_global); |
| 9270 | cfg_register_section("userlist", cfg_parse_users); |
| 9271 | cfg_register_section("peers", cfg_parse_peers); |
| 9272 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9273 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9274 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9275 | } |
| 9276 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9277 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9278 | * Local variables: |
| 9279 | * c-indent-level: 8 |
| 9280 | * c-basic-offset: 8 |
| 9281 | * End: |
| 9282 | */ |