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> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 54 | #include <types/stats.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 56 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 57 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 59 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 61 | #include <proto/compression.h> |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 62 | #include <proto/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 63 | #include <proto/stats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 64 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 65 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 66 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 67 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 68 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 69 | #include <proto/lb_fwlc.h> |
| 70 | #include <proto/lb_fwrr.h> |
| 71 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 72 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 73 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 74 | #include <proto/protocol.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> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 82 | #include <proto/stick_table.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 83 | #include <proto/task.h> |
| 84 | #include <proto/tcp_rules.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | |
| 86 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 87 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 88 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 89 | * |
| 90 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 91 | */ |
| 92 | const char sslv3_client_hello_pkt[] = { |
| 93 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 94 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 95 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 96 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 97 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 98 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 99 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 100 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 101 | "\x00" /* Session ID length : empty (no session ID) */ |
| 102 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 103 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 104 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 105 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 106 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 107 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 108 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 109 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 110 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 111 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 112 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 113 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 114 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 115 | }; |
| 116 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 117 | /* various keyword modifiers */ |
| 118 | enum kw_mod { |
| 119 | KWM_STD = 0, /* normal */ |
| 120 | KWM_NO, /* "no" prefixed before the keyword */ |
| 121 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 122 | }; |
| 123 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 124 | /* permit to store configuration section */ |
| 125 | struct cfg_section { |
| 126 | struct list list; |
| 127 | char *section_name; |
| 128 | int (*section_parser)(const char *, int, char **, int); |
| 129 | }; |
| 130 | |
| 131 | /* Used to chain configuration sections definitions. This list |
| 132 | * stores struct cfg_section |
| 133 | */ |
| 134 | struct list sections = LIST_HEAD_INIT(sections); |
| 135 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 136 | /* 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] | 137 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 138 | const char *name; |
| 139 | unsigned int val; |
| 140 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 141 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 142 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /* proxy->options */ |
| 146 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 147 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 148 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 149 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 150 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 151 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 152 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 153 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 154 | { "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] | 155 | { "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] | 156 | { "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] | 157 | { "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] | 158 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 159 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 160 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 161 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 162 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 163 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 164 | #else |
| 165 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 166 | #endif |
| 167 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 168 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 169 | }; |
| 170 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 171 | /* proxy->options2 */ |
| 172 | static const struct cfg_opt cfg_opts2[] = |
| 173 | { |
| 174 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 175 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 176 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 177 | { "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] | 178 | #else |
| 179 | { "splice-request", 0, 0, 0, 0 }, |
| 180 | { "splice-response", 0, 0, 0, 0 }, |
| 181 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 182 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 183 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 184 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 185 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 186 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 187 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 188 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 189 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 190 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 191 | { "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] | 192 | { "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] | 193 | { "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] | 194 | { "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] | 195 | { "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] | 196 | { NULL, 0, 0, 0 } |
| 197 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 198 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 199 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 200 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 201 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 202 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 203 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 204 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 205 | /* List head of all known configuration keywords */ |
| 206 | static struct cfg_kw_list cfg_keywords = { |
| 207 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 208 | }; |
| 209 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 210 | /* |
| 211 | * converts <str> to a list of listeners which are dynamically allocated. |
| 212 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 213 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 214 | * - <port> is a numerical port from 1 to 65535 ; |
| 215 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 216 | * 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] | 217 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 218 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 219 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 220 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 221 | 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] | 222 | { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 223 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 224 | int port, end; |
| 225 | |
| 226 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 227 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 228 | while (next && *next) { |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 229 | struct sockaddr_storage *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 230 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 231 | |
| 232 | str = next; |
| 233 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 234 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 235 | *next++ = 0; |
| 236 | } |
| 237 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 238 | ss2 = str2sa_range(str, NULL, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 239 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 240 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 241 | if (!ss2) |
| 242 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 243 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 244 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 245 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 246 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 247 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 248 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 250 | if (!port || !end) { |
| 251 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 252 | goto fail; |
| 253 | } |
| 254 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 256 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 257 | goto fail; |
| 258 | } |
| 259 | |
| 260 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 261 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 262 | goto fail; |
| 263 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 264 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 265 | else if (ss2->ss_family == AF_UNSPEC) { |
| 266 | socklen_t addr_len; |
| 267 | |
| 268 | /* We want to attach to an already bound fd whose number |
| 269 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 270 | * Note that by definition there is a single listener. |
| 271 | * We still have to determine the address family to |
| 272 | * register the correct protocol. |
| 273 | */ |
| 274 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 275 | addr_len = sizeof(*ss2); |
| 276 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 277 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 278 | goto fail; |
| 279 | } |
| 280 | |
| 281 | port = end = get_host_port(ss2); |
| 282 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 283 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 284 | /* OK the address looks correct */ |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 285 | if (!create_listeners(bind_conf, ss2, port, end, fd, err)) { |
| 286 | memprintf(err, "%s for address '%s'.\n", *err, str); |
| 287 | goto fail; |
| 288 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 289 | } /* end while(next) */ |
| 290 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 291 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 292 | fail: |
| 293 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 294 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 295 | } |
| 296 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 297 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 298 | * Report an error in <msg> when there are too many arguments. This version is |
| 299 | * intended to be used by keyword parsers so that the message will be included |
| 300 | * into the general error message. The index is the current keyword in args. |
| 301 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 302 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 303 | * message may also be null, it will simply not be produced (useful to check only). |
| 304 | * <msg> and <err_code> are only affected on error. |
| 305 | */ |
| 306 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 307 | { |
| 308 | int i; |
| 309 | |
| 310 | if (!*args[index + maxarg + 1]) |
| 311 | return 0; |
| 312 | |
| 313 | if (msg) { |
| 314 | *msg = NULL; |
| 315 | memprintf(msg, "%s", args[0]); |
| 316 | for (i = 1; i <= index; i++) |
| 317 | memprintf(msg, "%s %s", *msg, args[i]); |
| 318 | |
| 319 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 320 | } |
| 321 | if (err_code) |
| 322 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 323 | |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * same as too_many_args_idx with a 0 index |
| 329 | */ |
| 330 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 331 | { |
| 332 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 333 | } |
| 334 | |
| 335 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 336 | * Report a fatal Alert when there is too much arguments |
| 337 | * The index is the current keyword in args |
| 338 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 339 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 340 | */ |
| 341 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 342 | { |
| 343 | char *kw = NULL; |
| 344 | int i; |
| 345 | |
| 346 | if (!*args[index + maxarg + 1]) |
| 347 | return 0; |
| 348 | |
| 349 | memprintf(&kw, "%s", args[0]); |
| 350 | for (i = 1; i <= index; i++) { |
| 351 | memprintf(&kw, "%s %s", kw, args[i]); |
| 352 | } |
| 353 | |
| 354 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 355 | free(kw); |
| 356 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 357 | return 1; |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * same as alertif_too_many_args_idx with a 0 index |
| 362 | */ |
| 363 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 364 | { |
| 365 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 366 | } |
| 367 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 368 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 369 | * Return 1 if the warning has been emitted, otherwise 0. |
| 370 | */ |
| 371 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 372 | { |
| 373 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 374 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 375 | file, line, arg); |
| 376 | return 1; |
| 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 381 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 382 | * Return 1 if the warning has been emitted, otherwise 0. |
| 383 | */ |
| 384 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 385 | { |
| 386 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 387 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 388 | file, line, arg); |
| 389 | return 1; |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 394 | /* Report a warning if a rule is placed after a 'block' rule. |
| 395 | * Return 1 if the warning has been emitted, otherwise 0. |
| 396 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 397 | 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] | 398 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 399 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 400 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 401 | file, line, arg); |
| 402 | return 1; |
| 403 | } |
| 404 | return 0; |
| 405 | } |
| 406 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 407 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 408 | * Return 1 if the warning has been emitted, otherwise 0. |
| 409 | */ |
| 410 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 411 | { |
| 412 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 413 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 414 | file, line, arg); |
| 415 | return 1; |
| 416 | } |
| 417 | return 0; |
| 418 | } |
| 419 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 420 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 421 | * Return 1 if the warning has been emitted, otherwise 0. |
| 422 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 423 | 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] | 424 | { |
| 425 | if (proxy->req_exp) { |
| 426 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 427 | file, line, arg); |
| 428 | return 1; |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /* Report a warning if a rule is placed after a reqadd rule. |
| 434 | * Return 1 if the warning has been emitted, otherwise 0. |
| 435 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 436 | 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] | 437 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 438 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 439 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 440 | file, line, arg); |
| 441 | return 1; |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | /* Report a warning if a rule is placed after a redirect rule. |
| 447 | * Return 1 if the warning has been emitted, otherwise 0. |
| 448 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 449 | 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] | 450 | { |
| 451 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 452 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 453 | file, line, arg); |
| 454 | return 1; |
| 455 | } |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 460 | * Return 1 if the warning has been emitted, otherwise 0. |
| 461 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 462 | 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] | 463 | { |
| 464 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 465 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 466 | file, line, arg); |
| 467 | return 1; |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 472 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 473 | * Return 1 if the warning has been emitted, otherwise 0. |
| 474 | */ |
| 475 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 476 | { |
| 477 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 478 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 479 | file, line, arg); |
| 480 | return 1; |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 485 | /* report a warning if a redirect rule is dangerously placed */ |
| 486 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 487 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 488 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 489 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 490 | } |
| 491 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 492 | /* report a warning if a reqadd rule is dangerously placed */ |
| 493 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 494 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 495 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 496 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 499 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 500 | 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] | 501 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 502 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 503 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* report a warning if an http-request rule is dangerously placed */ |
| 507 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 508 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 509 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 510 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 513 | /* report a warning if a block rule is dangerously placed */ |
| 514 | 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] | 515 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 516 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 517 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 520 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 521 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 522 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 523 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 524 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 527 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 528 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 529 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 530 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 531 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 532 | } |
| 533 | |
| 534 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 535 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 536 | { |
| 537 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 538 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 541 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 542 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 543 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 544 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 545 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 546 | 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] | 547 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 548 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 549 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 550 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 551 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 552 | return 0; |
| 553 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 554 | acl = acl_cond_conflicts(cond, where); |
| 555 | if (acl) { |
| 556 | if (acl->name && *acl->name) |
| 557 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 558 | file, line, acl->name, sample_ckp_names(where)); |
| 559 | else |
| 560 | 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] | 561 | 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] | 562 | return ERR_WARN; |
| 563 | } |
| 564 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 565 | return 0; |
| 566 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 567 | if (acl->name && *acl->name) |
| 568 | 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] | 569 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 570 | else |
| 571 | 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] | 572 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 573 | return ERR_WARN; |
| 574 | } |
| 575 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 576 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 577 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 578 | * any combination of : |
| 579 | * - ERR_ABORT: must abort ASAP |
| 580 | * - ERR_FATAL: we can continue parsing but not start the service |
| 581 | * - ERR_WARN: a warning has been emitted |
| 582 | * - ERR_ALERT: an alert has been emitted |
| 583 | * Only the two first ones can stop processing, the two others are just |
| 584 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 585 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 586 | 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] | 587 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 588 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 589 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 590 | |
| 591 | if (!strcmp(args[0], "global")) { /* new section */ |
| 592 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 593 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 594 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 595 | } |
| 596 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 597 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 598 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 599 | global.mode |= MODE_DAEMON; |
| 600 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 601 | else if (!strcmp(args[0], "master-worker")) { |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 602 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 603 | goto out; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 604 | if (*args[1]) { |
| 605 | if (!strcmp(args[1], "exit-on-failure")) { |
| 606 | global.tune.options |= GTUNE_EXIT_ONFAILURE; |
| 607 | } else { |
| 608 | Alert("parsing [%s:%d] : '%s' only supports 'exit-on-failure' option.\n", file, linenum, args[0]); |
| 609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 610 | goto out; |
| 611 | } |
| 612 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 613 | global.mode |= MODE_MWORKER; |
| 614 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 615 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 616 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 617 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 618 | global.mode |= MODE_DEBUG; |
| 619 | } |
| 620 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 621 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 622 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 623 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 624 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 625 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 626 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 627 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 628 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 629 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 630 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 631 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 632 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 633 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 634 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 635 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 636 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 637 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 638 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 639 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 640 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 641 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 642 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 643 | global.tune.options &= ~GTUNE_USE_GAI; |
| 644 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 645 | else if (!strcmp(args[0], "noreuseport")) { |
| 646 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 647 | goto out; |
| 648 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 649 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 650 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 651 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 652 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 653 | global.mode |= MODE_QUIET; |
| 654 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 655 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 656 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 657 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 658 | if (global.tune.maxpollevents != 0) { |
| 659 | 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] | 660 | err_code |= ERR_ALERT; |
| 661 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 662 | } |
| 663 | if (*(args[1]) == 0) { |
| 664 | 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] | 665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 666 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 667 | } |
| 668 | global.tune.maxpollevents = atol(args[1]); |
| 669 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 670 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 671 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 672 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 673 | if (global.tune.maxaccept != 0) { |
| 674 | 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] | 675 | err_code |= ERR_ALERT; |
| 676 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 677 | } |
| 678 | if (*(args[1]) == 0) { |
| 679 | 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] | 680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 681 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 682 | } |
| 683 | global.tune.maxaccept = atol(args[1]); |
| 684 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 685 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 686 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 687 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 688 | if (*(args[1]) == 0) { |
| 689 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 691 | goto out; |
| 692 | } |
| 693 | global.tune.chksize = atol(args[1]); |
| 694 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 695 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 696 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 697 | goto out; |
| 698 | if (*(args[1]) == 0) { |
| 699 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 701 | goto out; |
| 702 | } |
| 703 | global.tune.recv_enough = atol(args[1]); |
| 704 | } |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 705 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 706 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 707 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 708 | if (*(args[1]) == 0) { |
| 709 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 711 | goto out; |
| 712 | } |
| 713 | global.tune.buf_limit = atol(args[1]); |
| 714 | if (global.tune.buf_limit) { |
| 715 | if (global.tune.buf_limit < 3) |
| 716 | global.tune.buf_limit = 3; |
| 717 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 718 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 719 | } |
| 720 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 721 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 722 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 723 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 724 | if (*(args[1]) == 0) { |
| 725 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 727 | goto out; |
| 728 | } |
| 729 | global.tune.reserved_bufs = atol(args[1]); |
| 730 | if (global.tune.reserved_bufs < 2) |
| 731 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 732 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 733 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 734 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 735 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 736 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 737 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 738 | if (*(args[1]) == 0) { |
| 739 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 744 | if (global.tune.bufsize <= 0) { |
| 745 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 747 | goto out; |
| 748 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 749 | } |
| 750 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 751 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 752 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 753 | if (*(args[1]) == 0) { |
| 754 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 756 | goto out; |
| 757 | } |
| 758 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 759 | if (global.tune.maxrewrite < 0) { |
| 760 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 762 | goto out; |
| 763 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 764 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 765 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 766 | unsigned int idle; |
| 767 | const char *res; |
| 768 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 769 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 770 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 771 | if (*(args[1]) == 0) { |
| 772 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 774 | goto out; |
| 775 | } |
| 776 | |
| 777 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 778 | if (res) { |
| 779 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 780 | file, linenum, *res, args[0]); |
| 781 | err_code |= ERR_ALERT | ERR_FATAL; |
| 782 | goto out; |
| 783 | } |
| 784 | |
| 785 | if (idle > 65535) { |
| 786 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 788 | goto out; |
| 789 | } |
| 790 | global.tune.idle_timer = idle; |
| 791 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 792 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 794 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 795 | if (global.tune.client_rcvbuf != 0) { |
| 796 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 797 | err_code |= ERR_ALERT; |
| 798 | goto out; |
| 799 | } |
| 800 | if (*(args[1]) == 0) { |
| 801 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 803 | goto out; |
| 804 | } |
| 805 | global.tune.client_rcvbuf = atol(args[1]); |
| 806 | } |
| 807 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 808 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 809 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 810 | if (global.tune.server_rcvbuf != 0) { |
| 811 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 812 | err_code |= ERR_ALERT; |
| 813 | goto out; |
| 814 | } |
| 815 | if (*(args[1]) == 0) { |
| 816 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 818 | goto out; |
| 819 | } |
| 820 | global.tune.server_rcvbuf = atol(args[1]); |
| 821 | } |
| 822 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 823 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 824 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 825 | if (global.tune.client_sndbuf != 0) { |
| 826 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 827 | err_code |= ERR_ALERT; |
| 828 | goto out; |
| 829 | } |
| 830 | if (*(args[1]) == 0) { |
| 831 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 833 | goto out; |
| 834 | } |
| 835 | global.tune.client_sndbuf = atol(args[1]); |
| 836 | } |
| 837 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 838 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 839 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 840 | if (global.tune.server_sndbuf != 0) { |
| 841 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 842 | err_code |= ERR_ALERT; |
| 843 | goto out; |
| 844 | } |
| 845 | if (*(args[1]) == 0) { |
| 846 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 848 | goto out; |
| 849 | } |
| 850 | global.tune.server_sndbuf = atol(args[1]); |
| 851 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 852 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 853 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 854 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 855 | if (*(args[1]) == 0) { |
| 856 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 858 | goto out; |
| 859 | } |
| 860 | global.tune.pipesize = atol(args[1]); |
| 861 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 862 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 863 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 864 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 865 | if (*(args[1]) == 0) { |
| 866 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 868 | goto out; |
| 869 | } |
| 870 | global.tune.cookie_len = atol(args[1]) + 1; |
| 871 | } |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 872 | else if (!strcmp(args[0], "tune.http.logurilen")) { |
| 873 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 874 | goto out; |
| 875 | if (*(args[1]) == 0) { |
| 876 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
| 879 | } |
| 880 | global.tune.requri_len = atol(args[1]) + 1; |
| 881 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 882 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
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 | ac1932d | 2011-10-24 19:14:41 +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 | } |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 890 | global.tune.max_http_hdr = atoi(args[1]); |
| 891 | if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) { |
| 892 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 893 | file, linenum, args[0]); |
| 894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 895 | goto out; |
| 896 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 897 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 898 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 899 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 900 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 901 | if (*args[1]) { |
| 902 | global.tune.comp_maxlevel = atoi(args[1]); |
| 903 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 904 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 905 | file, linenum, args[0]); |
| 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto out; |
| 908 | } |
| 909 | } else { |
| 910 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 911 | file, linenum, args[0]); |
| 912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 913 | goto out; |
| 914 | } |
| 915 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 916 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 917 | if (*args[1]) { |
| 918 | global.tune.pattern_cache = atoi(args[1]); |
| 919 | if (global.tune.pattern_cache < 0) { |
| 920 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 921 | file, linenum, args[0]); |
| 922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 923 | goto out; |
| 924 | } |
| 925 | } else { |
| 926 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 927 | file, linenum, args[0]); |
| 928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 929 | goto out; |
| 930 | } |
| 931 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 932 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 933 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 934 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 935 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 936 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 937 | err_code |= ERR_ALERT; |
| 938 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 939 | } |
| 940 | if (*(args[1]) == 0) { |
| 941 | 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] | 942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 943 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 944 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 945 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 946 | 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]); |
| 947 | err_code |= ERR_WARN; |
| 948 | goto out; |
| 949 | } |
| 950 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 951 | } |
| 952 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 953 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 954 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 955 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 956 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 957 | err_code |= ERR_ALERT; |
| 958 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 959 | } |
| 960 | if (*(args[1]) == 0) { |
| 961 | 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] | 962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 963 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 964 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 965 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 966 | 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]); |
| 967 | err_code |= ERR_WARN; |
| 968 | goto out; |
| 969 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 970 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 971 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 972 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 973 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 974 | global.external_check = 1; |
| 975 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 976 | /* user/group name handling */ |
| 977 | else if (!strcmp(args[0], "user")) { |
| 978 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 979 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 980 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 981 | if (global.uid != 0) { |
| 982 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 983 | err_code |= ERR_ALERT; |
| 984 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 985 | } |
| 986 | errno = 0; |
| 987 | ha_user = getpwnam(args[1]); |
| 988 | if (ha_user != NULL) { |
| 989 | global.uid = (int)ha_user->pw_uid; |
| 990 | } |
| 991 | else { |
| 992 | 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] | 993 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | else if (!strcmp(args[0], "group")) { |
| 997 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 998 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 999 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1000 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1001 | 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] | 1002 | err_code |= ERR_ALERT; |
| 1003 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1004 | } |
| 1005 | errno = 0; |
| 1006 | ha_group = getgrnam(args[1]); |
| 1007 | if (ha_group != NULL) { |
| 1008 | global.gid = (int)ha_group->gr_gid; |
| 1009 | } |
| 1010 | else { |
| 1011 | 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] | 1012 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1016 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1017 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1018 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1019 | if (*(args[1]) == 0) { |
| 1020 | 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] | 1021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1022 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1023 | } |
| 1024 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1025 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1026 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1027 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1029 | goto out; |
| 1030 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1031 | } |
| 1032 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1033 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1034 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1035 | if (global.maxconn != 0) { |
| 1036 | 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] | 1037 | err_code |= ERR_ALERT; |
| 1038 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1039 | } |
| 1040 | if (*(args[1]) == 0) { |
| 1041 | 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] | 1042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1043 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1044 | } |
| 1045 | global.maxconn = atol(args[1]); |
| 1046 | #ifdef SYSTEM_MAXCONN |
| 1047 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1048 | 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); |
| 1049 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1050 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1051 | } |
| 1052 | #endif /* SYSTEM_MAXCONN */ |
| 1053 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1054 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1055 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1056 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1057 | if (*(args[1]) == 0) { |
| 1058 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1060 | goto out; |
| 1061 | } |
| 1062 | if (strcmp(args[1],"none") == 0) |
| 1063 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1064 | else if (strcmp(args[1],"required") == 0) |
| 1065 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1066 | else { |
| 1067 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1069 | goto out; |
| 1070 | } |
| 1071 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1072 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1073 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1074 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1075 | if (global.cps_lim != 0) { |
| 1076 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1077 | err_code |= ERR_ALERT; |
| 1078 | goto out; |
| 1079 | } |
| 1080 | if (*(args[1]) == 0) { |
| 1081 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1083 | goto out; |
| 1084 | } |
| 1085 | global.cps_lim = atol(args[1]); |
| 1086 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1087 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1088 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1089 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1090 | if (global.sps_lim != 0) { |
| 1091 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1092 | err_code |= ERR_ALERT; |
| 1093 | goto out; |
| 1094 | } |
| 1095 | if (*(args[1]) == 0) { |
| 1096 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1098 | goto out; |
| 1099 | } |
| 1100 | global.sps_lim = atol(args[1]); |
| 1101 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1102 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1103 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1104 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1105 | if (global.ssl_lim != 0) { |
| 1106 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1107 | err_code |= ERR_ALERT; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | if (*(args[1]) == 0) { |
| 1111 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1113 | goto out; |
| 1114 | } |
| 1115 | global.ssl_lim = atol(args[1]); |
| 1116 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1117 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1118 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1119 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1120 | if (*(args[1]) == 0) { |
| 1121 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1123 | goto out; |
| 1124 | } |
| 1125 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1126 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1127 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1128 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1129 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1130 | if (global.maxpipes != 0) { |
| 1131 | 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] | 1132 | err_code |= ERR_ALERT; |
| 1133 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1134 | } |
| 1135 | if (*(args[1]) == 0) { |
| 1136 | 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] | 1137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1138 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1139 | } |
| 1140 | global.maxpipes = atol(args[1]); |
| 1141 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1142 | else if (!strcmp(args[0], "maxzlibmem")) { |
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; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1145 | if (*(args[1]) == 0) { |
| 1146 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1148 | goto out; |
| 1149 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1150 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1151 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1152 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1153 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1154 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1155 | if (*(args[1]) == 0) { |
| 1156 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1158 | goto out; |
| 1159 | } |
| 1160 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1161 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1162 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1164 | goto out; |
| 1165 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1166 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1167 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1168 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1169 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1170 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1171 | if (global.rlimit_nofile != 0) { |
| 1172 | 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] | 1173 | err_code |= ERR_ALERT; |
| 1174 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1175 | } |
| 1176 | if (*(args[1]) == 0) { |
| 1177 | 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] | 1178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1179 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1180 | } |
| 1181 | global.rlimit_nofile = atol(args[1]); |
| 1182 | } |
| 1183 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1184 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1186 | if (global.chroot != NULL) { |
| 1187 | 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] | 1188 | err_code |= ERR_ALERT; |
| 1189 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1190 | } |
| 1191 | if (*(args[1]) == 0) { |
| 1192 | 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] | 1193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1194 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1195 | } |
| 1196 | global.chroot = strdup(args[1]); |
| 1197 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1198 | else if (!strcmp(args[0], "description")) { |
| 1199 | int i, len=0; |
| 1200 | char *d; |
| 1201 | |
| 1202 | if (!*args[1]) { |
| 1203 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1204 | file, linenum, args[0]); |
| 1205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1206 | goto out; |
| 1207 | } |
| 1208 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1209 | for (i = 1; *args[i]; i++) |
| 1210 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1211 | |
| 1212 | if (global.desc) |
| 1213 | free(global.desc); |
| 1214 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1215 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1216 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1217 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1218 | for (i = 2; *args[i]; i++) |
| 1219 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1220 | } |
| 1221 | else if (!strcmp(args[0], "node")) { |
| 1222 | int i; |
| 1223 | char c; |
| 1224 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1225 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1226 | goto out; |
| 1227 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1228 | for (i=0; args[1][i]; i++) { |
| 1229 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1230 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1231 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1232 | break; |
| 1233 | } |
| 1234 | |
| 1235 | if (!i || args[1][i]) { |
| 1236 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1237 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1238 | file, linenum, args[0]); |
| 1239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1240 | goto out; |
| 1241 | } |
| 1242 | |
| 1243 | if (global.node) |
| 1244 | free(global.node); |
| 1245 | |
| 1246 | global.node = strdup(args[1]); |
| 1247 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1248 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1249 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1251 | if (global.pidfile != NULL) { |
| 1252 | 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] | 1253 | err_code |= ERR_ALERT; |
| 1254 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1255 | } |
| 1256 | if (*(args[1]) == 0) { |
| 1257 | 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] | 1258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1259 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1260 | } |
| 1261 | global.pidfile = strdup(args[1]); |
| 1262 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1263 | else if (!strcmp(args[0], "unix-bind")) { |
| 1264 | int cur_arg = 1; |
| 1265 | while (*(args[cur_arg])) { |
| 1266 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1267 | if (global.unix_bind.prefix != NULL) { |
| 1268 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1269 | err_code |= ERR_ALERT; |
| 1270 | cur_arg += 2; |
| 1271 | continue; |
| 1272 | } |
| 1273 | |
| 1274 | if (*(args[cur_arg+1]) == 0) { |
| 1275 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1277 | goto out; |
| 1278 | } |
| 1279 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1280 | cur_arg += 2; |
| 1281 | continue; |
| 1282 | } |
| 1283 | |
| 1284 | if (!strcmp(args[cur_arg], "mode")) { |
| 1285 | |
| 1286 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1287 | cur_arg += 2; |
| 1288 | continue; |
| 1289 | } |
| 1290 | |
| 1291 | if (!strcmp(args[cur_arg], "uid")) { |
| 1292 | |
| 1293 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1294 | cur_arg += 2; |
| 1295 | continue; |
| 1296 | } |
| 1297 | |
| 1298 | if (!strcmp(args[cur_arg], "gid")) { |
| 1299 | |
| 1300 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1301 | cur_arg += 2; |
| 1302 | continue; |
| 1303 | } |
| 1304 | |
| 1305 | if (!strcmp(args[cur_arg], "user")) { |
| 1306 | struct passwd *user; |
| 1307 | |
| 1308 | user = getpwnam(args[cur_arg + 1]); |
| 1309 | if (!user) { |
| 1310 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1311 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1313 | goto out; |
| 1314 | } |
| 1315 | |
| 1316 | global.unix_bind.ux.uid = user->pw_uid; |
| 1317 | cur_arg += 2; |
| 1318 | continue; |
| 1319 | } |
| 1320 | |
| 1321 | if (!strcmp(args[cur_arg], "group")) { |
| 1322 | struct group *group; |
| 1323 | |
| 1324 | group = getgrnam(args[cur_arg + 1]); |
| 1325 | if (!group) { |
| 1326 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1327 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | |
| 1332 | global.unix_bind.ux.gid = group->gr_gid; |
| 1333 | cur_arg += 2; |
| 1334 | continue; |
| 1335 | } |
| 1336 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1337 | 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] | 1338 | file, linenum, args[0]); |
| 1339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1340 | goto out; |
| 1341 | } |
| 1342 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1343 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1344 | /* delete previous herited or defined syslog servers */ |
| 1345 | struct logsrv *back; |
| 1346 | struct logsrv *tmp; |
| 1347 | |
| 1348 | if (*(args[1]) != 0) { |
| 1349 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1350 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1351 | goto out; |
| 1352 | } |
| 1353 | |
| 1354 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1355 | LIST_DEL(&tmp->list); |
| 1356 | free(tmp); |
| 1357 | } |
| 1358 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1359 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1360 | struct sockaddr_storage *sk; |
| 1361 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1362 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1363 | int arg = 0; |
| 1364 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1365 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1366 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1367 | goto out; |
| 1368 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1369 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1370 | 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] | 1371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1372 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1373 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1374 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1375 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1376 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1377 | /* just after the address, a length may be specified */ |
| 1378 | if (strcmp(args[arg+2], "len") == 0) { |
| 1379 | len = atoi(args[arg+3]); |
| 1380 | if (len < 80 || len > 65535) { |
| 1381 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1382 | file, linenum, args[arg+3]); |
| 1383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1384 | goto out; |
| 1385 | } |
| 1386 | logsrv->maxlen = len; |
| 1387 | |
| 1388 | /* skip these two args */ |
| 1389 | arg += 2; |
| 1390 | } |
| 1391 | else |
| 1392 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1393 | |
Christopher Faulet | 084aa96 | 2017-08-29 16:54:41 +0200 | [diff] [blame] | 1394 | if (logsrv->maxlen > global.max_syslog_len) |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1395 | global.max_syslog_len = logsrv->maxlen; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1396 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1397 | /* after the length, a format may be specified */ |
| 1398 | if (strcmp(args[arg+2], "format") == 0) { |
| 1399 | logsrv->format = get_log_format(args[arg+3]); |
| 1400 | if (logsrv->format < 0) { |
| 1401 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1402 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1403 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1404 | goto out; |
| 1405 | } |
| 1406 | |
| 1407 | /* skip these two args */ |
| 1408 | arg += 2; |
| 1409 | } |
| 1410 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1411 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1412 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1413 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1414 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1415 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1416 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1417 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1418 | 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] | 1419 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1420 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1421 | } |
| 1422 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1423 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1424 | if (*(args[arg+3])) { |
| 1425 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1426 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1427 | 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] | 1428 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1429 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1433 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1434 | if (*(args[arg+4])) { |
| 1435 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1436 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1437 | 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] | 1438 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1439 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1440 | } |
| 1441 | } |
| 1442 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1443 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1444 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1445 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1446 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1447 | free(logsrv); |
| 1448 | goto out; |
| 1449 | } |
| 1450 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1451 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1452 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1453 | if (port1 != port2) { |
| 1454 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1455 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1456 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1457 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1458 | goto out; |
| 1459 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1460 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1461 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1462 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1463 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1464 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1465 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1466 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1467 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1468 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1469 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1470 | |
| 1471 | if (global.log_send_hostname != NULL) { |
| 1472 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1473 | err_code |= ERR_ALERT; |
| 1474 | goto out; |
| 1475 | } |
| 1476 | |
| 1477 | if (*(args[1])) |
| 1478 | name = args[1]; |
| 1479 | else |
| 1480 | name = hostname; |
| 1481 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1482 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1483 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1484 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1485 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1486 | if (global.server_state_base != NULL) { |
| 1487 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1488 | err_code |= ERR_ALERT; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | |
| 1492 | if (!*(args[1])) { |
| 1493 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1494 | err_code |= ERR_FATAL; |
| 1495 | goto out; |
| 1496 | } |
| 1497 | |
| 1498 | global.server_state_base = strdup(args[1]); |
| 1499 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1500 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1501 | if (global.server_state_file != NULL) { |
| 1502 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1503 | err_code |= ERR_ALERT; |
| 1504 | goto out; |
| 1505 | } |
| 1506 | |
| 1507 | if (!*(args[1])) { |
| 1508 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1509 | err_code |= ERR_FATAL; |
| 1510 | goto out; |
| 1511 | } |
| 1512 | |
| 1513 | global.server_state_file = strdup(args[1]); |
| 1514 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1515 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1516 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1517 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1518 | if (*(args[1]) == 0) { |
| 1519 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1521 | goto out; |
| 1522 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1523 | chunk_destroy(&global.log_tag); |
| 1524 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1525 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1526 | 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] | 1527 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1528 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1529 | if (global.spread_checks != 0) { |
| 1530 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1531 | err_code |= ERR_ALERT; |
| 1532 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1533 | } |
| 1534 | if (*(args[1]) == 0) { |
| 1535 | 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] | 1536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1537 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1538 | } |
| 1539 | global.spread_checks = atol(args[1]); |
| 1540 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1541 | 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] | 1542 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1543 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1544 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1545 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1546 | const char *err; |
| 1547 | unsigned int val; |
| 1548 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1549 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1550 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1551 | if (*(args[1]) == 0) { |
| 1552 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1553 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1554 | goto out; |
| 1555 | } |
| 1556 | |
| 1557 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1558 | if (err) { |
| 1559 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1561 | } |
| 1562 | global.max_spread_checks = val; |
| 1563 | if (global.max_spread_checks < 0) { |
| 1564 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1566 | } |
| 1567 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1568 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1569 | #ifdef USE_CPU_AFFINITY |
| 1570 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1571 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1572 | unsigned long cpus = 0; |
| 1573 | |
| 1574 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1575 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1576 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1577 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1578 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1579 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1580 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1581 | proc = atol(args[1]); |
| 1582 | if (proc >= 1 && proc <= LONGBITS) |
| 1583 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1587 | 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", |
| 1588 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1590 | goto out; |
| 1591 | } |
| 1592 | |
| 1593 | cur_arg = 2; |
| 1594 | while (*args[cur_arg]) { |
| 1595 | unsigned int low, high; |
| 1596 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1597 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1598 | char *dash = strchr(args[cur_arg], '-'); |
| 1599 | |
| 1600 | low = high = str2uic(args[cur_arg]); |
| 1601 | if (dash) |
| 1602 | high = str2uic(dash + 1); |
| 1603 | |
| 1604 | if (high < low) { |
| 1605 | unsigned int swap = low; |
| 1606 | low = high; |
| 1607 | high = swap; |
| 1608 | } |
| 1609 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1610 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1611 | 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] | 1612 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1614 | goto out; |
| 1615 | } |
| 1616 | |
| 1617 | while (low <= high) |
| 1618 | cpus |= 1UL << low++; |
| 1619 | } |
| 1620 | else { |
| 1621 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1622 | file, linenum, args[0], args[cur_arg]); |
| 1623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1624 | goto out; |
| 1625 | } |
| 1626 | cur_arg++; |
| 1627 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1628 | for (i = 0; i < LONGBITS; i++) |
| 1629 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1630 | global.cpu_map[i] = cpus; |
| 1631 | #else |
| 1632 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1634 | goto out; |
| 1635 | #endif |
| 1636 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1637 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1638 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1639 | goto out; |
| 1640 | |
| 1641 | if (*(args[2]) == 0) { |
| 1642 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1644 | goto out; |
| 1645 | } |
| 1646 | |
| 1647 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1648 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1649 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1651 | goto out; |
| 1652 | } |
| 1653 | } |
| 1654 | else if (!strcmp(args[0], "unsetenv")) { |
| 1655 | int arg; |
| 1656 | |
| 1657 | if (*(args[1]) == 0) { |
| 1658 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1660 | goto out; |
| 1661 | } |
| 1662 | |
| 1663 | for (arg = 1; *args[arg]; arg++) { |
| 1664 | if (unsetenv(args[arg]) != 0) { |
| 1665 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1667 | goto out; |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | else if (!strcmp(args[0], "resetenv")) { |
| 1672 | extern char **environ; |
| 1673 | char **env = environ; |
| 1674 | |
| 1675 | /* args contain variable names to keep, one per argument */ |
| 1676 | while (*env) { |
| 1677 | int arg; |
| 1678 | |
| 1679 | /* look for current variable in among all those we want to keep */ |
| 1680 | for (arg = 1; *args[arg]; arg++) { |
| 1681 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1682 | (*env)[strlen(args[arg])] == '=') |
| 1683 | break; |
| 1684 | } |
| 1685 | |
| 1686 | /* delete this variable */ |
| 1687 | if (!*args[arg]) { |
| 1688 | char *delim = strchr(*env, '='); |
| 1689 | |
| 1690 | if (!delim || delim - *env >= trash.size) { |
| 1691 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1693 | goto out; |
| 1694 | } |
| 1695 | |
| 1696 | memcpy(trash.str, *env, delim - *env); |
| 1697 | trash.str[delim - *env] = 0; |
| 1698 | |
| 1699 | if (unsetenv(trash.str) != 0) { |
| 1700 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1702 | goto out; |
| 1703 | } |
| 1704 | } |
| 1705 | else |
| 1706 | env++; |
| 1707 | } |
| 1708 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1709 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1710 | struct cfg_kw_list *kwl; |
| 1711 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1712 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1713 | |
| 1714 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1715 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1716 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1717 | continue; |
| 1718 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1719 | 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] | 1720 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1721 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1722 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1723 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1724 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1725 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1726 | err_code |= ERR_WARN; |
| 1727 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1728 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1729 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | } |
| 1733 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1734 | 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] | 1735 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1736 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1737 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1738 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1739 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1740 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1743 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1744 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1745 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1746 | defproxy.mode = PR_MODE_TCP; |
| 1747 | defproxy.state = PR_STNEW; |
| 1748 | defproxy.maxconn = cfg_maxpconn; |
| 1749 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1750 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1751 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1752 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1753 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1754 | defproxy.defsrv.check.fastinter = 0; |
| 1755 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1756 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1757 | defproxy.defsrv.agent.fastinter = 0; |
| 1758 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1759 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1760 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1761 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1762 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1763 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1764 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1765 | defproxy.defsrv.maxqueue = 0; |
| 1766 | defproxy.defsrv.minconn = 0; |
| 1767 | defproxy.defsrv.maxconn = 0; |
| 1768 | defproxy.defsrv.slowstart = 0; |
| 1769 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1770 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1771 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1772 | |
| 1773 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1774 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1777 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1778 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1779 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1780 | * ERR_FATAL in case of error. |
| 1781 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1782 | static int create_cond_regex_rule(const char *file, int line, |
| 1783 | struct proxy *px, int dir, int action, int flags, |
| 1784 | const char *cmd, const char *reg, const char *repl, |
| 1785 | const char **cond_start) |
| 1786 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1787 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1788 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1789 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1790 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1791 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1792 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1793 | int cs; |
| 1794 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1795 | |
| 1796 | if (px == &defproxy) { |
| 1797 | 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] | 1798 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1799 | goto err; |
| 1800 | } |
| 1801 | |
| 1802 | if (*reg == 0) { |
| 1803 | 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] | 1804 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1805 | goto err; |
| 1806 | } |
| 1807 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1808 | if (warnifnotcap(px, PR_CAP_FE | PR_CAP_BE, file, line, cmd, NULL)) |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1809 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1810 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1811 | if (cond_start && |
| 1812 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1813 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1814 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1815 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1816 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1817 | goto err; |
| 1818 | } |
| 1819 | } |
| 1820 | else if (cond_start && **cond_start) { |
| 1821 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1822 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1823 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1824 | goto err; |
| 1825 | } |
| 1826 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1827 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1828 | (dir == SMP_OPT_DIR_REQ) ? |
| 1829 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1830 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1831 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1832 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1833 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1834 | if (!preg) { |
| 1835 | 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] | 1836 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1837 | goto err; |
| 1838 | } |
| 1839 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1840 | cs = !(flags & REG_ICASE); |
| 1841 | cap = !(flags & REG_NOSUB); |
| 1842 | error = NULL; |
| 1843 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1844 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1845 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1846 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1847 | goto err; |
| 1848 | } |
| 1849 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1850 | 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] | 1851 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1852 | if (repl && err) { |
| 1853 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1854 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1855 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1856 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1859 | 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] | 1860 | ret_code |= ERR_WARN; |
| 1861 | |
| 1862 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1863 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1864 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1865 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1866 | err: |
| 1867 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1868 | free(errmsg); |
| 1869 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1872 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1873 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1874 | * Returns the error code, 0 if OK, or any combination of : |
| 1875 | * - ERR_ABORT: must abort ASAP |
| 1876 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1877 | * - ERR_WARN: a warning has been emitted |
| 1878 | * - ERR_ALERT: an alert has been emitted |
| 1879 | * Only the two first ones can stop processing, the two others are just |
| 1880 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1881 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1882 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1883 | { |
| 1884 | static struct peers *curpeers = NULL; |
| 1885 | struct peer *newpeer = NULL; |
| 1886 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1887 | struct bind_conf *bind_conf; |
| 1888 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1889 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1890 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1891 | |
| 1892 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1893 | if (!*args[1]) { |
| 1894 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1895 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1896 | goto out; |
| 1897 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1898 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1899 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1900 | goto out; |
| 1901 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1902 | err = invalid_char(args[1]); |
| 1903 | if (err) { |
| 1904 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1905 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1906 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1907 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1908 | } |
| 1909 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 1910 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1911 | /* |
| 1912 | * If there are two proxies with the same name only following |
| 1913 | * combinations are allowed: |
| 1914 | */ |
| 1915 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1916 | 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] | 1917 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1918 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1922 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1923 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1924 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1925 | goto out; |
| 1926 | } |
| 1927 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 1928 | curpeers->next = cfg_peers; |
| 1929 | cfg_peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1930 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1931 | curpeers->conf.line = linenum; |
| 1932 | curpeers->last_change = now.tv_sec; |
| 1933 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1934 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1935 | } |
| 1936 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1937 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1938 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1939 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1940 | |
| 1941 | if (!*args[2]) { |
| 1942 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1943 | file, linenum, args[0]); |
| 1944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1945 | goto out; |
| 1946 | } |
| 1947 | |
| 1948 | err = invalid_char(args[1]); |
| 1949 | if (err) { |
| 1950 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1951 | file, linenum, *err, args[1]); |
| 1952 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1953 | goto out; |
| 1954 | } |
| 1955 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1956 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1957 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1958 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1959 | goto out; |
| 1960 | } |
| 1961 | |
| 1962 | /* the peers are linked backwards first */ |
| 1963 | curpeers->count++; |
| 1964 | newpeer->next = curpeers->remote; |
| 1965 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1966 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1967 | newpeer->conf.line = linenum; |
| 1968 | |
| 1969 | newpeer->last_change = now.tv_sec; |
| 1970 | newpeer->id = strdup(args[1]); |
| 1971 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1972 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1973 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1974 | 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] | 1975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1976 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1977 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1978 | |
| 1979 | proto = protocol_by_family(sk->ss_family); |
| 1980 | if (!proto || !proto->connect) { |
| 1981 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1982 | file, linenum, args[0], args[1]); |
| 1983 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1984 | goto out; |
| 1985 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1986 | |
| 1987 | if (port1 != port2) { |
| 1988 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1989 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1991 | goto out; |
| 1992 | } |
| 1993 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1994 | if (!port1) { |
| 1995 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1996 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1998 | goto out; |
| 1999 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2000 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2001 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2002 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2003 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2004 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2005 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2006 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2007 | /* Current is local peer, it define a frontend */ |
| 2008 | newpeer->local = 1; |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2009 | cfg_peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2010 | |
| 2011 | if (!curpeers->peers_fe) { |
| 2012 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2013 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2014 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2015 | goto out; |
| 2016 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2017 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2018 | init_new_proxy(curpeers->peers_fe); |
| 2019 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2020 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2021 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2022 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2023 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2024 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2025 | bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW)); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2026 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2027 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2028 | if (errmsg && *errmsg) { |
| 2029 | indent_msg(&errmsg, 2); |
| 2030 | 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] | 2031 | } |
| 2032 | else |
| 2033 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2034 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2035 | err_code |= ERR_FATAL; |
| 2036 | goto out; |
| 2037 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2038 | |
| 2039 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2040 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2041 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2042 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2043 | l->accept = session_accept_fd; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2044 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2045 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2046 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2047 | global.maxsock += l->maxconn; |
| 2048 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2049 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2050 | else { |
| 2051 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2052 | file, linenum, args[0], args[1], |
| 2053 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2054 | err_code |= ERR_FATAL; |
| 2055 | goto out; |
| 2056 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2057 | } |
| 2058 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2059 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2060 | curpeers->state = PR_STSTOPPED; |
| 2061 | } |
| 2062 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2063 | curpeers->state = PR_STNEW; |
| 2064 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2065 | else if (*args[0] != 0) { |
| 2066 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2068 | goto out; |
| 2069 | } |
| 2070 | |
| 2071 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2072 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2073 | return err_code; |
| 2074 | } |
| 2075 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2076 | /* |
| 2077 | * Parse a <resolvers> section. |
| 2078 | * Returns the error code, 0 if OK, or any combination of : |
| 2079 | * - ERR_ABORT: must abort ASAP |
| 2080 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2081 | * - ERR_WARN: a warning has been emitted |
| 2082 | * - ERR_ALERT: an alert has been emitted |
| 2083 | * Only the two first ones can stop processing, the two others are just |
| 2084 | * indicators. |
| 2085 | */ |
| 2086 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2087 | { |
| 2088 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2089 | struct dns_nameserver *newnameserver = NULL; |
| 2090 | const char *err; |
| 2091 | int err_code = 0; |
| 2092 | char *errmsg = NULL; |
| 2093 | |
| 2094 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2095 | if (!*args[1]) { |
| 2096 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2097 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2098 | goto out; |
| 2099 | } |
| 2100 | |
| 2101 | err = invalid_char(args[1]); |
| 2102 | if (err) { |
| 2103 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2104 | file, linenum, *err, args[0], args[1]); |
| 2105 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2106 | goto out; |
| 2107 | } |
| 2108 | |
| 2109 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2110 | /* Error if two resolvers owns the same name */ |
| 2111 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2112 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2113 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2114 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2118 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2119 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2120 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2121 | goto out; |
| 2122 | } |
| 2123 | |
| 2124 | /* default values */ |
| 2125 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2126 | curr_resolvers->conf.file = strdup(file); |
| 2127 | curr_resolvers->conf.line = linenum; |
| 2128 | curr_resolvers->id = strdup(args[1]); |
| 2129 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2130 | /* default maximum response size */ |
| 2131 | curr_resolvers->accepted_payload_size = 512; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2132 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2133 | curr_resolvers->hold.nx = 30000; |
| 2134 | curr_resolvers->hold.other = 30000; |
| 2135 | curr_resolvers->hold.refused = 30000; |
| 2136 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 686408b | 2017-08-18 10:15:42 +0200 | [diff] [blame] | 2137 | curr_resolvers->hold.obsolete = 0; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2138 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2139 | curr_resolvers->hold.valid = 10000; |
| 2140 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2141 | curr_resolvers->resolve_retries = 3; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2142 | /* default resolution pool size */ |
| 2143 | curr_resolvers->resolution_pool_size = DNS_DEFAULT_RESOLUTION_POOL_SIZE; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2144 | LIST_INIT(&curr_resolvers->nameserver_list); |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2145 | LIST_INIT(&curr_resolvers->resolution.curr); |
| 2146 | LIST_INIT(&curr_resolvers->resolution.wait); |
| 2147 | LIST_INIT(&curr_resolvers->resolution.pool); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2148 | } |
| 2149 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2150 | struct sockaddr_storage *sk; |
| 2151 | int port1, port2; |
| 2152 | struct protocol *proto; |
| 2153 | |
| 2154 | if (!*args[2]) { |
| 2155 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2156 | file, linenum, args[0]); |
| 2157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2158 | goto out; |
| 2159 | } |
| 2160 | |
| 2161 | err = invalid_char(args[1]); |
| 2162 | if (err) { |
| 2163 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2164 | file, linenum, *err, args[1]); |
| 2165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2166 | goto out; |
| 2167 | } |
| 2168 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2169 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2170 | /* Error if two resolvers owns the same name */ |
| 2171 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2172 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2173 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2175 | } |
| 2176 | } |
| 2177 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2178 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2179 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2180 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2181 | goto out; |
| 2182 | } |
| 2183 | |
| 2184 | /* the nameservers are linked backward first */ |
| 2185 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2186 | curr_resolvers->count_nameservers++; |
| 2187 | newnameserver->resolvers = curr_resolvers; |
| 2188 | newnameserver->conf.file = strdup(file); |
| 2189 | newnameserver->conf.line = linenum; |
| 2190 | newnameserver->id = strdup(args[1]); |
| 2191 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2192 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2193 | if (!sk) { |
| 2194 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2196 | goto out; |
| 2197 | } |
| 2198 | |
| 2199 | proto = protocol_by_family(sk->ss_family); |
| 2200 | if (!proto || !proto->connect) { |
| 2201 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2202 | file, linenum, args[0], args[1]); |
| 2203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2204 | goto out; |
| 2205 | } |
| 2206 | |
| 2207 | if (port1 != port2) { |
| 2208 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2209 | file, linenum, args[0], args[1], args[2]); |
| 2210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2211 | goto out; |
| 2212 | } |
| 2213 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2214 | if (!port1 && !port2) { |
| 2215 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2216 | file, linenum, args[0], args[1]); |
| 2217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2218 | goto out; |
| 2219 | } |
| 2220 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2221 | newnameserver->addr = *sk; |
| 2222 | } |
| 2223 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2224 | const char *res; |
| 2225 | unsigned int time; |
| 2226 | |
| 2227 | if (!*args[2]) { |
| 2228 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2229 | file, linenum, args[0]); |
| 2230 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2232 | goto out; |
| 2233 | } |
| 2234 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2235 | if (res) { |
| 2236 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2237 | file, linenum, *res, args[0]); |
| 2238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2239 | goto out; |
| 2240 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2241 | if (strcmp(args[1], "nx") == 0) |
| 2242 | curr_resolvers->hold.nx = time; |
| 2243 | else if (strcmp(args[1], "other") == 0) |
| 2244 | curr_resolvers->hold.other = time; |
| 2245 | else if (strcmp(args[1], "refused") == 0) |
| 2246 | curr_resolvers->hold.refused = time; |
| 2247 | else if (strcmp(args[1], "timeout") == 0) |
| 2248 | curr_resolvers->hold.timeout = time; |
| 2249 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2250 | curr_resolvers->hold.valid = time; |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2251 | else if (strcmp(args[1], "obsolete") == 0) |
| 2252 | curr_resolvers->hold.obsolete = time; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2253 | else { |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2254 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n", |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2255 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2257 | goto out; |
| 2258 | } |
| 2259 | |
| 2260 | } |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2261 | else if (strcmp(args[0], "accepted_payload_size") == 0) { |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2262 | int i = 0; |
| 2263 | |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2264 | if (!*args[1]) { |
| 2265 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2266 | file, linenum, args[0]); |
| 2267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2268 | goto out; |
| 2269 | } |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2270 | |
| 2271 | i = atoi(args[1]); |
Willy Tarreau | 0c219be | 2017-08-22 12:01:26 +0200 | [diff] [blame] | 2272 | if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) { |
| 2273 | Alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n", |
| 2274 | file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]); |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2276 | goto out; |
| 2277 | } |
| 2278 | |
| 2279 | curr_resolvers->accepted_payload_size = i; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2280 | } |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2281 | else if (strcmp(args[0], "resolution_pool_size") == 0) { |
| 2282 | if (!*args[1]) { |
| 2283 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2284 | file, linenum, args[0]); |
| 2285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2286 | goto out; |
| 2287 | } |
| 2288 | curr_resolvers->resolution_pool_size = atoi(args[1]); |
| 2289 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2290 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2291 | if (!*args[1]) { |
| 2292 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2293 | file, linenum, args[0]); |
| 2294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2295 | goto out; |
| 2296 | } |
| 2297 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2298 | } |
| 2299 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2300 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2301 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2302 | file, linenum, args[0]); |
| 2303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2304 | goto out; |
| 2305 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2306 | else if (strcmp(args[1], "retry") == 0) { |
| 2307 | const char *res; |
| 2308 | unsigned int timeout_retry; |
| 2309 | |
| 2310 | if (!*args[2]) { |
| 2311 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2312 | file, linenum, args[0], args[1]); |
| 2313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2314 | goto out; |
| 2315 | } |
| 2316 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2317 | if (res) { |
| 2318 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2319 | file, linenum, *res, args[0], args[1]); |
| 2320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2321 | goto out; |
| 2322 | } |
| 2323 | curr_resolvers->timeout.retry = timeout_retry; |
| 2324 | } |
| 2325 | else { |
| 2326 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2327 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2331 | } /* neither "nameserver" nor "resolvers" */ |
| 2332 | else if (*args[0] != 0) { |
| 2333 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2335 | goto out; |
| 2336 | } |
| 2337 | |
| 2338 | out: |
| 2339 | free(errmsg); |
| 2340 | return err_code; |
| 2341 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2342 | |
| 2343 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2344 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2345 | * Returns the error code, 0 if OK, or any combination of : |
| 2346 | * - ERR_ABORT: must abort ASAP |
| 2347 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2348 | * - ERR_WARN: a warning has been emitted |
| 2349 | * - ERR_ALERT: an alert has been emitted |
| 2350 | * Only the two first ones can stop processing, the two others are just |
| 2351 | * indicators. |
| 2352 | */ |
| 2353 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2354 | { |
| 2355 | static struct mailers *curmailers = NULL; |
| 2356 | struct mailer *newmailer = NULL; |
| 2357 | const char *err; |
| 2358 | int err_code = 0; |
| 2359 | char *errmsg = NULL; |
| 2360 | |
| 2361 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2362 | if (!*args[1]) { |
| 2363 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2364 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2365 | goto out; |
| 2366 | } |
| 2367 | |
| 2368 | err = invalid_char(args[1]); |
| 2369 | if (err) { |
| 2370 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2371 | file, linenum, *err, args[0], args[1]); |
| 2372 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2373 | goto out; |
| 2374 | } |
| 2375 | |
| 2376 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2377 | /* |
| 2378 | * If there are two proxies with the same name only following |
| 2379 | * combinations are allowed: |
| 2380 | */ |
| 2381 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2382 | 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] | 2383 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2384 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2388 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2389 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2390 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2391 | goto out; |
| 2392 | } |
| 2393 | |
| 2394 | curmailers->next = mailers; |
| 2395 | mailers = curmailers; |
| 2396 | curmailers->conf.file = strdup(file); |
| 2397 | curmailers->conf.line = linenum; |
| 2398 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2399 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2400 | * But need enough time so that timeouts don't occur |
| 2401 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2402 | } |
| 2403 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2404 | struct sockaddr_storage *sk; |
| 2405 | int port1, port2; |
| 2406 | struct protocol *proto; |
| 2407 | |
| 2408 | if (!*args[2]) { |
| 2409 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2410 | file, linenum, args[0]); |
| 2411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | |
| 2415 | err = invalid_char(args[1]); |
| 2416 | if (err) { |
| 2417 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2418 | file, linenum, *err, args[1]); |
| 2419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2420 | goto out; |
| 2421 | } |
| 2422 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2423 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2424 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2425 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2426 | goto out; |
| 2427 | } |
| 2428 | |
| 2429 | /* the mailers are linked backwards first */ |
| 2430 | curmailers->count++; |
| 2431 | newmailer->next = curmailers->mailer_list; |
| 2432 | curmailers->mailer_list = newmailer; |
| 2433 | newmailer->mailers = curmailers; |
| 2434 | newmailer->conf.file = strdup(file); |
| 2435 | newmailer->conf.line = linenum; |
| 2436 | |
| 2437 | newmailer->id = strdup(args[1]); |
| 2438 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2439 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2440 | if (!sk) { |
| 2441 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2443 | goto out; |
| 2444 | } |
| 2445 | |
| 2446 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2447 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2448 | 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] | 2449 | file, linenum, args[0], args[1]); |
| 2450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2451 | goto out; |
| 2452 | } |
| 2453 | |
| 2454 | if (port1 != port2) { |
| 2455 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2456 | file, linenum, args[0], args[1], args[2]); |
| 2457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2458 | goto out; |
| 2459 | } |
| 2460 | |
| 2461 | if (!port1) { |
| 2462 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2463 | file, linenum, args[0], args[1], args[2]); |
| 2464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2465 | goto out; |
| 2466 | } |
| 2467 | |
| 2468 | newmailer->addr = *sk; |
| 2469 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2470 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2471 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2472 | } |
| 2473 | else if (strcmp(args[0], "timeout") == 0) { |
| 2474 | if (!*args[1]) { |
| 2475 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2476 | file, linenum, args[0]); |
| 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
| 2479 | } |
| 2480 | else if (strcmp(args[1], "mail") == 0) { |
| 2481 | const char *res; |
| 2482 | unsigned int timeout_mail; |
| 2483 | if (!*args[2]) { |
| 2484 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2485 | file, linenum, args[0], args[1]); |
| 2486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2487 | goto out; |
| 2488 | } |
| 2489 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2490 | if (res) { |
| 2491 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2492 | file, linenum, *res, args[0]); |
| 2493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2494 | goto out; |
| 2495 | } |
| 2496 | if (timeout_mail <= 0) { |
| 2497 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2499 | goto out; |
| 2500 | } |
| 2501 | curmailers->timeout.mail = timeout_mail; |
| 2502 | } else { |
| 2503 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2504 | file, linenum, args[0], args[1]); |
| 2505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2506 | goto out; |
| 2507 | } |
| 2508 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2509 | else if (*args[0] != 0) { |
| 2510 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2512 | goto out; |
| 2513 | } |
| 2514 | |
| 2515 | out: |
| 2516 | free(errmsg); |
| 2517 | return err_code; |
| 2518 | } |
| 2519 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2520 | static void free_email_alert(struct proxy *p) |
| 2521 | { |
| 2522 | free(p->email_alert.mailers.name); |
| 2523 | p->email_alert.mailers.name = NULL; |
| 2524 | free(p->email_alert.from); |
| 2525 | p->email_alert.from = NULL; |
| 2526 | free(p->email_alert.to); |
| 2527 | p->email_alert.to = NULL; |
| 2528 | free(p->email_alert.myhostname); |
| 2529 | p->email_alert.myhostname = NULL; |
| 2530 | } |
| 2531 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2532 | 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] | 2533 | { |
| 2534 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2535 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2536 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2537 | int rc; |
| 2538 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2539 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2540 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2541 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2542 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2543 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2544 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2545 | if (!strcmp(args[0], "listen")) |
| 2546 | rc = PR_CAP_LISTEN; |
| 2547 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2548 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2549 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2550 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2551 | else |
| 2552 | rc = PR_CAP_NONE; |
| 2553 | |
| 2554 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2555 | if (!*args[1]) { |
| 2556 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2557 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2558 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2559 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2560 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2561 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2562 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2563 | err = invalid_char(args[1]); |
| 2564 | if (err) { |
| 2565 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2566 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2567 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2568 | } |
| 2569 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2570 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2571 | if (curproxy) { |
| 2572 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2573 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2574 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2575 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2576 | } |
| 2577 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2578 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2579 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2580 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2581 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2582 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2583 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2584 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2585 | curproxy->next = proxy; |
| 2586 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2587 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2588 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2589 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2590 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2591 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2592 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2593 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2594 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2595 | if (curproxy->cap & PR_CAP_FE) |
| 2596 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2597 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2601 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2602 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2603 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2604 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2605 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2606 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2607 | curproxy->no_options = defproxy.no_options; |
| 2608 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2609 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2610 | curproxy->except_net = defproxy.except_net; |
| 2611 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2612 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2613 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2614 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2615 | if (defproxy.fwdfor_hdr_len) { |
| 2616 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2617 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2618 | } |
| 2619 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2620 | if (defproxy.orgto_hdr_len) { |
| 2621 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2622 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2623 | } |
| 2624 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2625 | if (defproxy.server_id_hdr_len) { |
| 2626 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2627 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2628 | } |
| 2629 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2630 | if (curproxy->cap & PR_CAP_FE) { |
| 2631 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2632 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2633 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2634 | |
| 2635 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2636 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2637 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2638 | |
| 2639 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2640 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2641 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2642 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2643 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2644 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2645 | curproxy->fullconn = defproxy.fullconn; |
| 2646 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2647 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2648 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2649 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2650 | if (defproxy.check_req) { |
| 2651 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2652 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2653 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2654 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2655 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2656 | if (defproxy.expect_str) { |
| 2657 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2658 | if (defproxy.expect_regex) { |
| 2659 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2660 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2661 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2665 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2666 | if (defproxy.cookie_name) |
| 2667 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2668 | curproxy->cookie_len = defproxy.cookie_len; |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2669 | |
| 2670 | if (defproxy.dyncookie_key) |
| 2671 | curproxy->dyncookie_key = strdup(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2672 | if (defproxy.cookie_domain) |
| 2673 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2674 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2675 | if (defproxy.cookie_maxidle) |
| 2676 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2677 | |
| 2678 | if (defproxy.cookie_maxlife) |
| 2679 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2680 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2681 | if (defproxy.rdp_cookie_name) |
| 2682 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2683 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2684 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2685 | if (defproxy.url_param_name) |
| 2686 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2687 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2688 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2689 | if (defproxy.hh_name) |
| 2690 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2691 | curproxy->hh_len = defproxy.hh_len; |
| 2692 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2693 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2694 | if (defproxy.conn_src.iface_name) |
| 2695 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2696 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2697 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2698 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2699 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2700 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2701 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2702 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2703 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2704 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2705 | if (defproxy.capture_name) |
| 2706 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2707 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2708 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2710 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2711 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2712 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2713 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2714 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2715 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2716 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2717 | curproxy->mon_net = defproxy.mon_net; |
| 2718 | curproxy->mon_mask = defproxy.mon_mask; |
| 2719 | if (defproxy.monitor_uri) |
| 2720 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2721 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2722 | if (defproxy.defbe.name) |
| 2723 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2724 | |
| 2725 | /* 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] | 2726 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2727 | if (curproxy->conf.logformat_string && |
| 2728 | curproxy->conf.logformat_string != default_http_log_format && |
| 2729 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2730 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2731 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2732 | |
| 2733 | if (defproxy.conf.lfs_file) { |
| 2734 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2735 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2736 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2737 | |
| 2738 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2739 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2740 | if (curproxy->conf.logformat_sd_string && |
| 2741 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2742 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2743 | |
| 2744 | if (defproxy.conf.lfsd_file) { |
| 2745 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2746 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2747 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2751 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2752 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2753 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2754 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2755 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2756 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2757 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2758 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2759 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2760 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2761 | } |
| 2762 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2763 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2764 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2765 | |
| 2766 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2767 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2768 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2769 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2770 | LIST_INIT(&node->list); |
| 2771 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2772 | } |
| 2773 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2774 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2775 | if (curproxy->conf.uniqueid_format_string) |
| 2776 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2777 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2778 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2779 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2780 | if (defproxy.conf.uif_file) { |
| 2781 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2782 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2783 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2784 | |
| 2785 | /* copy default header unique id */ |
| 2786 | if (defproxy.header_unique_id) |
| 2787 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2788 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2789 | /* default compression options */ |
| 2790 | if (defproxy.comp != NULL) { |
| 2791 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2792 | curproxy->comp->algos = defproxy.comp->algos; |
| 2793 | curproxy->comp->types = defproxy.comp->types; |
| 2794 | } |
| 2795 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2796 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2797 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2798 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2799 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2800 | if (defproxy.check_path) |
| 2801 | curproxy->check_path = strdup(defproxy.check_path); |
| 2802 | if (defproxy.check_command) |
| 2803 | curproxy->check_command = strdup(defproxy.check_command); |
| 2804 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2805 | if (defproxy.email_alert.mailers.name) |
| 2806 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 2807 | if (defproxy.email_alert.from) |
| 2808 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 2809 | if (defproxy.email_alert.to) |
| 2810 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 2811 | if (defproxy.email_alert.myhostname) |
| 2812 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2813 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 2814 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2815 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2816 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2817 | } |
| 2818 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2819 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2820 | /* FIXME-20070101: we should do this too at the end of the |
| 2821 | * config parsing to free all default values. |
| 2822 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2823 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2824 | err_code |= ERR_ABORT; |
| 2825 | goto out; |
| 2826 | } |
| 2827 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2828 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2829 | free(defproxy.check_command); |
| 2830 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2831 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2832 | free(defproxy.rdp_cookie_name); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2833 | free(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2834 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2835 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2836 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2837 | free(defproxy.capture_name); |
| 2838 | free(defproxy.monitor_uri); |
| 2839 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2840 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2841 | free(defproxy.fwdfor_hdr_name); |
| 2842 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2843 | free(defproxy.orgto_hdr_name); |
| 2844 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2845 | free(defproxy.server_id_hdr_name); |
| 2846 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2847 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2848 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2849 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2850 | free(defproxy.expect_regex); |
| 2851 | defproxy.expect_regex = NULL; |
| 2852 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2853 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2854 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2855 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2856 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2857 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2858 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2859 | free(defproxy.conf.uniqueid_format_string); |
| 2860 | free(defproxy.conf.lfs_file); |
| 2861 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2862 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2863 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2864 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2865 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2866 | free(defproxy.conf.logformat_sd_string); |
| 2867 | free(defproxy.conf.lfsd_file); |
| 2868 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2869 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2870 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2871 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2872 | /* we cannot free uri_auth because it might already be used */ |
| 2873 | init_default_instance(); |
| 2874 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2875 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2876 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2877 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2878 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2879 | } |
| 2880 | else if (curproxy == NULL) { |
| 2881 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2883 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2884 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2885 | |
| 2886 | /* update the current file and line being parsed */ |
| 2887 | curproxy->conf.args.file = curproxy->conf.file; |
| 2888 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2889 | |
| 2890 | /* Now let's parse the proxy-specific keywords */ |
Frédéric Lécaille | b82f742 | 2017-04-13 18:24:23 +0200 | [diff] [blame] | 2891 | if (!strcmp(args[0], "server") || |
| 2892 | !strcmp(args[0], "default-server") || |
| 2893 | !strcmp(args[0], "server-template")) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2894 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2895 | if (err_code & ERR_FATAL) |
| 2896 | goto out; |
| 2897 | } |
| 2898 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2899 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2900 | int cur_arg; |
| 2901 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2902 | if (curproxy == &defproxy) { |
| 2903 | 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] | 2904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2905 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2906 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2907 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2908 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2909 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2910 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2911 | 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] | 2912 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2914 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2915 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2916 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2917 | bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW)); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 2918 | |
| 2919 | /* use default settings for unix sockets */ |
| 2920 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2921 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2922 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2923 | |
| 2924 | /* NOTE: the following line might create several listeners if there |
| 2925 | * are comma-separated IPs or port ranges. So all further processing |
| 2926 | * will have to be applied to all listeners created after last_listen. |
| 2927 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2928 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2929 | if (errmsg && *errmsg) { |
| 2930 | indent_msg(&errmsg, 2); |
| 2931 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2932 | } |
| 2933 | else |
| 2934 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2935 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2937 | goto out; |
| 2938 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2939 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2940 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2941 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2942 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2943 | } |
| 2944 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2945 | cur_arg = 2; |
| 2946 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2947 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2948 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2949 | char *err; |
| 2950 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2951 | kw = bind_find_kw(args[cur_arg]); |
| 2952 | if (kw) { |
| 2953 | char *err = NULL; |
| 2954 | int code; |
| 2955 | |
| 2956 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2957 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2958 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2959 | cur_arg += 1 + kw->skip ; |
| 2960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2961 | goto out; |
| 2962 | } |
| 2963 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2964 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2965 | err_code |= code; |
| 2966 | |
| 2967 | if (code) { |
| 2968 | if (err && *err) { |
| 2969 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2970 | 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] | 2971 | } |
| 2972 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2973 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2974 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2975 | if (code & ERR_FATAL) { |
| 2976 | free(err); |
| 2977 | cur_arg += 1 + kw->skip; |
| 2978 | goto out; |
| 2979 | } |
| 2980 | } |
| 2981 | free(err); |
| 2982 | cur_arg += 1 + kw->skip; |
| 2983 | continue; |
| 2984 | } |
| 2985 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2986 | err = NULL; |
| 2987 | if (!bind_dumped) { |
| 2988 | bind_dump_kws(&err); |
| 2989 | indent_msg(&err, 4); |
| 2990 | bind_dumped = 1; |
| 2991 | } |
| 2992 | |
| 2993 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2994 | file, linenum, args[0], args[1], args[cur_arg], |
| 2995 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2996 | free(err); |
| 2997 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2999 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3000 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3001 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3002 | } |
| 3003 | 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] | 3004 | 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] | 3005 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3006 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3008 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3009 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3010 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3011 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3012 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3013 | /* flush useless bits */ |
| 3014 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3015 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3016 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3017 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3018 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3019 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3020 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3021 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3022 | goto out; |
| 3023 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3024 | if (!*args[1]) { |
| 3025 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3026 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3028 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3029 | } |
| 3030 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3031 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3032 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3033 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3034 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3035 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3036 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3037 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3038 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3039 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3040 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3041 | goto out; |
| 3042 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3043 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3044 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3045 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3046 | else { |
| 3047 | 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] | 3048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3049 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3050 | } |
| 3051 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3052 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3053 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3054 | |
| 3055 | if (curproxy == &defproxy) { |
| 3056 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3057 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3058 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3059 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3062 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3063 | goto out; |
| 3064 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3065 | if (!*args[1]) { |
| 3066 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3067 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3069 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3073 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3074 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3075 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3076 | if (curproxy->uuid <= 0) { |
| 3077 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3078 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3080 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3083 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3084 | if (node) { |
| 3085 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3086 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3087 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3088 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3090 | goto out; |
| 3091 | } |
| 3092 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3093 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3094 | else if (!strcmp(args[0], "description")) { |
| 3095 | int i, len=0; |
| 3096 | char *d; |
| 3097 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3098 | if (curproxy == &defproxy) { |
| 3099 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3100 | file, linenum, args[0]); |
| 3101 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3102 | goto out; |
| 3103 | } |
| 3104 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3105 | if (!*args[1]) { |
| 3106 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3107 | file, linenum, args[0]); |
| 3108 | return -1; |
| 3109 | } |
| 3110 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3111 | for (i = 1; *args[i]; i++) |
| 3112 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3113 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3114 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3115 | curproxy->desc = d; |
| 3116 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3117 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3118 | for (i = 2; *args[i]; i++) |
| 3119 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3120 | |
| 3121 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3122 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3123 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3124 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3125 | curproxy->state = PR_STSTOPPED; |
| 3126 | } |
| 3127 | 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] | 3128 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3129 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3130 | curproxy->state = PR_STNEW; |
| 3131 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3132 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3133 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3134 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3135 | |
| 3136 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3137 | unsigned int low, high; |
| 3138 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3139 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3140 | set = 0; |
| 3141 | break; |
| 3142 | } |
| 3143 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3144 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3145 | } |
| 3146 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3147 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3148 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3149 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3150 | char *dash = strchr(args[cur_arg], '-'); |
| 3151 | |
| 3152 | low = high = str2uic(args[cur_arg]); |
| 3153 | if (dash) |
| 3154 | high = str2uic(dash + 1); |
| 3155 | |
| 3156 | if (high < low) { |
| 3157 | unsigned int swap = low; |
| 3158 | low = high; |
| 3159 | high = swap; |
| 3160 | } |
| 3161 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3162 | if (low < 1 || high > LONGBITS) { |
| 3163 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3164 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3166 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3167 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3168 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3169 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3170 | } |
| 3171 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3172 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3173 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3175 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3176 | } |
| 3177 | cur_arg++; |
| 3178 | } |
| 3179 | curproxy->bind_proc = set; |
| 3180 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3181 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3182 | if (curproxy == &defproxy) { |
| 3183 | 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] | 3184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3185 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3186 | } |
| 3187 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3188 | err = invalid_char(args[1]); |
| 3189 | if (err) { |
| 3190 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3191 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1822e8c | 2017-04-12 18:54:00 +0200 | [diff] [blame] | 3193 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3194 | } |
| 3195 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3196 | 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] | 3197 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3198 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3200 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3201 | } |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3202 | } |
| 3203 | else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */ |
| 3204 | |
| 3205 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3206 | err_code |= ERR_WARN; |
| 3207 | |
| 3208 | if (*(args[1]) == 0) { |
| 3209 | Alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 3210 | file, linenum, args[0]); |
| 3211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3212 | goto out; |
| 3213 | } |
| 3214 | free(curproxy->dyncookie_key); |
| 3215 | curproxy->dyncookie_key = strdup(args[1]); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3216 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3217 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3218 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3219 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3220 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3221 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3222 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3223 | if (*(args[1]) == 0) { |
| 3224 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3225 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3227 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3228 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3229 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3230 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3231 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3232 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3233 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3234 | curproxy->cookie_name = strdup(args[1]); |
| 3235 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3236 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3237 | cur_arg = 2; |
| 3238 | while (*(args[cur_arg])) { |
| 3239 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3240 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3241 | } |
| 3242 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3243 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3244 | } |
| 3245 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3246 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3247 | } |
| 3248 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3249 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3250 | } |
| 3251 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3252 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3253 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3254 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3255 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3256 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3257 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3258 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3259 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3260 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3261 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3262 | } |
| 3263 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3264 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3265 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3266 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3267 | if (!*args[cur_arg + 1]) { |
| 3268 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3269 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3271 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3272 | } |
| 3273 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3274 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3275 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3276 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3277 | " dots nor does not start with a dot." |
| 3278 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3279 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3280 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3284 | if (err) { |
| 3285 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3286 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3288 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3289 | } |
| 3290 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3291 | if (!curproxy->cookie_domain) { |
| 3292 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3293 | } else { |
| 3294 | /* one domain was already specified, add another one by |
| 3295 | * building the string which will be returned along with |
| 3296 | * the cookie. |
| 3297 | */ |
| 3298 | char *new_ptr; |
| 3299 | int new_len = strlen(curproxy->cookie_domain) + |
| 3300 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3301 | new_ptr = malloc(new_len); |
| 3302 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3303 | free(curproxy->cookie_domain); |
| 3304 | curproxy->cookie_domain = new_ptr; |
| 3305 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3306 | cur_arg++; |
| 3307 | } |
| 3308 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3309 | unsigned int maxidle; |
| 3310 | const char *res; |
| 3311 | |
| 3312 | if (!*args[cur_arg + 1]) { |
| 3313 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3314 | file, linenum, args[cur_arg]); |
| 3315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3316 | goto out; |
| 3317 | } |
| 3318 | |
| 3319 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3320 | if (res) { |
| 3321 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3322 | file, linenum, *res, args[cur_arg]); |
| 3323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3324 | goto out; |
| 3325 | } |
| 3326 | curproxy->cookie_maxidle = maxidle; |
| 3327 | cur_arg++; |
| 3328 | } |
| 3329 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3330 | unsigned int maxlife; |
| 3331 | const char *res; |
| 3332 | |
| 3333 | if (!*args[cur_arg + 1]) { |
| 3334 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3335 | file, linenum, args[cur_arg]); |
| 3336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3337 | goto out; |
| 3338 | } |
| 3339 | |
| 3340 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3341 | if (res) { |
| 3342 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3343 | file, linenum, *res, args[cur_arg]); |
| 3344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3345 | goto out; |
| 3346 | } |
| 3347 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3348 | cur_arg++; |
| 3349 | } |
Olivier Houchard | a5938f7 | 2017-03-15 15:12:06 +0100 | [diff] [blame] | 3350 | else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */ |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3351 | |
| 3352 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 3353 | err_code |= ERR_WARN; |
| 3354 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 3355 | } |
| 3356 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3357 | else { |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3358 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3359 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3361 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3362 | } |
| 3363 | cur_arg++; |
| 3364 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3365 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3366 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3367 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3369 | } |
| 3370 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3371 | 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] | 3372 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3373 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3374 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3375 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3376 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3377 | 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] | 3378 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3379 | file, linenum); |
| 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3381 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3382 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3383 | else if (!strcmp(args[0], "email-alert")) { |
| 3384 | if (*(args[1]) == 0) { |
| 3385 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3386 | file, linenum, args[0]); |
| 3387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3388 | goto out; |
| 3389 | } |
| 3390 | |
| 3391 | if (!strcmp(args[1], "from")) { |
| 3392 | if (*(args[1]) == 0) { |
| 3393 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3394 | file, linenum, args[1]); |
| 3395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3396 | goto out; |
| 3397 | } |
| 3398 | free(curproxy->email_alert.from); |
| 3399 | curproxy->email_alert.from = strdup(args[2]); |
| 3400 | } |
| 3401 | else if (!strcmp(args[1], "mailers")) { |
| 3402 | if (*(args[1]) == 0) { |
| 3403 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3404 | file, linenum, args[1]); |
| 3405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3406 | goto out; |
| 3407 | } |
| 3408 | free(curproxy->email_alert.mailers.name); |
| 3409 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3410 | } |
| 3411 | else if (!strcmp(args[1], "myhostname")) { |
| 3412 | if (*(args[1]) == 0) { |
| 3413 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3414 | file, linenum, args[1]); |
| 3415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3416 | goto out; |
| 3417 | } |
| 3418 | free(curproxy->email_alert.myhostname); |
| 3419 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3420 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3421 | else if (!strcmp(args[1], "level")) { |
| 3422 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3423 | if (curproxy->email_alert.level < 0) { |
| 3424 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3425 | file, linenum, args[1], args[2]); |
| 3426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3427 | goto out; |
| 3428 | } |
| 3429 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3430 | else if (!strcmp(args[1], "to")) { |
| 3431 | if (*(args[1]) == 0) { |
| 3432 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3433 | file, linenum, args[1]); |
| 3434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3435 | goto out; |
| 3436 | } |
| 3437 | free(curproxy->email_alert.to); |
| 3438 | curproxy->email_alert.to = strdup(args[2]); |
| 3439 | } |
| 3440 | else { |
| 3441 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3442 | file, linenum, args[1]); |
| 3443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3444 | goto out; |
| 3445 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3446 | /* Indicate that the email_alert is at least partially configured */ |
| 3447 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3448 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3449 | else if (!strcmp(args[0], "external-check")) { |
| 3450 | if (*(args[1]) == 0) { |
| 3451 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3452 | file, linenum, args[0]); |
| 3453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3454 | goto out; |
| 3455 | } |
| 3456 | |
| 3457 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3458 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3459 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3460 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3461 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3462 | file, linenum, args[1]); |
| 3463 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3464 | goto out; |
| 3465 | } |
| 3466 | free(curproxy->check_command); |
| 3467 | curproxy->check_command = strdup(args[2]); |
| 3468 | } |
| 3469 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3470 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3471 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3472 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3473 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3474 | file, linenum, args[1]); |
| 3475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3476 | goto out; |
| 3477 | } |
| 3478 | free(curproxy->check_path); |
| 3479 | curproxy->check_path = strdup(args[2]); |
| 3480 | } |
| 3481 | else { |
| 3482 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3483 | file, linenum, args[1]); |
| 3484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3485 | goto out; |
| 3486 | } |
| 3487 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3488 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3489 | if (*(args[1]) == 0) { |
| 3490 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3491 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3493 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3497 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3498 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3499 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3500 | const char *beg, *end; |
| 3501 | |
| 3502 | beg = args[1] + 11; |
| 3503 | end = strchr(beg, ')'); |
| 3504 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3505 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3506 | goto out; |
| 3507 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3508 | if (!end || end == beg) { |
| 3509 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3510 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3512 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | free(curproxy->rdp_cookie_name); |
| 3516 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3517 | curproxy->rdp_cookie_len = end-beg; |
| 3518 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3519 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3520 | free(curproxy->rdp_cookie_name); |
| 3521 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3522 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3523 | } |
| 3524 | else { /* syntax */ |
| 3525 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3526 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3528 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3529 | } |
| 3530 | } |
| 3531 | else { |
| 3532 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3533 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3535 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3536 | } |
| 3537 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3538 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3539 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3541 | goto out; |
| 3542 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3543 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3544 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3545 | err_code |= ERR_WARN; |
| 3546 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3547 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3548 | } |
| 3549 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3550 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3551 | } |
| 3552 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3553 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3554 | } |
| 3555 | else { |
| 3556 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3557 | file, linenum, args[0], args[1]); |
| 3558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3559 | goto out; |
| 3560 | } |
| 3561 | } |
| 3562 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3563 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3564 | err_code |= ERR_WARN; |
| 3565 | if (*(args[1]) == 0) { |
| 3566 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3567 | file, linenum, args[0]); |
| 3568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3569 | goto out; |
| 3570 | } |
| 3571 | else if (!strcmp(args[1], "use-backend-name")) |
| 3572 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3573 | else |
| 3574 | curproxy->server_state_file_name = strdup(args[1]); |
| 3575 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3576 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3577 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3578 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3579 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3580 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3581 | if (curproxy == &defproxy) { |
| 3582 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3583 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3584 | goto out; |
| 3585 | } |
| 3586 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3587 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3588 | goto out; |
| 3589 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3590 | if (*(args[4]) == 0) { |
| 3591 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3592 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3594 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3595 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3596 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3597 | curproxy->capture_name = strdup(args[2]); |
| 3598 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3599 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3600 | curproxy->to_log |= LW_COOKIE; |
| 3601 | } |
| 3602 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3603 | struct cap_hdr *hdr; |
| 3604 | |
| 3605 | if (curproxy == &defproxy) { |
| 3606 | 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] | 3607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3609 | } |
| 3610 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3611 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3612 | goto out; |
| 3613 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3614 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3615 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3616 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3618 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3619 | } |
| 3620 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3621 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3622 | hdr->next = curproxy->req_cap; |
| 3623 | hdr->name = strdup(args[3]); |
| 3624 | hdr->namelen = strlen(args[3]); |
| 3625 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3626 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3627 | hdr->index = curproxy->nb_req_cap++; |
| 3628 | curproxy->req_cap = hdr; |
| 3629 | curproxy->to_log |= LW_REQHDR; |
| 3630 | } |
| 3631 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3632 | struct cap_hdr *hdr; |
| 3633 | |
| 3634 | if (curproxy == &defproxy) { |
| 3635 | 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] | 3636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3637 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3638 | } |
| 3639 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3640 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3641 | goto out; |
| 3642 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3643 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3644 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3645 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3647 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3648 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3649 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3650 | hdr->next = curproxy->rsp_cap; |
| 3651 | hdr->name = strdup(args[3]); |
| 3652 | hdr->namelen = strlen(args[3]); |
| 3653 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3654 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3655 | hdr->index = curproxy->nb_rsp_cap++; |
| 3656 | curproxy->rsp_cap = hdr; |
| 3657 | curproxy->to_log |= LW_RSPHDR; |
| 3658 | } |
| 3659 | else { |
| 3660 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3661 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3663 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3664 | } |
| 3665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3666 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3667 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3668 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3669 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3670 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3671 | goto out; |
| 3672 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3673 | if (*(args[1]) == 0) { |
| 3674 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3675 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3677 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3678 | } |
| 3679 | curproxy->conn_retries = atol(args[1]); |
| 3680 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3681 | 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] | 3682 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3683 | |
| 3684 | if (curproxy == &defproxy) { |
| 3685 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3687 | goto out; |
| 3688 | } |
| 3689 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3690 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3691 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3692 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3693 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3694 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3695 | 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] | 3696 | 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] | 3697 | file, linenum, args[0]); |
| 3698 | err_code |= ERR_WARN; |
| 3699 | } |
| 3700 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3701 | 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] | 3702 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3703 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3704 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3705 | goto out; |
| 3706 | } |
| 3707 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3708 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3709 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3710 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3711 | file, linenum); |
| 3712 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3713 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3714 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3715 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3716 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3717 | |
| 3718 | if (curproxy == &defproxy) { |
| 3719 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3721 | goto out; |
| 3722 | } |
| 3723 | |
| 3724 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3725 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3726 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3727 | 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] | 3728 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3729 | file, linenum, args[0]); |
| 3730 | err_code |= ERR_WARN; |
| 3731 | } |
| 3732 | |
| 3733 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3734 | |
| 3735 | if (!rule) { |
| 3736 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3737 | goto out; |
| 3738 | } |
| 3739 | |
| 3740 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3741 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3742 | file, linenum); |
| 3743 | |
| 3744 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3745 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3746 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3747 | /* set the header name and length into the proxy structure */ |
| 3748 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3749 | err_code |= ERR_WARN; |
| 3750 | |
| 3751 | if (!*args[1]) { |
| 3752 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3753 | file, linenum, args[0]); |
| 3754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3755 | goto out; |
| 3756 | } |
| 3757 | |
| 3758 | /* set the desired header name */ |
| 3759 | free(curproxy->server_id_hdr_name); |
| 3760 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3761 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3762 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3763 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3764 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3765 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3766 | if (curproxy == &defproxy) { |
| 3767 | 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] | 3768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3769 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3772 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3773 | * be processed before all http-request rules, we put them into their own list |
| 3774 | * and will insert them at the end. |
| 3775 | */ |
| 3776 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3777 | if (!rule) { |
| 3778 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3779 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3780 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3781 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3782 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3783 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3784 | file, linenum); |
| 3785 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3786 | |
| 3787 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3788 | 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]); |
| 3789 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3790 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3791 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3792 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3793 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3794 | if (curproxy == &defproxy) { |
| 3795 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3797 | goto out; |
| 3798 | } |
| 3799 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3800 | 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] | 3801 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3802 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3804 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3805 | } |
| 3806 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3807 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3808 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3809 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3810 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3811 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3812 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3813 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3814 | struct switching_rule *rule; |
| 3815 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3816 | if (curproxy == &defproxy) { |
| 3817 | 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] | 3818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3819 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3820 | } |
| 3821 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3822 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3823 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3824 | |
| 3825 | if (*(args[1]) == 0) { |
| 3826 | 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] | 3827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3828 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3829 | } |
| 3830 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3831 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3832 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3833 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3834 | file, linenum, errmsg); |
| 3835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3836 | goto out; |
| 3837 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3838 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3839 | 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] | 3840 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 3841 | else if (*args[2]) { |
| 3842 | Alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 3843 | file, linenum, args[2]); |
| 3844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3845 | goto out; |
| 3846 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3847 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3848 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 3849 | if (!rule) { |
| 3850 | Alert("Out of memory error.\n"); |
| 3851 | goto out; |
| 3852 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3853 | rule->cond = cond; |
| 3854 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 3855 | rule->line = linenum; |
| 3856 | rule->file = strdup(file); |
| 3857 | if (!rule->file) { |
| 3858 | Alert("Out of memory error.\n"); |
| 3859 | goto out; |
| 3860 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3861 | LIST_INIT(&rule->list); |
| 3862 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3863 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3864 | else if (strcmp(args[0], "use-server") == 0) { |
| 3865 | struct server_rule *rule; |
| 3866 | |
| 3867 | if (curproxy == &defproxy) { |
| 3868 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3870 | goto out; |
| 3871 | } |
| 3872 | |
| 3873 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3874 | err_code |= ERR_WARN; |
| 3875 | |
| 3876 | if (*(args[1]) == 0) { |
| 3877 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3879 | goto out; |
| 3880 | } |
| 3881 | |
| 3882 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3883 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3884 | file, linenum, args[0]); |
| 3885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3886 | goto out; |
| 3887 | } |
| 3888 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3889 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3890 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3891 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3893 | goto out; |
| 3894 | } |
| 3895 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3896 | 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] | 3897 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3898 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3899 | rule->cond = cond; |
| 3900 | rule->srv.name = strdup(args[1]); |
| 3901 | LIST_INIT(&rule->list); |
| 3902 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3903 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3904 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3905 | else if ((!strcmp(args[0], "force-persist")) || |
| 3906 | (!strcmp(args[0], "ignore-persist"))) { |
| 3907 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3908 | |
| 3909 | if (curproxy == &defproxy) { |
| 3910 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3912 | goto out; |
| 3913 | } |
| 3914 | |
| 3915 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3916 | err_code |= ERR_WARN; |
| 3917 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3918 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3919 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3920 | file, linenum, args[0]); |
| 3921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3922 | goto out; |
| 3923 | } |
| 3924 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3925 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3926 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3927 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3929 | goto out; |
| 3930 | } |
| 3931 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3932 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3933 | * where force-persist is applied. |
| 3934 | */ |
| 3935 | 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] | 3936 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3937 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3938 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3939 | if (!strcmp(args[0], "force-persist")) { |
| 3940 | rule->type = PERSIST_TYPE_FORCE; |
| 3941 | } else { |
| 3942 | rule->type = PERSIST_TYPE_IGNORE; |
| 3943 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3944 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3945 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3946 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3947 | else if (!strcmp(args[0], "stick-table")) { |
| 3948 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3949 | struct proxy *other; |
| 3950 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 3951 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3952 | if (other) { |
| 3953 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 3954 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 3955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3956 | goto out; |
| 3957 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3958 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3959 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3960 | curproxy->table.type = (unsigned int)-1; |
| 3961 | while (*args[myidx]) { |
| 3962 | const char *err; |
| 3963 | |
| 3964 | if (strcmp(args[myidx], "size") == 0) { |
| 3965 | myidx++; |
| 3966 | if (!*(args[myidx])) { |
| 3967 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3968 | file, linenum, args[myidx-1]); |
| 3969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3970 | goto out; |
| 3971 | } |
| 3972 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3973 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3974 | file, linenum, *err, args[myidx-1]); |
| 3975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3976 | goto out; |
| 3977 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3978 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3979 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3980 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3981 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3982 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3983 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3984 | file, linenum, args[myidx-1]); |
| 3985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3986 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3987 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3988 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3989 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3990 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3991 | myidx++; |
| 3992 | if (!*(args[myidx])) { |
| 3993 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3994 | file, linenum, args[myidx-1]); |
| 3995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3996 | goto out; |
| 3997 | } |
| 3998 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3999 | if (err) { |
| 4000 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4001 | file, linenum, *err, args[myidx-1]); |
| 4002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4003 | goto out; |
| 4004 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4005 | if (val > INT_MAX) { |
| 4006 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4007 | file, linenum, val); |
| 4008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4009 | goto out; |
| 4010 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4011 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4012 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4013 | } |
| 4014 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4015 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4016 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4017 | } |
| 4018 | else if (strcmp(args[myidx], "type") == 0) { |
| 4019 | myidx++; |
| 4020 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4021 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4022 | file, linenum, args[myidx]); |
| 4023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4024 | goto out; |
| 4025 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4026 | /* myidx already points to next arg */ |
| 4027 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4028 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4029 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4030 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4031 | |
| 4032 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4033 | nw = args[myidx]; |
| 4034 | while (*nw) { |
| 4035 | /* the "store" keyword supports a comma-separated list */ |
| 4036 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4037 | sa = NULL; /* store arg */ |
| 4038 | while (*nw && *nw != ',') { |
| 4039 | if (*nw == '(') { |
| 4040 | *nw = 0; |
| 4041 | sa = ++nw; |
| 4042 | while (*nw != ')') { |
| 4043 | if (!*nw) { |
| 4044 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4045 | file, linenum, args[0], cw); |
| 4046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4047 | goto out; |
| 4048 | } |
| 4049 | nw++; |
| 4050 | } |
| 4051 | *nw = '\0'; |
| 4052 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4053 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4054 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4055 | if (*nw) |
| 4056 | *nw++ = '\0'; |
| 4057 | type = stktable_get_data_type(cw); |
| 4058 | if (type < 0) { |
| 4059 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4060 | file, linenum, args[0], cw); |
| 4061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4062 | goto out; |
| 4063 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4064 | |
| 4065 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4066 | switch (err) { |
| 4067 | case PE_NONE: break; |
| 4068 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4069 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4070 | file, linenum, args[0], cw); |
| 4071 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4072 | break; |
| 4073 | |
| 4074 | case PE_ARG_MISSING: |
| 4075 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4076 | file, linenum, args[0], cw); |
| 4077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4078 | goto out; |
| 4079 | |
| 4080 | case PE_ARG_NOT_USED: |
| 4081 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4082 | file, linenum, args[0], cw); |
| 4083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4084 | goto out; |
| 4085 | |
| 4086 | default: |
| 4087 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4088 | file, linenum, args[0], cw); |
| 4089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4090 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4091 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4092 | } |
| 4093 | myidx++; |
| 4094 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4095 | else { |
| 4096 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4097 | file, linenum, args[myidx]); |
| 4098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4099 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4100 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | if (!curproxy->table.size) { |
| 4104 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4105 | file, linenum); |
| 4106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4107 | goto out; |
| 4108 | } |
| 4109 | |
| 4110 | if (curproxy->table.type == (unsigned int)-1) { |
| 4111 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4112 | file, linenum); |
| 4113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4114 | goto out; |
| 4115 | } |
| 4116 | } |
| 4117 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4118 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4119 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4120 | int myidx = 0; |
| 4121 | const char *name = NULL; |
| 4122 | int flags; |
| 4123 | |
| 4124 | if (curproxy == &defproxy) { |
| 4125 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4127 | goto out; |
| 4128 | } |
| 4129 | |
| 4130 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4131 | err_code |= ERR_WARN; |
| 4132 | goto out; |
| 4133 | } |
| 4134 | |
| 4135 | myidx++; |
| 4136 | if ((strcmp(args[myidx], "store") == 0) || |
| 4137 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4138 | myidx++; |
| 4139 | flags = STK_IS_STORE; |
| 4140 | } |
| 4141 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4142 | myidx++; |
| 4143 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4144 | } |
| 4145 | else if (strcmp(args[myidx], "match") == 0) { |
| 4146 | myidx++; |
| 4147 | flags = STK_IS_MATCH; |
| 4148 | } |
| 4149 | else if (strcmp(args[myidx], "on") == 0) { |
| 4150 | myidx++; |
| 4151 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4152 | } |
| 4153 | else { |
| 4154 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4156 | goto out; |
| 4157 | } |
| 4158 | |
| 4159 | if (*(args[myidx]) == 0) { |
| 4160 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4162 | goto out; |
| 4163 | } |
| 4164 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4165 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4166 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4167 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4168 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4170 | goto out; |
| 4171 | } |
| 4172 | |
| 4173 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4174 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4175 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4176 | 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] | 4177 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4178 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4179 | goto out; |
| 4180 | } |
| 4181 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4182 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4183 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4184 | 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] | 4185 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4186 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4187 | goto out; |
| 4188 | } |
| 4189 | } |
| 4190 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4191 | /* 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] | 4192 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4193 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4194 | if (strcmp(args[myidx], "table") == 0) { |
| 4195 | myidx++; |
| 4196 | name = args[myidx++]; |
| 4197 | } |
| 4198 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4199 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4200 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4201 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4202 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4203 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4204 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4205 | goto out; |
| 4206 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4207 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4208 | else if (*(args[myidx])) { |
| 4209 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4210 | file, linenum, args[0], args[myidx]); |
| 4211 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4212 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4213 | goto out; |
| 4214 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4215 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4216 | 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] | 4217 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4218 | 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] | 4219 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4220 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4221 | rule->cond = cond; |
| 4222 | rule->expr = expr; |
| 4223 | rule->flags = flags; |
| 4224 | rule->table.name = name ? strdup(name) : NULL; |
| 4225 | LIST_INIT(&rule->list); |
| 4226 | if (flags & STK_ON_RSP) |
| 4227 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4228 | else |
| 4229 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4230 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4231 | else if (!strcmp(args[0], "stats")) { |
| 4232 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4233 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4234 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4235 | if (!*args[1]) { |
| 4236 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4237 | } else if (!strcmp(args[1], "admin")) { |
| 4238 | struct stats_admin_rule *rule; |
| 4239 | |
| 4240 | if (curproxy == &defproxy) { |
| 4241 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4243 | goto out; |
| 4244 | } |
| 4245 | |
| 4246 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4247 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4248 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4249 | goto out; |
| 4250 | } |
| 4251 | |
| 4252 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4253 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4254 | file, linenum, args[0], args[1]); |
| 4255 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4256 | goto out; |
| 4257 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4258 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4259 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4260 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4262 | goto out; |
| 4263 | } |
| 4264 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4265 | err_code |= warnif_cond_conflicts(cond, |
| 4266 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4267 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4268 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4269 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4270 | rule->cond = cond; |
| 4271 | LIST_INIT(&rule->list); |
| 4272 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4273 | } else if (!strcmp(args[1], "uri")) { |
| 4274 | if (*(args[2]) == 0) { |
| 4275 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4277 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4278 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4279 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4280 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4281 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4282 | } |
| 4283 | } else if (!strcmp(args[1], "realm")) { |
| 4284 | if (*(args[2]) == 0) { |
| 4285 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4287 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4288 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4289 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4290 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4291 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4292 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4293 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4294 | unsigned interval; |
| 4295 | |
| 4296 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4297 | if (err) { |
| 4298 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4299 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4301 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4302 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4303 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4304 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4305 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4306 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4307 | } 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] | 4308 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4309 | |
| 4310 | if (curproxy == &defproxy) { |
| 4311 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4313 | goto out; |
| 4314 | } |
| 4315 | |
| 4316 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4317 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4318 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4319 | goto out; |
| 4320 | } |
| 4321 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4322 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4323 | !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] | 4324 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4325 | file, linenum, args[0]); |
| 4326 | err_code |= ERR_WARN; |
| 4327 | } |
| 4328 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4329 | 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] | 4330 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4331 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4332 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4333 | goto out; |
| 4334 | } |
| 4335 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4336 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4337 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4338 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4339 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4340 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4341 | } else if (!strcmp(args[1], "auth")) { |
| 4342 | if (*(args[2]) == 0) { |
| 4343 | 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] | 4344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4345 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4346 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4347 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4348 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4349 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4350 | } |
| 4351 | } else if (!strcmp(args[1], "scope")) { |
| 4352 | if (*(args[2]) == 0) { |
| 4353 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4355 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4356 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4357 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4358 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4359 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4360 | } |
| 4361 | } else if (!strcmp(args[1], "enable")) { |
| 4362 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4363 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4364 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4365 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4366 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4367 | } else if (!strcmp(args[1], "hide-version")) { |
| 4368 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4369 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4370 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4371 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4372 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4373 | } else if (!strcmp(args[1], "show-legends")) { |
| 4374 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4375 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4376 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4377 | goto out; |
| 4378 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4379 | } else if (!strcmp(args[1], "show-node")) { |
| 4380 | |
| 4381 | if (*args[2]) { |
| 4382 | int i; |
| 4383 | char c; |
| 4384 | |
| 4385 | for (i=0; args[2][i]; i++) { |
| 4386 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4387 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4388 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4389 | break; |
| 4390 | } |
| 4391 | |
| 4392 | if (!i || args[2][i]) { |
| 4393 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4394 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4395 | file, linenum, args[0], args[1]); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4402 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4403 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4404 | goto out; |
| 4405 | } |
| 4406 | } else if (!strcmp(args[1], "show-desc")) { |
| 4407 | char *desc = NULL; |
| 4408 | |
| 4409 | if (*args[2]) { |
| 4410 | int i, len=0; |
| 4411 | char *d; |
| 4412 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4413 | for (i = 2; *args[i]; i++) |
| 4414 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4415 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4416 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4417 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4418 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4419 | for (i = 3; *args[i]; i++) |
| 4420 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | if (!*args[2] && !global.desc) |
| 4424 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4425 | file, linenum, args[1]); |
| 4426 | else { |
| 4427 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4428 | free(desc); |
| 4429 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4430 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4431 | goto out; |
| 4432 | } |
| 4433 | free(desc); |
| 4434 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4435 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4436 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4437 | 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] | 4438 | 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] | 4439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4440 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4444 | int optnum; |
| 4445 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4446 | if (*(args[1]) == '\0') { |
| 4447 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4448 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4450 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4451 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4452 | |
| 4453 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4454 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4455 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4456 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4457 | file, linenum, cfg_opts[optnum].name); |
| 4458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4459 | goto out; |
| 4460 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4461 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4462 | goto out; |
| 4463 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4464 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4465 | err_code |= ERR_WARN; |
| 4466 | goto out; |
| 4467 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4468 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4469 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4470 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4471 | |
| 4472 | switch (kwm) { |
| 4473 | case KWM_STD: |
| 4474 | curproxy->options |= cfg_opts[optnum].val; |
| 4475 | break; |
| 4476 | case KWM_NO: |
| 4477 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4478 | break; |
| 4479 | case KWM_DEF: /* already cleared */ |
| 4480 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4481 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4482 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4483 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4487 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4488 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4489 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4490 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4491 | file, linenum, cfg_opts2[optnum].name); |
| 4492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4493 | goto out; |
| 4494 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4495 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4496 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4497 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4498 | err_code |= ERR_WARN; |
| 4499 | goto out; |
| 4500 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4501 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4502 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4503 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4504 | |
| 4505 | switch (kwm) { |
| 4506 | case KWM_STD: |
| 4507 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4508 | break; |
| 4509 | case KWM_NO: |
| 4510 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4511 | break; |
| 4512 | case KWM_DEF: /* already cleared */ |
| 4513 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4514 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4515 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4519 | /* HTTP options override each other. They can be cancelled using |
| 4520 | * "no option xxx" which only switches to default mode if the mode |
| 4521 | * was this one (useful for cancelling options set in defaults |
| 4522 | * sections). |
| 4523 | */ |
| 4524 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4525 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4526 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4527 | if (kwm == KWM_STD) { |
| 4528 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4529 | curproxy->options |= PR_O_HTTP_PCL; |
| 4530 | goto out; |
| 4531 | } |
| 4532 | else if (kwm == KWM_NO) { |
| 4533 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4534 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4535 | goto out; |
| 4536 | } |
| 4537 | } |
| 4538 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4539 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4540 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4541 | if (kwm == KWM_STD) { |
| 4542 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4543 | curproxy->options |= PR_O_HTTP_FCL; |
| 4544 | goto out; |
| 4545 | } |
| 4546 | else if (kwm == KWM_NO) { |
| 4547 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4548 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4549 | goto out; |
| 4550 | } |
| 4551 | } |
| 4552 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4553 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4554 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4555 | if (kwm == KWM_STD) { |
| 4556 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4557 | curproxy->options |= PR_O_HTTP_SCL; |
| 4558 | goto out; |
| 4559 | } |
| 4560 | else if (kwm == KWM_NO) { |
| 4561 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4562 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4563 | goto out; |
| 4564 | } |
| 4565 | } |
| 4566 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4567 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4568 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4569 | if (kwm == KWM_STD) { |
| 4570 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4571 | curproxy->options |= PR_O_HTTP_KAL; |
| 4572 | goto out; |
| 4573 | } |
| 4574 | else if (kwm == KWM_NO) { |
| 4575 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4576 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4577 | goto out; |
| 4578 | } |
| 4579 | } |
| 4580 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4581 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4582 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4583 | if (kwm == KWM_STD) { |
| 4584 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4585 | curproxy->options |= PR_O_HTTP_TUN; |
| 4586 | goto out; |
| 4587 | } |
| 4588 | else if (kwm == KWM_NO) { |
| 4589 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4590 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4591 | goto out; |
| 4592 | } |
| 4593 | } |
| 4594 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4595 | /* Redispatch can take an integer argument that control when the |
| 4596 | * resispatch occurs. All values are relative to the retries option. |
| 4597 | * This can be cancelled using "no option xxx". |
| 4598 | */ |
| 4599 | if (strcmp(args[1], "redispatch") == 0) { |
| 4600 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4601 | err_code |= ERR_WARN; |
| 4602 | goto out; |
| 4603 | } |
| 4604 | |
| 4605 | curproxy->no_options &= ~PR_O_REDISP; |
| 4606 | curproxy->options &= ~PR_O_REDISP; |
| 4607 | |
| 4608 | switch (kwm) { |
| 4609 | case KWM_STD: |
| 4610 | curproxy->options |= PR_O_REDISP; |
| 4611 | curproxy->redispatch_after = -1; |
| 4612 | if(*args[2]) { |
| 4613 | curproxy->redispatch_after = atol(args[2]); |
| 4614 | } |
| 4615 | break; |
| 4616 | case KWM_NO: |
| 4617 | curproxy->no_options |= PR_O_REDISP; |
| 4618 | curproxy->redispatch_after = 0; |
| 4619 | break; |
| 4620 | case KWM_DEF: /* already cleared */ |
| 4621 | break; |
| 4622 | } |
| 4623 | goto out; |
| 4624 | } |
| 4625 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4626 | if (kwm != KWM_STD) { |
| 4627 | 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] | 4628 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4630 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4631 | } |
| 4632 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4633 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4634 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4635 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4636 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4637 | if (*(args[2]) != '\0') { |
| 4638 | if (!strcmp(args[2], "clf")) { |
| 4639 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4640 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4641 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4642 | 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] | 4643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4644 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4645 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4646 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4647 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4648 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4649 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4650 | char *oldlogformat = "log-format"; |
| 4651 | char *clflogformat = ""; |
| 4652 | |
| 4653 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4654 | oldlogformat = "option httplog"; |
| 4655 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4656 | oldlogformat = "option tcplog"; |
| 4657 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4658 | oldlogformat = "option httplog clf"; |
| 4659 | if (logformat == clf_http_log_format) |
| 4660 | clflogformat = " clf"; |
| 4661 | Warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 4662 | file, linenum, clflogformat, oldlogformat); |
| 4663 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4664 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4665 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4666 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4667 | free(curproxy->conf.logformat_string); |
| 4668 | curproxy->conf.logformat_string = logformat; |
| 4669 | |
| 4670 | free(curproxy->conf.lfs_file); |
| 4671 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4672 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4673 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4674 | else if (!strcmp(args[1], "tcplog")) { |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4675 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4676 | char *oldlogformat = "log-format"; |
| 4677 | |
| 4678 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4679 | oldlogformat = "option httplog"; |
| 4680 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4681 | oldlogformat = "option tcplog"; |
| 4682 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4683 | oldlogformat = "option httplog clf"; |
| 4684 | Warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 4685 | file, linenum, oldlogformat); |
| 4686 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4687 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4688 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4689 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4690 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4691 | free(curproxy->conf.logformat_string); |
| 4692 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4693 | |
| 4694 | free(curproxy->conf.lfs_file); |
| 4695 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4696 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4697 | |
| 4698 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4699 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4700 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4701 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4702 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4703 | 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] | 4704 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4705 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4706 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4707 | goto out; |
| 4708 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4709 | if (curproxy->cap & PR_CAP_FE) |
| 4710 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4711 | if (curproxy->cap & PR_CAP_BE) |
| 4712 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4713 | } |
| 4714 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4715 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4716 | err_code |= ERR_WARN; |
| 4717 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4718 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4719 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4720 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4721 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4722 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4723 | if (!*args[2]) { /* no argument */ |
| 4724 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4725 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4726 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4727 | 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] | 4728 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4729 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4730 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4731 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4732 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4733 | if (*args[4]) |
| 4734 | reqlen += strlen(args[4]); |
| 4735 | else |
| 4736 | reqlen += strlen("HTTP/1.0"); |
| 4737 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4738 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4739 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4740 | "%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] | 4741 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4742 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4743 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4744 | } |
| 4745 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4746 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4747 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4748 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4749 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4750 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4751 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4752 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4753 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4754 | |
| 4755 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4756 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4757 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4758 | else if (!strcmp(args[1], "smtpchk")) { |
| 4759 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4760 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4761 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4762 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4763 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4764 | |
| 4765 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4766 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4767 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4768 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4769 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4770 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4771 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4772 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4773 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4774 | } else { |
| 4775 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4776 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4777 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4778 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4779 | } |
| 4780 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4781 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4782 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4783 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4784 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4785 | /* use PostgreSQL request to check servers' health */ |
| 4786 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4787 | err_code |= ERR_WARN; |
| 4788 | |
| 4789 | free(curproxy->check_req); |
| 4790 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4791 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4792 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4793 | |
| 4794 | if (*(args[2])) { |
| 4795 | int cur_arg = 2; |
| 4796 | |
| 4797 | while (*(args[cur_arg])) { |
| 4798 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4799 | char * packet; |
| 4800 | uint32_t packet_len; |
| 4801 | uint32_t pv; |
| 4802 | |
| 4803 | /* suboption header - needs additional argument for it */ |
| 4804 | if (*(args[cur_arg+1]) == 0) { |
| 4805 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4806 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4808 | goto out; |
| 4809 | } |
| 4810 | |
| 4811 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4812 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4813 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4814 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4815 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4816 | |
| 4817 | memcpy(packet + 4, &pv, 4); |
| 4818 | |
| 4819 | /* copy "user" */ |
| 4820 | memcpy(packet + 8, "user", 4); |
| 4821 | |
| 4822 | /* copy username */ |
| 4823 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4824 | |
| 4825 | free(curproxy->check_req); |
| 4826 | curproxy->check_req = packet; |
| 4827 | curproxy->check_len = packet_len; |
| 4828 | |
| 4829 | packet_len = htonl(packet_len); |
| 4830 | memcpy(packet, &packet_len, 4); |
| 4831 | cur_arg += 2; |
| 4832 | } else { |
| 4833 | /* unknown suboption - catchall */ |
| 4834 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4835 | file, linenum, args[0], args[1]); |
| 4836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4837 | goto out; |
| 4838 | } |
| 4839 | } /* end while loop */ |
| 4840 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4841 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4842 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4845 | else if (!strcmp(args[1], "redis-check")) { |
| 4846 | /* use REDIS PING request to check servers' health */ |
| 4847 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4848 | err_code |= ERR_WARN; |
| 4849 | |
| 4850 | free(curproxy->check_req); |
| 4851 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4852 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4853 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4854 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4855 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4856 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4857 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4858 | |
| 4859 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4860 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4861 | } |
| 4862 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4863 | else if (!strcmp(args[1], "mysql-check")) { |
| 4864 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4865 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4866 | err_code |= ERR_WARN; |
| 4867 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4868 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4869 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4870 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4871 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4872 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4873 | /* 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] | 4874 | * const char mysql40_client_auth_pkt[] = { |
| 4875 | * "\x0e\x00\x00" // packet length |
| 4876 | * "\x01" // packet number |
| 4877 | * "\x00\x00" // client capabilities |
| 4878 | * "\x00\x00\x01" // max packet |
| 4879 | * "haproxy\x00" // username (null terminated string) |
| 4880 | * "\x00" // filler (always 0x00) |
| 4881 | * "\x01\x00\x00" // packet length |
| 4882 | * "\x00" // packet number |
| 4883 | * "\x01" // COM_QUIT command |
| 4884 | * }; |
| 4885 | */ |
| 4886 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4887 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4888 | * const char mysql41_client_auth_pkt[] = { |
| 4889 | * "\x0e\x00\x00\" // packet length |
| 4890 | * "\x01" // packet number |
| 4891 | * "\x00\x00\x00\x00" // client capabilities |
| 4892 | * "\x00\x00\x00\x01" // max packet |
| 4893 | * "\x21" // character set (UTF-8) |
| 4894 | * char[23] // All zeroes |
| 4895 | * "haproxy\x00" // username (null terminated string) |
| 4896 | * "\x00" // filler (always 0x00) |
| 4897 | * "\x01\x00\x00" // packet length |
| 4898 | * "\x00" // packet number |
| 4899 | * "\x01" // COM_QUIT command |
| 4900 | * }; |
| 4901 | */ |
| 4902 | |
| 4903 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4904 | if (*(args[2])) { |
| 4905 | int cur_arg = 2; |
| 4906 | |
| 4907 | while (*(args[cur_arg])) { |
| 4908 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4909 | char *mysqluser; |
| 4910 | int packetlen, reqlen, userlen; |
| 4911 | |
| 4912 | /* suboption header - needs additional argument for it */ |
| 4913 | if (*(args[cur_arg+1]) == 0) { |
| 4914 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4915 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4916 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4917 | goto out; |
| 4918 | } |
| 4919 | mysqluser = args[cur_arg + 1]; |
| 4920 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4921 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4922 | if (*(args[cur_arg+2])) { |
| 4923 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4924 | packetlen = userlen + 7 + 27; |
| 4925 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4926 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4927 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4928 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4929 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4930 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4931 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4932 | ((unsigned char) packetlen & 0xff), |
| 4933 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4934 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4935 | |
| 4936 | curproxy->check_req[3] = 1; |
| 4937 | curproxy->check_req[5] = 130; |
| 4938 | curproxy->check_req[11] = 1; |
| 4939 | curproxy->check_req[12] = 33; |
| 4940 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4941 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4942 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4943 | cur_arg += 3; |
| 4944 | } else { |
| 4945 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4947 | goto out; |
| 4948 | } |
| 4949 | } else { |
| 4950 | packetlen = userlen + 7; |
| 4951 | reqlen = packetlen + 9; |
| 4952 | |
| 4953 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4954 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4955 | curproxy->check_len = reqlen; |
| 4956 | |
| 4957 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4958 | ((unsigned char) packetlen & 0xff), |
| 4959 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4960 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4961 | |
| 4962 | curproxy->check_req[3] = 1; |
| 4963 | curproxy->check_req[5] = 128; |
| 4964 | curproxy->check_req[8] = 1; |
| 4965 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4966 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4967 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4968 | cur_arg += 2; |
| 4969 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4970 | } else { |
| 4971 | /* unknown suboption - catchall */ |
| 4972 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4973 | file, linenum, args[0], args[1]); |
| 4974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4975 | goto out; |
| 4976 | } |
| 4977 | } /* end while loop */ |
| 4978 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4979 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4980 | else if (!strcmp(args[1], "ldap-check")) { |
| 4981 | /* use LDAP request to check servers' health */ |
| 4982 | free(curproxy->check_req); |
| 4983 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4984 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4985 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4986 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4987 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4988 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4989 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4990 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4991 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4992 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 4993 | else if (!strcmp(args[1], "spop-check")) { |
| 4994 | if (curproxy == &defproxy) { |
| 4995 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 4996 | file, linenum, args[0], args[1]); |
| 4997 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4998 | goto out; |
| 4999 | } |
| 5000 | if (curproxy->cap & PR_CAP_FE) { |
| 5001 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5002 | file, linenum, args[0], args[1]); |
| 5003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5004 | goto out; |
| 5005 | } |
| 5006 | |
| 5007 | /* use SPOE request to check servers' health */ |
| 5008 | free(curproxy->check_req); |
| 5009 | curproxy->check_req = NULL; |
| 5010 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5011 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5012 | |
Christopher Faulet | 8ef7525 | 2017-02-20 22:56:03 +0100 | [diff] [blame] | 5013 | if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5014 | Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
| 5015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5016 | goto out; |
| 5017 | } |
| 5018 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5019 | goto out; |
| 5020 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5021 | else if (!strcmp(args[1], "tcp-check")) { |
| 5022 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5023 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5024 | err_code |= ERR_WARN; |
| 5025 | |
| 5026 | free(curproxy->check_req); |
| 5027 | curproxy->check_req = NULL; |
| 5028 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5029 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5030 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5031 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5032 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5033 | else if (!strcmp(args[1], "external-check")) { |
| 5034 | /* excute an external command to check servers' health */ |
| 5035 | free(curproxy->check_req); |
| 5036 | curproxy->check_req = NULL; |
| 5037 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5038 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5039 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5040 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5041 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5042 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5043 | int cur_arg; |
| 5044 | |
| 5045 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5046 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5047 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5048 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5049 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5050 | |
| 5051 | free(curproxy->fwdfor_hdr_name); |
| 5052 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5053 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5054 | |
| 5055 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5056 | cur_arg = 2; |
| 5057 | while (*(args[cur_arg])) { |
| 5058 | if (!strcmp(args[cur_arg], "except")) { |
| 5059 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5060 | 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] | 5061 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5062 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5064 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5065 | } |
| 5066 | /* flush useless bits */ |
| 5067 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5068 | cur_arg += 2; |
| 5069 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5070 | /* suboption header - needs additional argument for it */ |
| 5071 | if (*(args[cur_arg+1]) == 0) { |
| 5072 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5073 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5075 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5076 | } |
| 5077 | free(curproxy->fwdfor_hdr_name); |
| 5078 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5079 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5080 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5081 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5082 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5083 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5084 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5085 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5086 | 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] | 5087 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5089 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5090 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5091 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5092 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5093 | else if (!strcmp(args[1], "originalto")) { |
| 5094 | int cur_arg; |
| 5095 | |
| 5096 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5097 | * set default options (ie: bitfield, header name, etc) |
| 5098 | */ |
| 5099 | |
| 5100 | curproxy->options |= PR_O_ORGTO; |
| 5101 | |
| 5102 | free(curproxy->orgto_hdr_name); |
| 5103 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5104 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5105 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5106 | /* 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] | 5107 | cur_arg = 2; |
| 5108 | while (*(args[cur_arg])) { |
| 5109 | if (!strcmp(args[cur_arg], "except")) { |
| 5110 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5111 | 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] | 5112 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5113 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5115 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5116 | } |
| 5117 | /* flush useless bits */ |
| 5118 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5119 | cur_arg += 2; |
| 5120 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5121 | /* suboption header - needs additional argument for it */ |
| 5122 | if (*(args[cur_arg+1]) == 0) { |
| 5123 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5124 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5126 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5127 | } |
| 5128 | free(curproxy->orgto_hdr_name); |
| 5129 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5130 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5131 | cur_arg += 2; |
| 5132 | } else { |
| 5133 | /* unknown suboption - catchall */ |
| 5134 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5135 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5137 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5138 | } |
| 5139 | } /* end while loop */ |
| 5140 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5141 | else { |
| 5142 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5144 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5145 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5146 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5147 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5148 | else if (!strcmp(args[0], "default_backend")) { |
| 5149 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5150 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5151 | |
| 5152 | if (*(args[1]) == 0) { |
| 5153 | 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] | 5154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5155 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5156 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5157 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5158 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5159 | |
| 5160 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5161 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5162 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5163 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5164 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5165 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5166 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5167 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5168 | 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] | 5169 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5170 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5171 | /* enable reconnections to dispatch */ |
| 5172 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5173 | |
| 5174 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5175 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5176 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5177 | else if (!strcmp(args[0], "http-reuse")) { |
| 5178 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5179 | err_code |= ERR_WARN; |
| 5180 | |
| 5181 | if (strcmp(args[1], "never") == 0) { |
| 5182 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5183 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5184 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5185 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5186 | goto out; |
| 5187 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5188 | else if (strcmp(args[1], "safe") == 0) { |
| 5189 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5190 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5191 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5192 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5193 | goto out; |
| 5194 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5195 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5196 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5197 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5198 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5199 | goto out; |
| 5200 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5201 | else if (strcmp(args[1], "always") == 0) { |
| 5202 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5203 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5204 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5205 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5206 | goto out; |
| 5207 | } |
| 5208 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5209 | 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] | 5210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5211 | goto out; |
| 5212 | } |
| 5213 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5214 | else if (!strcmp(args[0], "http-check")) { |
| 5215 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5216 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5217 | |
| 5218 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5219 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5220 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5221 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5222 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5223 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5224 | else if (strcmp(args[1], "send-state") == 0) { |
| 5225 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5226 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5227 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5228 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5229 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5230 | else if (strcmp(args[1], "expect") == 0) { |
| 5231 | const char *ptr_arg; |
| 5232 | int cur_arg; |
| 5233 | |
| 5234 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5235 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5237 | goto out; |
| 5238 | } |
| 5239 | |
| 5240 | cur_arg = 2; |
| 5241 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5242 | while (*(ptr_arg = args[cur_arg])) { |
| 5243 | while (*ptr_arg == '!') { |
| 5244 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5245 | ptr_arg++; |
| 5246 | } |
| 5247 | if (*ptr_arg) |
| 5248 | break; |
| 5249 | cur_arg++; |
| 5250 | } |
| 5251 | /* now ptr_arg points to the beginning of a word past any possible |
| 5252 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5253 | */ |
| 5254 | if (strcmp(ptr_arg, "status") == 0) { |
| 5255 | if (!*(args[cur_arg + 1])) { |
| 5256 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5257 | file, linenum, args[0], args[1], ptr_arg); |
| 5258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5259 | goto out; |
| 5260 | } |
| 5261 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5262 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5263 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5264 | } |
| 5265 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5266 | if (!*(args[cur_arg + 1])) { |
| 5267 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5268 | file, linenum, args[0], args[1], ptr_arg); |
| 5269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5270 | goto out; |
| 5271 | } |
| 5272 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5273 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5274 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5275 | } |
| 5276 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5277 | if (!*(args[cur_arg + 1])) { |
| 5278 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5279 | file, linenum, args[0], args[1], ptr_arg); |
| 5280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5281 | goto out; |
| 5282 | } |
| 5283 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5284 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5285 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5286 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5287 | free(curproxy->expect_regex); |
| 5288 | curproxy->expect_regex = NULL; |
| 5289 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5290 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5291 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5292 | error = NULL; |
| 5293 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5294 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5295 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5296 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5298 | goto out; |
| 5299 | } |
| 5300 | } |
| 5301 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5302 | if (!*(args[cur_arg + 1])) { |
| 5303 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5304 | file, linenum, args[0], args[1], ptr_arg); |
| 5305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5306 | goto out; |
| 5307 | } |
| 5308 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5309 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5310 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5311 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5312 | free(curproxy->expect_regex); |
| 5313 | curproxy->expect_regex = NULL; |
| 5314 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5315 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5316 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5317 | error = NULL; |
| 5318 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5319 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5320 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5321 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5323 | goto out; |
| 5324 | } |
| 5325 | } |
| 5326 | else { |
| 5327 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5328 | file, linenum, args[0], args[1], ptr_arg); |
| 5329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5330 | goto out; |
| 5331 | } |
| 5332 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5333 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5334 | 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] | 5335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5336 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5337 | } |
| 5338 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5339 | else if (!strcmp(args[0], "tcp-check")) { |
| 5340 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5341 | err_code |= ERR_WARN; |
| 5342 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5343 | if (strcmp(args[1], "comment") == 0) { |
| 5344 | int cur_arg; |
| 5345 | struct tcpcheck_rule *tcpcheck; |
| 5346 | |
| 5347 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5348 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5349 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5350 | |
| 5351 | if (!*args[cur_arg + 1]) { |
| 5352 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5353 | file, linenum, args[cur_arg]); |
| 5354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5355 | goto out; |
| 5356 | } |
| 5357 | |
| 5358 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5359 | |
| 5360 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5361 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5362 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5363 | } |
| 5364 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5365 | const char *ptr_arg; |
| 5366 | int cur_arg; |
| 5367 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5368 | |
| 5369 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5370 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5371 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5372 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5373 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5374 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5375 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5376 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5377 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5378 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5379 | file, linenum); |
| 5380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5381 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5385 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5386 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5387 | |
| 5388 | /* parsing each parameters to fill up the rule */ |
| 5389 | while (*(ptr_arg = args[cur_arg])) { |
| 5390 | /* tcp port */ |
| 5391 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5392 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5393 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5394 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5395 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5397 | goto out; |
| 5398 | } |
| 5399 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5400 | cur_arg += 2; |
| 5401 | } |
| 5402 | /* send proxy protocol */ |
| 5403 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5404 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5405 | cur_arg++; |
| 5406 | } |
| 5407 | #ifdef USE_OPENSSL |
| 5408 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5409 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5410 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5411 | cur_arg++; |
| 5412 | } |
| 5413 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5414 | /* comment for this tcpcheck line */ |
| 5415 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5416 | if (!*args[cur_arg + 1]) { |
| 5417 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5418 | file, linenum, args[cur_arg]); |
| 5419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5420 | goto out; |
| 5421 | } |
| 5422 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5423 | cur_arg += 2; |
| 5424 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5425 | else { |
| 5426 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5427 | 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] | 5428 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5429 | 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] | 5430 | #endif /* USE_OPENSSL */ |
| 5431 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5433 | goto out; |
| 5434 | } |
| 5435 | |
| 5436 | } |
| 5437 | |
| 5438 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5439 | } |
| 5440 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5441 | if (! *(args[2]) ) { |
| 5442 | /* SEND string expected */ |
| 5443 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5444 | file, linenum, args[0], args[1], args[2]); |
| 5445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5446 | goto out; |
| 5447 | } else { |
| 5448 | struct tcpcheck_rule *tcpcheck; |
| 5449 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5450 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5451 | |
| 5452 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5453 | tcpcheck->string_len = strlen(args[2]); |
| 5454 | tcpcheck->string = strdup(args[2]); |
| 5455 | tcpcheck->expect_regex = NULL; |
| 5456 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5457 | /* comment for this tcpcheck line */ |
| 5458 | if (strcmp(args[3], "comment") == 0) { |
| 5459 | if (!*args[4]) { |
| 5460 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5461 | file, linenum, args[3]); |
| 5462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5463 | goto out; |
| 5464 | } |
| 5465 | tcpcheck->comment = strdup(args[4]); |
| 5466 | } |
| 5467 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5468 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5469 | } |
| 5470 | } |
| 5471 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5472 | if (! *(args[2]) ) { |
| 5473 | /* SEND binary string expected */ |
| 5474 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5475 | file, linenum, args[0], args[1], args[2]); |
| 5476 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5477 | goto out; |
| 5478 | } else { |
| 5479 | struct tcpcheck_rule *tcpcheck; |
| 5480 | char *err = NULL; |
| 5481 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5482 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5483 | |
| 5484 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5485 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5486 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5487 | file, linenum, args[0], args[1], args[2], err); |
| 5488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5489 | goto out; |
| 5490 | } |
| 5491 | tcpcheck->expect_regex = NULL; |
| 5492 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5493 | /* comment for this tcpcheck line */ |
| 5494 | if (strcmp(args[3], "comment") == 0) { |
| 5495 | if (!*args[4]) { |
| 5496 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5497 | file, linenum, args[3]); |
| 5498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5499 | goto out; |
| 5500 | } |
| 5501 | tcpcheck->comment = strdup(args[4]); |
| 5502 | } |
| 5503 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5504 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5505 | } |
| 5506 | } |
| 5507 | else if (strcmp(args[1], "expect") == 0) { |
| 5508 | const char *ptr_arg; |
| 5509 | int cur_arg; |
| 5510 | int inverse = 0; |
| 5511 | |
| 5512 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5513 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5515 | goto out; |
| 5516 | } |
| 5517 | |
| 5518 | cur_arg = 2; |
| 5519 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5520 | while (*(ptr_arg = args[cur_arg])) { |
| 5521 | while (*ptr_arg == '!') { |
| 5522 | inverse = !inverse; |
| 5523 | ptr_arg++; |
| 5524 | } |
| 5525 | if (*ptr_arg) |
| 5526 | break; |
| 5527 | cur_arg++; |
| 5528 | } |
| 5529 | /* now ptr_arg points to the beginning of a word past any possible |
| 5530 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5531 | */ |
| 5532 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5533 | struct tcpcheck_rule *tcpcheck; |
| 5534 | char *err = NULL; |
| 5535 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5536 | if (!*(args[cur_arg + 1])) { |
| 5537 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5538 | file, linenum, args[0], args[1], ptr_arg); |
| 5539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5540 | goto out; |
| 5541 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5542 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5543 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5544 | |
| 5545 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5546 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5547 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5548 | file, linenum, args[0], args[1], args[2], err); |
| 5549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5550 | goto out; |
| 5551 | } |
| 5552 | tcpcheck->expect_regex = NULL; |
| 5553 | tcpcheck->inverse = inverse; |
| 5554 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5555 | /* tcpcheck comment */ |
| 5556 | cur_arg += 2; |
| 5557 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5558 | if (!*args[cur_arg + 1]) { |
| 5559 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5560 | file, linenum, args[cur_arg + 1]); |
| 5561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5562 | goto out; |
| 5563 | } |
| 5564 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5565 | } |
| 5566 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5567 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5568 | } |
| 5569 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5570 | struct tcpcheck_rule *tcpcheck; |
| 5571 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5572 | if (!*(args[cur_arg + 1])) { |
| 5573 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5574 | file, linenum, args[0], args[1], ptr_arg); |
| 5575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5576 | goto out; |
| 5577 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5578 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5579 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5580 | |
| 5581 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5582 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5583 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5584 | tcpcheck->expect_regex = NULL; |
| 5585 | tcpcheck->inverse = inverse; |
| 5586 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5587 | /* tcpcheck comment */ |
| 5588 | cur_arg += 2; |
| 5589 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5590 | if (!*args[cur_arg + 1]) { |
| 5591 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5592 | file, linenum, args[cur_arg + 1]); |
| 5593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5594 | goto out; |
| 5595 | } |
| 5596 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5597 | } |
| 5598 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5599 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5600 | } |
| 5601 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5602 | struct tcpcheck_rule *tcpcheck; |
| 5603 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5604 | if (!*(args[cur_arg + 1])) { |
| 5605 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5606 | file, linenum, args[0], args[1], ptr_arg); |
| 5607 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5608 | goto out; |
| 5609 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5610 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5611 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5612 | |
| 5613 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5614 | tcpcheck->string_len = 0; |
| 5615 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5616 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5617 | error = NULL; |
| 5618 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5619 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5620 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5621 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5623 | goto out; |
| 5624 | } |
| 5625 | tcpcheck->inverse = inverse; |
| 5626 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5627 | /* tcpcheck comment */ |
| 5628 | cur_arg += 2; |
| 5629 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5630 | if (!*args[cur_arg + 1]) { |
| 5631 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5632 | file, linenum, args[cur_arg + 1]); |
| 5633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5634 | goto out; |
| 5635 | } |
| 5636 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5637 | } |
| 5638 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5639 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5640 | } |
| 5641 | else { |
| 5642 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5643 | file, linenum, args[0], args[1], ptr_arg); |
| 5644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5645 | goto out; |
| 5646 | } |
| 5647 | } |
| 5648 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5649 | 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] | 5650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5651 | goto out; |
| 5652 | } |
| 5653 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5654 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5655 | if (curproxy == &defproxy) { |
| 5656 | 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] | 5657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5658 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5659 | } |
| 5660 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5661 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5662 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5663 | |
| 5664 | if (strcmp(args[1], "fail") == 0) { |
| 5665 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5666 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5667 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5668 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5670 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5671 | } |
| 5672 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5673 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5674 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5675 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5677 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5678 | } |
| 5679 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5680 | } |
| 5681 | else { |
| 5682 | 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] | 5683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5684 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5685 | } |
| 5686 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5687 | #ifdef TPROXY |
| 5688 | else if (!strcmp(args[0], "transparent")) { |
| 5689 | /* enable transparent proxy connections */ |
| 5690 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5691 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5692 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5693 | } |
| 5694 | #endif |
| 5695 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5696 | 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] | 5697 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5698 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5699 | if (*(args[1]) == 0) { |
| 5700 | 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] | 5701 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5702 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5703 | } |
| 5704 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5705 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5706 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5707 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5708 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5709 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5710 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5711 | |
| 5712 | if (*(args[1]) == 0) { |
| 5713 | 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] | 5714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5715 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5716 | } |
| 5717 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5718 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5719 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5720 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5721 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5722 | 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] | 5723 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5724 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5725 | if (*(args[1]) == 0) { |
| 5726 | 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] | 5727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5728 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5729 | } |
| 5730 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5731 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5732 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5733 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5734 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5735 | if (*(args[1]) == 0) { |
| 5736 | 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] | 5737 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5738 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5739 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5740 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5741 | if (err) { |
| 5742 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5743 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5745 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5746 | } |
| 5747 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5748 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5750 | } |
| 5751 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5752 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5753 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5754 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5755 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5756 | if (curproxy == &defproxy) { |
| 5757 | 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] | 5758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5760 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5761 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5762 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5763 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5764 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5765 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5766 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5767 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5768 | goto out; |
| 5769 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5770 | |
| 5771 | proto = protocol_by_family(sk->ss_family); |
| 5772 | if (!proto || !proto->connect) { |
| 5773 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5774 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5776 | goto out; |
| 5777 | } |
| 5778 | |
| 5779 | if (port1 != port2) { |
| 5780 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5781 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5783 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5784 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5785 | |
| 5786 | if (!port1) { |
| 5787 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5788 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5790 | goto out; |
| 5791 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5792 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5794 | goto out; |
| 5795 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5796 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5797 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5798 | } |
| 5799 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5800 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5801 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5802 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5803 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5804 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5806 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5807 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5808 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5809 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5810 | /** |
| 5811 | * The syntax for hash-type config element is |
| 5812 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5813 | * |
| 5814 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5815 | */ |
| 5816 | 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] | 5817 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5818 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5819 | err_code |= ERR_WARN; |
| 5820 | |
| 5821 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5822 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5823 | } |
| 5824 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5825 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5826 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5827 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5828 | 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]); |
| 5829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5830 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5831 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5832 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5833 | 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] | 5834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5835 | goto out; |
| 5836 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5837 | |
| 5838 | /* set the hash function to use */ |
| 5839 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5840 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5841 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5842 | |
| 5843 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5844 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5845 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5846 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5847 | /* set the hash function */ |
| 5848 | if (!strcmp(args[2], "sdbm")) { |
| 5849 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5850 | } |
| 5851 | else if (!strcmp(args[2], "djb2")) { |
| 5852 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5853 | } |
| 5854 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5855 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5856 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5857 | else if (!strcmp(args[2], "crc32")) { |
| 5858 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5859 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5860 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5861 | 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] | 5862 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5863 | goto out; |
| 5864 | } |
| 5865 | |
| 5866 | /* set the hash modifier */ |
| 5867 | if (!strcmp(args[3], "avalanche")) { |
| 5868 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5869 | } |
| 5870 | else if (*args[3]) { |
| 5871 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5873 | goto out; |
| 5874 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5875 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5876 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 5877 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 5878 | if (*(args[1]) == 0) { |
| 5879 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 5880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5881 | goto out; |
| 5882 | } |
| 5883 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 5884 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 5885 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 5886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5887 | goto out; |
| 5888 | } |
| 5889 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5890 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5891 | if (!*(args[1])) { |
| 5892 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5894 | goto out; |
| 5895 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5896 | if (*(args[2])) { |
| 5897 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5899 | goto out; |
| 5900 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5901 | free(curproxy->conf.uniqueid_format_string); |
| 5902 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5903 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5904 | free(curproxy->conf.uif_file); |
| 5905 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5906 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5907 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5908 | |
| 5909 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5910 | if (!*(args[1])) { |
| 5911 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5912 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5913 | goto out; |
| 5914 | } |
| 5915 | free(curproxy->header_unique_id); |
| 5916 | curproxy->header_unique_id = strdup(args[1]); |
| 5917 | } |
| 5918 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5919 | else if (strcmp(args[0], "log-format") == 0) { |
| 5920 | if (!*(args[1])) { |
| 5921 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5923 | goto out; |
| 5924 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5925 | if (*(args[2])) { |
| 5926 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5928 | goto out; |
| 5929 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 5930 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 5931 | char *oldlogformat = "log-format"; |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 5932 | |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 5933 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 5934 | oldlogformat = "option httplog"; |
| 5935 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 5936 | oldlogformat = "option tcplog"; |
| 5937 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 5938 | oldlogformat = "option httplog clf"; |
| 5939 | Warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 5940 | file, linenum, oldlogformat); |
| 5941 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5942 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 5943 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 5944 | curproxy->conf.logformat_string != clf_http_log_format) |
| 5945 | free(curproxy->conf.logformat_string); |
| 5946 | curproxy->conf.logformat_string = strdup(args[1]); |
| 5947 | |
| 5948 | free(curproxy->conf.lfs_file); |
| 5949 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 5950 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5951 | |
| 5952 | /* get a chance to improve log-format error reporting by |
| 5953 | * reporting the correct line-number when possible. |
| 5954 | */ |
| 5955 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5956 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 5957 | file, linenum, curproxy->id); |
| 5958 | err_code |= ERR_WARN; |
| 5959 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5960 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 5961 | else if (!strcmp(args[0], "log-format-sd")) { |
| 5962 | if (!*(args[1])) { |
| 5963 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5965 | goto out; |
| 5966 | } |
| 5967 | if (*(args[2])) { |
| 5968 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5970 | goto out; |
| 5971 | } |
| 5972 | |
| 5973 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 5974 | free(curproxy->conf.logformat_sd_string); |
| 5975 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 5976 | |
| 5977 | free(curproxy->conf.lfsd_file); |
| 5978 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 5979 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 5980 | |
| 5981 | /* get a chance to improve log-format-sd error reporting by |
| 5982 | * reporting the correct line-number when possible. |
| 5983 | */ |
| 5984 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5985 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 5986 | file, linenum, curproxy->id); |
| 5987 | err_code |= ERR_WARN; |
| 5988 | } |
| 5989 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 5990 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 5991 | if (*(args[1]) == 0) { |
| 5992 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 5993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5994 | goto out; |
| 5995 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 5996 | chunk_destroy(&curproxy->log_tag); |
| 5997 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 5998 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5999 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6000 | /* delete previous herited or defined syslog servers */ |
| 6001 | struct logsrv *back; |
| 6002 | |
| 6003 | if (*(args[1]) != 0) { |
| 6004 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6006 | goto out; |
| 6007 | } |
| 6008 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6009 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6010 | LIST_DEL(&tmplogsrv->list); |
| 6011 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6012 | } |
| 6013 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6014 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6015 | struct logsrv *logsrv; |
| 6016 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6017 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6018 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6019 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6020 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6021 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6022 | LIST_INIT(&node->list); |
| 6023 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6024 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6025 | } |
| 6026 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6027 | struct sockaddr_storage *sk; |
| 6028 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6029 | int arg = 0; |
| 6030 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6031 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6032 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6033 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6034 | /* just after the address, a length may be specified */ |
| 6035 | if (strcmp(args[arg+2], "len") == 0) { |
| 6036 | len = atoi(args[arg+3]); |
| 6037 | if (len < 80 || len > 65535) { |
| 6038 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6039 | file, linenum, args[arg+3]); |
| 6040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6041 | goto out; |
| 6042 | } |
| 6043 | logsrv->maxlen = len; |
| 6044 | |
| 6045 | /* skip these two args */ |
| 6046 | arg += 2; |
| 6047 | } |
| 6048 | else |
| 6049 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6050 | |
Christopher Faulet | 084aa96 | 2017-08-29 16:54:41 +0200 | [diff] [blame] | 6051 | if (logsrv->maxlen > global.max_syslog_len) |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6052 | global.max_syslog_len = logsrv->maxlen; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6053 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6054 | /* after the length, a format may be specified */ |
| 6055 | if (strcmp(args[arg+2], "format") == 0) { |
| 6056 | logsrv->format = get_log_format(args[arg+3]); |
| 6057 | if (logsrv->format < 0) { |
| 6058 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6060 | goto out; |
| 6061 | } |
| 6062 | |
| 6063 | /* skip these two args */ |
| 6064 | arg += 2; |
| 6065 | } |
| 6066 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6067 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6068 | goto out; |
| 6069 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6070 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6071 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6072 | 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] | 6073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6074 | goto out; |
| 6075 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6076 | } |
| 6077 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6078 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6079 | if (*(args[arg+3])) { |
| 6080 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6081 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6082 | 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] | 6083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6084 | goto out; |
| 6085 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6086 | } |
| 6087 | } |
| 6088 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6089 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6090 | if (*(args[arg+4])) { |
| 6091 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6092 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6093 | 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] | 6094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6095 | goto out; |
| 6096 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6097 | } |
| 6098 | } |
| 6099 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6100 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6101 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6102 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6103 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6104 | goto out; |
| 6105 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6106 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6107 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6108 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6109 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6110 | if (port1 != port2) { |
| 6111 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6112 | file, linenum, args[0], args[1]); |
| 6113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6114 | goto out; |
| 6115 | } |
| 6116 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6117 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6118 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6119 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6120 | |
| 6121 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6122 | } |
| 6123 | else { |
| 6124 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6125 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6128 | } |
| 6129 | } |
| 6130 | 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] | 6131 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6132 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6133 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6134 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6135 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6136 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6137 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6138 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6139 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6140 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6141 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6142 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6143 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6144 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6145 | |
| 6146 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6147 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6148 | free(curproxy->conn_src.iface_name); |
| 6149 | curproxy->conn_src.iface_name = NULL; |
| 6150 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6151 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6152 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6153 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6154 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6155 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6156 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6157 | goto out; |
| 6158 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6159 | |
| 6160 | proto = protocol_by_family(sk->ss_family); |
| 6161 | if (!proto || !proto->connect) { |
| 6162 | 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] | 6163 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6165 | goto out; |
| 6166 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6167 | |
| 6168 | if (port1 != port2) { |
| 6169 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6170 | file, linenum, args[0], args[1]); |
| 6171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6172 | goto out; |
| 6173 | } |
| 6174 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6175 | curproxy->conn_src.source_addr = *sk; |
| 6176 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6177 | |
| 6178 | cur_arg = 2; |
| 6179 | while (*(args[cur_arg])) { |
| 6180 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6181 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6182 | if (!*args[cur_arg + 1]) { |
| 6183 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6184 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6186 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6190 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6191 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6192 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6193 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6194 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6195 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6196 | char *name, *end; |
| 6197 | |
| 6198 | name = args[cur_arg+1] + 7; |
| 6199 | while (isspace(*name)) |
| 6200 | name++; |
| 6201 | |
| 6202 | end = name; |
| 6203 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6204 | end++; |
| 6205 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6206 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6207 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6208 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6209 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6210 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6211 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6212 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6213 | |
| 6214 | /* now look for an occurrence number */ |
| 6215 | while (isspace(*end)) |
| 6216 | end++; |
| 6217 | if (*end == ',') { |
| 6218 | end++; |
| 6219 | name = end; |
| 6220 | if (*end == '-') |
| 6221 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6222 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6223 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6224 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6225 | } |
| 6226 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6227 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6228 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6229 | " occurrences values smaller than %d.\n", |
| 6230 | file, linenum, MAX_HDR_HISTORY); |
| 6231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6232 | goto out; |
| 6233 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6234 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6235 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6236 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6237 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6238 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6239 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6240 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6241 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6242 | goto out; |
| 6243 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6244 | |
| 6245 | proto = protocol_by_family(sk->ss_family); |
| 6246 | if (!proto || !proto->connect) { |
| 6247 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6248 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6250 | goto out; |
| 6251 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6252 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6253 | if (port1 != port2) { |
| 6254 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6255 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6257 | goto out; |
| 6258 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6259 | curproxy->conn_src.tproxy_addr = *sk; |
| 6260 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6261 | } |
| 6262 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6263 | #else /* no TPROXY support */ |
| 6264 | 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] | 6265 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6267 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6268 | #endif |
| 6269 | cur_arg += 2; |
| 6270 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6271 | } |
| 6272 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6273 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6274 | #ifdef SO_BINDTODEVICE |
| 6275 | if (!*args[cur_arg + 1]) { |
| 6276 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6277 | file, linenum, args[0]); |
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 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6281 | free(curproxy->conn_src.iface_name); |
| 6282 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6283 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6284 | global.last_checks |= LSTCHK_NETADM; |
| 6285 | #else |
| 6286 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6287 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6289 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6290 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6291 | cur_arg += 2; |
| 6292 | continue; |
| 6293 | } |
| 6294 | 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] | 6295 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6297 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6298 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6299 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6300 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6301 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6302 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6304 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6305 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6306 | 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] | 6307 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6308 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6309 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6311 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6312 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6313 | |
| 6314 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6315 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6316 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6317 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6318 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6319 | } |
| 6320 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6321 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6322 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6323 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6324 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6326 | } |
| 6327 | 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] | 6328 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6329 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6330 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6331 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6333 | } |
| 6334 | 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] | 6335 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6336 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6337 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6338 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6339 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6340 | } |
| 6341 | 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] | 6342 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6343 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6344 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6345 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6346 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6347 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6348 | 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] | 6349 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6350 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6351 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6352 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6353 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6354 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6355 | 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] | 6356 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6357 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6358 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6361 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6362 | |
| 6363 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6364 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6365 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6366 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6367 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6368 | } |
| 6369 | 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] | 6370 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6371 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6372 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6373 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6374 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6375 | } |
| 6376 | 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] | 6377 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6378 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6379 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6380 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6381 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6382 | } |
| 6383 | 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] | 6384 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6385 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6386 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6387 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6389 | } |
| 6390 | 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] | 6391 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6392 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6393 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6394 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6395 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6396 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6397 | 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] | 6398 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6399 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6400 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6401 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6402 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6403 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6404 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6405 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6406 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6407 | if (curproxy == &defproxy) { |
| 6408 | 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] | 6409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6410 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6411 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6412 | else 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] | 6413 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6414 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6415 | if (*(args[1]) == 0) { |
| 6416 | 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] | 6417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6418 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6419 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6420 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6421 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6422 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6423 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6424 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6426 | goto out; |
| 6427 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6428 | err_code |= warnif_cond_conflicts(cond, |
| 6429 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6430 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6431 | } |
| 6432 | else if (*args[2]) { |
| 6433 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6434 | file, linenum, args[0], args[2]); |
| 6435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6436 | goto out; |
| 6437 | } |
| 6438 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6439 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6440 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6441 | wl->s = strdup(args[1]); |
| 6442 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6443 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6444 | } |
| 6445 | 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] | 6446 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6447 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6448 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6450 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6451 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6452 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6453 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6454 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6455 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6456 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6457 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6458 | } |
| 6459 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6460 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6461 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6462 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6463 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6464 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6465 | } |
| 6466 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6467 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6468 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6469 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6470 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6471 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6472 | } |
| 6473 | 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] | 6474 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6475 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6476 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6478 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6479 | } |
| 6480 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6481 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6482 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6483 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6484 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6485 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6486 | } |
| 6487 | 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] | 6488 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6489 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6490 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6491 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6492 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6493 | } |
| 6494 | 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] | 6495 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6496 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6497 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6498 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6499 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6500 | } |
| 6501 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6502 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6503 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6504 | if (curproxy == &defproxy) { |
| 6505 | 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] | 6506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6507 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6508 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6509 | else 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] | 6510 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6511 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6512 | if (*(args[1]) == 0) { |
| 6513 | 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] | 6514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6515 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6516 | } |
| 6517 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6518 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6519 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6520 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6521 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6523 | goto out; |
| 6524 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6525 | err_code |= warnif_cond_conflicts(cond, |
| 6526 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6527 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6528 | } |
| 6529 | else if (*args[2]) { |
| 6530 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6531 | file, linenum, args[0], args[2]); |
| 6532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6533 | goto out; |
| 6534 | } |
| 6535 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6536 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6537 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6538 | wl->s = strdup(args[1]); |
| 6539 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6540 | } |
| 6541 | else if (!strcmp(args[0], "errorloc") || |
| 6542 | !strcmp(args[0], "errorloc302") || |
| 6543 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6544 | int errnum, errlen; |
| 6545 | char *err; |
| 6546 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6547 | 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] | 6548 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6549 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6550 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6551 | 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] | 6552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6553 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6554 | } |
| 6555 | |
| 6556 | errnum = atol(args[1]); |
| 6557 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6558 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6559 | err = malloc(errlen); |
| 6560 | 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] | 6561 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6562 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6563 | err = malloc(errlen); |
| 6564 | 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] | 6565 | } |
| 6566 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6567 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6568 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6569 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6570 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6571 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6572 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6573 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6574 | |
| 6575 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6576 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6577 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6578 | free(err); |
| 6579 | } |
| 6580 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6581 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6582 | int errnum, errlen, fd; |
| 6583 | char *err; |
| 6584 | struct stat stat; |
| 6585 | |
| 6586 | 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] | 6587 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6588 | |
| 6589 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6590 | 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] | 6591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6592 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | fd = open(args[2], O_RDONLY); |
| 6596 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6597 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6598 | file, linenum, args[2], args[1]); |
| 6599 | if (fd >= 0) |
| 6600 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6602 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6603 | } |
| 6604 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6605 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6606 | errlen = stat.st_size; |
| 6607 | } else { |
| 6608 | 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] | 6609 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6610 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6611 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6615 | errnum = read(fd, err, errlen); |
| 6616 | if (errnum != errlen) { |
| 6617 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6618 | file, linenum, args[2], args[1]); |
| 6619 | close(fd); |
| 6620 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6622 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6623 | } |
| 6624 | close(fd); |
| 6625 | |
| 6626 | errnum = atol(args[1]); |
| 6627 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6628 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6629 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6630 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6631 | break; |
| 6632 | } |
| 6633 | } |
| 6634 | |
| 6635 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6636 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6637 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6638 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6639 | free(err); |
| 6640 | } |
| 6641 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6642 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6643 | struct cfg_kw_list *kwl; |
| 6644 | int index; |
| 6645 | |
| 6646 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6647 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6648 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6649 | continue; |
| 6650 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6651 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6652 | 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] | 6653 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6654 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6656 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6657 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6658 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6659 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6660 | err_code |= ERR_WARN; |
| 6661 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6662 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6663 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6664 | } |
| 6665 | } |
| 6666 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6667 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6668 | 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] | 6669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6670 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6671 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6672 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6673 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6674 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6675 | } |
| 6676 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6677 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6678 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6679 | { |
| 6680 | #ifdef CONFIG_HAP_NS |
| 6681 | const char *err; |
| 6682 | const char *item = args[0]; |
| 6683 | |
| 6684 | if (!strcmp(item, "namespace_list")) { |
| 6685 | return 0; |
| 6686 | } |
| 6687 | else if (!strcmp(item, "namespace")) { |
| 6688 | size_t idx = 1; |
| 6689 | const char *current; |
| 6690 | while (*(current = args[idx++])) { |
| 6691 | err = invalid_char(current); |
| 6692 | if (err) { |
| 6693 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6694 | file, linenum, *err, item, current); |
| 6695 | return ERR_ALERT | ERR_FATAL; |
| 6696 | } |
| 6697 | |
| 6698 | if (netns_store_lookup(current, strlen(current))) { |
| 6699 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6700 | file, linenum, current); |
| 6701 | return ERR_ALERT | ERR_FATAL; |
| 6702 | } |
| 6703 | if (!netns_store_insert(current)) { |
| 6704 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6705 | file, linenum, current); |
| 6706 | return ERR_ALERT | ERR_FATAL; |
| 6707 | } |
| 6708 | } |
| 6709 | } |
| 6710 | |
| 6711 | return 0; |
| 6712 | #else |
| 6713 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6714 | file, linenum); |
| 6715 | return ERR_ALERT | ERR_FATAL; |
| 6716 | #endif |
| 6717 | } |
| 6718 | |
| 6719 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6720 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6721 | { |
| 6722 | |
| 6723 | int err_code = 0; |
| 6724 | const char *err; |
| 6725 | |
| 6726 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6727 | struct userlist *newul; |
| 6728 | |
| 6729 | if (!*args[1]) { |
| 6730 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6731 | file, linenum, args[0]); |
| 6732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6733 | goto out; |
| 6734 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6735 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6736 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6737 | |
| 6738 | err = invalid_char(args[1]); |
| 6739 | if (err) { |
| 6740 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6741 | file, linenum, *err, args[0], args[1]); |
| 6742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6743 | goto out; |
| 6744 | } |
| 6745 | |
| 6746 | for (newul = userlist; newul; newul = newul->next) |
| 6747 | if (!strcmp(newul->name, args[1])) { |
| 6748 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6749 | file, linenum, args[1]); |
| 6750 | err_code |= ERR_WARN; |
| 6751 | goto out; |
| 6752 | } |
| 6753 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6754 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6755 | if (!newul) { |
| 6756 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6757 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6758 | goto out; |
| 6759 | } |
| 6760 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6761 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6762 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6763 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6764 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6765 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6766 | goto out; |
| 6767 | } |
| 6768 | |
| 6769 | newul->next = userlist; |
| 6770 | userlist = newul; |
| 6771 | |
| 6772 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6773 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6774 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6775 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6776 | |
| 6777 | if (!*args[1]) { |
| 6778 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6779 | file, linenum, args[0]); |
| 6780 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6781 | goto out; |
| 6782 | } |
| 6783 | |
| 6784 | err = invalid_char(args[1]); |
| 6785 | if (err) { |
| 6786 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6787 | file, linenum, *err, args[0], args[1]); |
| 6788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6789 | goto out; |
| 6790 | } |
| 6791 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6792 | if (!userlist) |
| 6793 | goto out; |
| 6794 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6795 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6796 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6797 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6798 | file, linenum, args[1], userlist->name); |
| 6799 | err_code |= ERR_ALERT; |
| 6800 | goto out; |
| 6801 | } |
| 6802 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6803 | ag = calloc(1, sizeof(*ag)); |
| 6804 | if (!ag) { |
| 6805 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6806 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6807 | goto out; |
| 6808 | } |
| 6809 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6810 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6811 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6812 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6813 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6814 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6815 | goto out; |
| 6816 | } |
| 6817 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6818 | cur_arg = 2; |
| 6819 | |
| 6820 | while (*args[cur_arg]) { |
| 6821 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6822 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6823 | cur_arg += 2; |
| 6824 | continue; |
| 6825 | } else { |
| 6826 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6827 | file, linenum, args[0]); |
| 6828 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6829 | free(ag->groupusers); |
| 6830 | free(ag->name); |
| 6831 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6832 | goto out; |
| 6833 | } |
| 6834 | } |
| 6835 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6836 | ag->next = userlist->groups; |
| 6837 | userlist->groups = ag; |
| 6838 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6839 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6840 | struct auth_users *newuser; |
| 6841 | int cur_arg; |
| 6842 | |
| 6843 | if (!*args[1]) { |
| 6844 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6845 | file, linenum, args[0]); |
| 6846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6847 | goto out; |
| 6848 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6849 | if (!userlist) |
| 6850 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6851 | |
| 6852 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6853 | if (!strcmp(newuser->user, args[1])) { |
| 6854 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6855 | file, linenum, args[1], userlist->name); |
| 6856 | err_code |= ERR_ALERT; |
| 6857 | goto out; |
| 6858 | } |
| 6859 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6860 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6861 | if (!newuser) { |
| 6862 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6863 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6864 | goto out; |
| 6865 | } |
| 6866 | |
| 6867 | newuser->user = strdup(args[1]); |
| 6868 | |
| 6869 | newuser->next = userlist->users; |
| 6870 | userlist->users = newuser; |
| 6871 | |
| 6872 | cur_arg = 2; |
| 6873 | |
| 6874 | while (*args[cur_arg]) { |
| 6875 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6876 | #ifdef CONFIG_HAP_CRYPT |
| 6877 | if (!crypt("", args[cur_arg + 1])) { |
| 6878 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6879 | file, linenum, newuser->user); |
| 6880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6881 | goto out; |
| 6882 | } |
| 6883 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6884 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6885 | file, linenum); |
| 6886 | err_code |= ERR_ALERT; |
| 6887 | #endif |
| 6888 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6889 | cur_arg += 2; |
| 6890 | continue; |
| 6891 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6892 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6893 | newuser->flags |= AU_O_INSECURE; |
| 6894 | cur_arg += 2; |
| 6895 | continue; |
| 6896 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6897 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6898 | cur_arg += 2; |
| 6899 | continue; |
| 6900 | } else { |
| 6901 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6902 | file, linenum, args[0]); |
| 6903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6904 | goto out; |
| 6905 | } |
| 6906 | } |
| 6907 | } else { |
| 6908 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6910 | } |
| 6911 | |
| 6912 | out: |
| 6913 | return err_code; |
| 6914 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6915 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6916 | int |
| 6917 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6918 | { |
| 6919 | char *beg, *end, *scope = NULL; |
| 6920 | int err_code = 0; |
| 6921 | const char *err; |
| 6922 | |
| 6923 | beg = line + 1; |
| 6924 | end = strchr(beg, ']'); |
| 6925 | |
| 6926 | /* Detect end of scope declaration */ |
| 6927 | if (!end || end == beg) { |
| 6928 | Alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 6929 | file, linenum); |
| 6930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6931 | goto out; |
| 6932 | } |
| 6933 | |
| 6934 | /* Get scope name and check its validity */ |
| 6935 | scope = my_strndup(beg, end-beg); |
| 6936 | err = invalid_char(scope); |
| 6937 | if (err) { |
| 6938 | Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 6939 | file, linenum, *err); |
| 6940 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6941 | goto out; |
| 6942 | } |
| 6943 | |
| 6944 | /* Be sure to have a scope declaration alone on its line */ |
| 6945 | line = end+1; |
| 6946 | while (isspace((unsigned char)*line)) |
| 6947 | line++; |
| 6948 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
| 6949 | Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 6950 | file, linenum, *line); |
| 6951 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6952 | goto out; |
| 6953 | } |
| 6954 | |
| 6955 | /* We have a valid scope declaration, save it */ |
| 6956 | free(cfg_scope); |
| 6957 | cfg_scope = scope; |
| 6958 | scope = NULL; |
| 6959 | |
| 6960 | out: |
| 6961 | free(scope); |
| 6962 | return err_code; |
| 6963 | } |
| 6964 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6965 | /* |
| 6966 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6967 | * Returns the error code, 0 if OK, or any combination of : |
| 6968 | * - ERR_ABORT: must abort ASAP |
| 6969 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6970 | * - ERR_WARN: a warning has been emitted |
| 6971 | * - ERR_ALERT: an alert has been emitted |
| 6972 | * Only the two first ones can stop processing, the two others are just |
| 6973 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6974 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 6975 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6976 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6977 | char *thisline; |
| 6978 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6979 | FILE *f; |
| 6980 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6981 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6982 | struct cfg_section *cs = NULL; |
| 6983 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6984 | int readbytes = 0; |
| 6985 | |
| 6986 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6987 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6988 | return -1; |
| 6989 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6990 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6991 | if ((f=fopen(file,"r")) == NULL) { |
| 6992 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6993 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6994 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6995 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6996 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6997 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6998 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6999 | char *end; |
| 7000 | char *args[MAX_LINE_ARGS + 1]; |
| 7001 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7002 | int dquote = 0; /* double quote */ |
| 7003 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7004 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7005 | linenum++; |
| 7006 | |
| 7007 | end = line + strlen(line); |
| 7008 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7009 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7010 | /* Check if we reached the limit and the last char is not \n. |
| 7011 | * Watch out for the last line without the terminating '\n'! |
| 7012 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7013 | char *newline; |
| 7014 | int newlinesize = linesize * 2; |
| 7015 | |
| 7016 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7017 | if (newline == NULL) { |
| 7018 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7019 | file, linenum); |
| 7020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7021 | continue; |
| 7022 | } |
| 7023 | |
| 7024 | readbytes = linesize - 1; |
| 7025 | linesize = newlinesize; |
| 7026 | thisline = newline; |
| 7027 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7028 | } |
| 7029 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7030 | readbytes = 0; |
| 7031 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7032 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7033 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7034 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7035 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7036 | |
| 7037 | if (*line == '[') {/* This is the begining if a scope */ |
| 7038 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7039 | goto next_line; |
| 7040 | } |
| 7041 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7042 | arg = 0; |
| 7043 | args[arg] = line; |
| 7044 | |
| 7045 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7046 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7047 | if (dquote) |
| 7048 | dquote = 0; |
| 7049 | else |
| 7050 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7051 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7052 | end--; |
| 7053 | } |
| 7054 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7055 | if (squote) |
| 7056 | squote = 0; |
| 7057 | else |
| 7058 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7059 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7060 | end--; |
| 7061 | } |
| 7062 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7063 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7064 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7065 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7066 | int skip = 0; |
| 7067 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7068 | *line = line[1]; |
| 7069 | skip = 1; |
| 7070 | } |
| 7071 | else if (line[1] == 'r') { |
| 7072 | *line = '\r'; |
| 7073 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7074 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7075 | else if (line[1] == 'n') { |
| 7076 | *line = '\n'; |
| 7077 | skip = 1; |
| 7078 | } |
| 7079 | else if (line[1] == 't') { |
| 7080 | *line = '\t'; |
| 7081 | skip = 1; |
| 7082 | } |
| 7083 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7084 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7085 | unsigned char hex1, hex2; |
| 7086 | hex1 = toupper(line[2]) - '0'; |
| 7087 | hex2 = toupper(line[3]) - '0'; |
| 7088 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7089 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7090 | *line = (hex1<<4) + hex2; |
| 7091 | skip = 3; |
| 7092 | } |
| 7093 | else { |
| 7094 | 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] | 7095 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7096 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7097 | } else if (line[1] == '"') { |
| 7098 | *line = '"'; |
| 7099 | skip = 1; |
| 7100 | } else if (line[1] == '\'') { |
| 7101 | *line = '\''; |
| 7102 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7103 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7104 | *line = '$'; |
| 7105 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7106 | } |
| 7107 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7108 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7109 | end -= skip; |
| 7110 | } |
| 7111 | line++; |
| 7112 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7113 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7114 | /* end of string, end of loop */ |
| 7115 | *line = 0; |
| 7116 | break; |
| 7117 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7118 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7119 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7120 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7121 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7122 | line++; |
| 7123 | args[++arg] = line; |
| 7124 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7125 | else if (dquote && *line == '$') { |
| 7126 | /* environment variables are evaluated inside double quotes */ |
| 7127 | char *var_beg; |
| 7128 | char *var_end; |
| 7129 | char save_char; |
| 7130 | char *value; |
| 7131 | int val_len; |
| 7132 | int newlinesize; |
| 7133 | int braces = 0; |
| 7134 | |
| 7135 | var_beg = line + 1; |
| 7136 | var_end = var_beg; |
| 7137 | |
| 7138 | if (*var_beg == '{') { |
| 7139 | var_beg++; |
| 7140 | var_end++; |
| 7141 | braces = 1; |
| 7142 | } |
| 7143 | |
| 7144 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7145 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7147 | goto next_line; /* skip current line */ |
| 7148 | } |
| 7149 | |
| 7150 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7151 | var_end++; |
| 7152 | |
| 7153 | save_char = *var_end; |
| 7154 | *var_end = '\0'; |
| 7155 | value = getenv(var_beg); |
| 7156 | *var_end = save_char; |
| 7157 | val_len = value ? strlen(value) : 0; |
| 7158 | |
| 7159 | if (braces) { |
| 7160 | if (*var_end == '}') { |
| 7161 | var_end++; |
| 7162 | braces = 0; |
| 7163 | } else { |
| 7164 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7166 | goto next_line; /* skip current line */ |
| 7167 | } |
| 7168 | } |
| 7169 | |
| 7170 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7171 | |
| 7172 | /* if not enough space in thisline */ |
| 7173 | if (newlinesize > linesize) { |
| 7174 | char *newline; |
| 7175 | |
| 7176 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7177 | if (newline == NULL) { |
| 7178 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7180 | goto next_line; /* slip current line */ |
| 7181 | } |
| 7182 | /* recompute pointers if realloc returns a new pointer */ |
| 7183 | if (newline != thisline) { |
| 7184 | int i; |
| 7185 | int diff; |
| 7186 | |
| 7187 | for (i = 0; i <= arg; i++) { |
| 7188 | diff = args[i] - thisline; |
| 7189 | args[i] = newline + diff; |
| 7190 | } |
| 7191 | |
| 7192 | diff = var_end - thisline; |
| 7193 | var_end = newline + diff; |
| 7194 | diff = end - thisline; |
| 7195 | end = newline + diff; |
| 7196 | diff = line - thisline; |
| 7197 | line = newline + diff; |
| 7198 | thisline = newline; |
| 7199 | } |
| 7200 | linesize = newlinesize; |
| 7201 | } |
| 7202 | |
| 7203 | /* insert value inside the line */ |
| 7204 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7205 | memcpy(line, value, val_len); |
| 7206 | end += val_len - (var_end - line); |
| 7207 | line += val_len; |
| 7208 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7209 | else { |
| 7210 | line++; |
| 7211 | } |
| 7212 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7213 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7214 | if (dquote) { |
| 7215 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7217 | } |
| 7218 | |
| 7219 | if (squote) { |
| 7220 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7222 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7223 | |
| 7224 | /* empty line */ |
| 7225 | if (!**args) |
| 7226 | continue; |
| 7227 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7228 | if (*line) { |
| 7229 | /* we had to stop due to too many args. |
| 7230 | * Let's terminate the string, print the offending part then cut the |
| 7231 | * last arg. |
| 7232 | */ |
| 7233 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7234 | line++; |
| 7235 | *line = '\0'; |
| 7236 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7237 | 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] | 7238 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7240 | args[arg] = line; |
| 7241 | } |
| 7242 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7243 | /* zero out remaining args and ensure that at least one entry |
| 7244 | * is zeroed out. |
| 7245 | */ |
| 7246 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7247 | args[arg] = line; |
| 7248 | } |
| 7249 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7250 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7251 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7252 | char *tmp; |
| 7253 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7254 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7255 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7256 | for (arg=0; *args[arg+1]; arg++) |
| 7257 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7258 | *tmp = '\0'; // fix the next arg to \0 |
| 7259 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7260 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7261 | else if (!strcmp(args[0], "default")) { |
| 7262 | kwm = KWM_DEF; |
| 7263 | for (arg=0; *args[arg+1]; arg++) |
| 7264 | args[arg] = args[arg+1]; // shift args after inversion |
| 7265 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7266 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7267 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7268 | strcmp(args[0], "log") != 0) { |
| 7269 | 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] | 7270 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7271 | } |
| 7272 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7273 | /* detect section start */ |
| 7274 | list_for_each_entry(ics, §ions, list) { |
| 7275 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7276 | cursection = ics->section_name; |
| 7277 | cs = ics; |
| 7278 | break; |
| 7279 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7280 | } |
| 7281 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7282 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7283 | if (cs) |
| 7284 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7285 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7286 | 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] | 7287 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7288 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7289 | |
| 7290 | if (err_code & ERR_ABORT) |
| 7291 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7292 | } |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7293 | free(cfg_scope); |
| 7294 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7295 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7296 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7297 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7298 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7299 | } |
| 7300 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7301 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7302 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7303 | * bound to all of its processes. After that, if the target is a "listen" |
| 7304 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7305 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7306 | * checked first to ensure that <to> is already bound to all processes of |
| 7307 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7308 | * path to the destination. |
| 7309 | * |
| 7310 | * It is possible to set <to> to NULL for the first call so that the function |
| 7311 | * takes care of visiting the initial frontend in <from>. |
| 7312 | * |
| 7313 | * It is important to note that the function relies on the fact that all names |
| 7314 | * have already been resolved. |
| 7315 | */ |
| 7316 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7317 | { |
| 7318 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7319 | |
| 7320 | if (to) { |
| 7321 | /* check whether we need to go down */ |
| 7322 | if (from->bind_proc && |
| 7323 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7324 | return; |
| 7325 | |
| 7326 | if (!from->bind_proc && !to->bind_proc) |
| 7327 | return; |
| 7328 | |
| 7329 | to->bind_proc = from->bind_proc ? |
| 7330 | (to->bind_proc | from->bind_proc) : 0; |
| 7331 | |
| 7332 | /* now propagate down */ |
| 7333 | from = to; |
| 7334 | } |
| 7335 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7336 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7337 | return; |
| 7338 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7339 | if (from->state == PR_STSTOPPED) |
| 7340 | return; |
| 7341 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7342 | /* default_backend */ |
| 7343 | if (from->defbe.be) |
| 7344 | propagate_processes(from, from->defbe.be); |
| 7345 | |
| 7346 | /* use_backend */ |
| 7347 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7348 | if (rule->dynamic) |
| 7349 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7350 | to = rule->be.backend; |
| 7351 | propagate_processes(from, to); |
| 7352 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7353 | } |
| 7354 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7355 | /* |
| 7356 | * Returns the error code, 0 if OK, or any combination of : |
| 7357 | * - ERR_ABORT: must abort ASAP |
| 7358 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7359 | * - ERR_WARN: a warning has been emitted |
| 7360 | * - ERR_ALERT: an alert has been emitted |
| 7361 | * Only the two first ones can stop processing, the two others are just |
| 7362 | * indicators. |
| 7363 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7364 | int check_config_validity() |
| 7365 | { |
| 7366 | int cfgerr = 0; |
| 7367 | struct proxy *curproxy = NULL; |
| 7368 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7369 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7370 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7371 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7372 | char *err; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 7373 | struct dns_resolvers *curr_resolvers; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7374 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7375 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7376 | /* |
| 7377 | * Now, check for the integrity of all that we have collected. |
| 7378 | */ |
| 7379 | |
| 7380 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7381 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7382 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7383 | if (!global.tune.max_http_hdr) |
| 7384 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7385 | |
| 7386 | if (!global.tune.cookie_len) |
| 7387 | global.tune.cookie_len = CAPTURE_LEN; |
| 7388 | |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 7389 | if (!global.tune.requri_len) |
| 7390 | global.tune.requri_len = REQURI_LEN; |
| 7391 | |
Emeric Brun | 96fd926 | 2017-07-05 13:33:16 +0200 | [diff] [blame] | 7392 | pool2_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED); |
| 7393 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7394 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7395 | |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 7396 | /* allocate pool of resolution per resolvers */ |
| 7397 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 7398 | if (dns_alloc_resolution_pool(curr_resolvers) != 0) { |
| 7399 | /* error message is already displayed by dns_alloc_resolution_pool() */ |
| 7400 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7401 | goto out; |
| 7402 | } |
| 7403 | } |
| 7404 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7405 | /* Post initialisation of the users and groups lists. */ |
| 7406 | err_code = userlist_postinit(); |
| 7407 | if (err_code != ERR_NONE) |
| 7408 | goto out; |
| 7409 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7410 | /* first, we will invert the proxy list order */ |
| 7411 | curproxy = NULL; |
| 7412 | while (proxy) { |
| 7413 | struct proxy *next; |
| 7414 | |
| 7415 | next = proxy->next; |
| 7416 | proxy->next = curproxy; |
| 7417 | curproxy = proxy; |
| 7418 | if (!next) |
| 7419 | break; |
| 7420 | proxy = next; |
| 7421 | } |
| 7422 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7423 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7424 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7425 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7426 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7427 | struct act_rule *trule; |
| 7428 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7429 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7430 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7431 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7432 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7433 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7434 | /* proxy ID not set, use automatic numbering with first |
| 7435 | * spare entry starting with next_pxid. |
| 7436 | */ |
| 7437 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7438 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7439 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7440 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7441 | next_pxid++; |
| 7442 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7443 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7444 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7445 | /* ensure we don't keep listeners uselessly bound */ |
| 7446 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7447 | free((void *)curproxy->table.peers.name); |
| 7448 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7449 | continue; |
| 7450 | } |
| 7451 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7452 | /* Check multi-process mode compatibility for the current proxy */ |
| 7453 | |
| 7454 | if (curproxy->bind_proc) { |
| 7455 | /* an explicit bind-process was specified, let's check how many |
| 7456 | * processes remain. |
| 7457 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7458 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7459 | |
| 7460 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7461 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7462 | 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); |
| 7463 | curproxy->bind_proc = 1; |
| 7464 | } |
| 7465 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7466 | 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); |
| 7467 | curproxy->bind_proc = 0; |
| 7468 | } |
| 7469 | } |
| 7470 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7471 | /* check and reduce the bind-proc of each listener */ |
| 7472 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7473 | unsigned long mask; |
| 7474 | |
| 7475 | if (!bind_conf->bind_proc) |
| 7476 | continue; |
| 7477 | |
| 7478 | mask = nbits(global.nbproc); |
| 7479 | if (curproxy->bind_proc) |
| 7480 | mask &= curproxy->bind_proc; |
| 7481 | /* mask cannot be null here thanks to the previous checks */ |
| 7482 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7483 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7484 | bind_conf->bind_proc &= mask; |
| 7485 | |
| 7486 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7487 | 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", |
| 7488 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7489 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7490 | } |
| 7491 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7492 | 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", |
| 7493 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7494 | bind_conf->bind_proc = 0; |
| 7495 | } |
| 7496 | } |
| 7497 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7498 | switch (curproxy->mode) { |
| 7499 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7500 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7501 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7502 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7503 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7504 | cfgerr++; |
| 7505 | } |
| 7506 | |
| 7507 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7508 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7509 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7510 | break; |
| 7511 | |
| 7512 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7513 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7514 | break; |
| 7515 | |
| 7516 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7517 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7518 | break; |
| 7519 | } |
| 7520 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7521 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7522 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7523 | proxy_type_str(curproxy), curproxy->id); |
| 7524 | err_code |= ERR_WARN; |
| 7525 | } |
| 7526 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7527 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7528 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7529 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7530 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7531 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7532 | cfgerr++; |
| 7533 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7534 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7535 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7536 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7537 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7538 | cfgerr++; |
| 7539 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7540 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7541 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7542 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7543 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7544 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7545 | } |
| 7546 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7547 | 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] | 7548 | /* If no LB algo is set in a backend, and we're not in |
| 7549 | * transparent mode, dispatch mode nor proxy mode, we |
| 7550 | * want to use balance roundrobin by default. |
| 7551 | */ |
| 7552 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7553 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7554 | } |
| 7555 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7556 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7557 | if (curproxy->options & PR_O_DISPATCH) |
| 7558 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7559 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7560 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7561 | else if (curproxy->options & PR_O_TRANSP) |
| 7562 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7563 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7564 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7565 | if (curproxy->options & PR_O_DISABLE404) { |
| 7566 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7567 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7568 | err_code |= ERR_WARN; |
| 7569 | curproxy->options &= ~PR_O_DISABLE404; |
| 7570 | } |
| 7571 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7572 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7573 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7574 | err_code |= ERR_WARN; |
| 7575 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7576 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7577 | } |
| 7578 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7579 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7580 | if (!global.external_check) { |
| 7581 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7582 | curproxy->id, "option external-check"); |
| 7583 | cfgerr++; |
| 7584 | } |
| 7585 | if (!curproxy->check_command) { |
| 7586 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7587 | curproxy->id, "option external-check"); |
| 7588 | cfgerr++; |
| 7589 | } |
| 7590 | } |
| 7591 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7592 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7593 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7594 | 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] | 7595 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7596 | "'email-alert myhostname', or 'email-alert to' " |
| 7597 | "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] | 7598 | "to be present).\n", |
| 7599 | proxy_type_str(curproxy), curproxy->id); |
| 7600 | err_code |= ERR_WARN; |
| 7601 | free_email_alert(curproxy); |
| 7602 | } |
| 7603 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7604 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7605 | } |
| 7606 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7607 | if (curproxy->check_command) { |
| 7608 | int clear = 0; |
| 7609 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7610 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7611 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7612 | err_code |= ERR_WARN; |
| 7613 | clear = 1; |
| 7614 | } |
| 7615 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7616 | 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] | 7617 | curproxy->id, "external-check command"); |
| 7618 | cfgerr++; |
| 7619 | } |
| 7620 | if (clear) { |
| 7621 | free(curproxy->check_command); |
| 7622 | curproxy->check_command = NULL; |
| 7623 | } |
| 7624 | } |
| 7625 | |
| 7626 | if (curproxy->check_path) { |
| 7627 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7628 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7629 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7630 | err_code |= ERR_WARN; |
| 7631 | free(curproxy->check_path); |
| 7632 | curproxy->check_path = NULL; |
| 7633 | } |
| 7634 | } |
| 7635 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7636 | /* if a default backend was specified, let's find it */ |
| 7637 | if (curproxy->defbe.name) { |
| 7638 | struct proxy *target; |
| 7639 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7640 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7641 | if (!target) { |
| 7642 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7643 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7644 | cfgerr++; |
| 7645 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7646 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7647 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7648 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7649 | } else if (target->mode != curproxy->mode && |
| 7650 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7651 | |
| 7652 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7653 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7654 | curproxy->conf.file, curproxy->conf.line, |
| 7655 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7656 | target->conf.file, target->conf.line); |
| 7657 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7658 | } else { |
| 7659 | free(curproxy->defbe.name); |
| 7660 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7661 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7662 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7663 | /* Emit a warning if this proxy also has some servers */ |
| 7664 | if (curproxy->srv) { |
| 7665 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7666 | curproxy->id); |
| 7667 | err_code |= ERR_WARN; |
| 7668 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7669 | } |
| 7670 | } |
| 7671 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7672 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7673 | /* Case of listen without default backend |
| 7674 | * The curproxy will be its own default backend |
| 7675 | * so we update tot_fe_maxconn for a further |
| 7676 | * fullconn's computation */ |
| 7677 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7678 | } |
| 7679 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7680 | /* find the target proxy for 'use_backend' rules */ |
| 7681 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7682 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7683 | struct logformat_node *node; |
| 7684 | char *pxname; |
| 7685 | |
| 7686 | /* Try to parse the string as a log format expression. If the result |
| 7687 | * of the parsing is only one entry containing a simple string, then |
| 7688 | * it's a standard string corresponding to a static rule, thus the |
| 7689 | * parsing is cancelled and be.name is restored to be resolved. |
| 7690 | */ |
| 7691 | pxname = rule->be.name; |
| 7692 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7693 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7694 | curproxy->conf.args.file = rule->file; |
| 7695 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7696 | err = NULL; |
| 7697 | if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
| 7698 | Alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7699 | rule->file, rule->line, pxname, err); |
| 7700 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7701 | cfgerr++; |
| 7702 | continue; |
| 7703 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7704 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7705 | |
| 7706 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7707 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7708 | rule->dynamic = 1; |
| 7709 | free(pxname); |
| 7710 | continue; |
| 7711 | } |
| 7712 | /* simple string: free the expression and fall back to static rule */ |
| 7713 | free(node->arg); |
| 7714 | free(node); |
| 7715 | } |
| 7716 | |
| 7717 | rule->dynamic = 0; |
| 7718 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7719 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7720 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7721 | if (!target) { |
| 7722 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7723 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7724 | cfgerr++; |
| 7725 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7726 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7727 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7728 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7729 | } else if (target->mode != curproxy->mode && |
| 7730 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7731 | |
| 7732 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7733 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7734 | curproxy->conf.file, curproxy->conf.line, |
| 7735 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7736 | target->conf.file, target->conf.line); |
| 7737 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7738 | } else { |
| 7739 | free((void *)rule->be.name); |
| 7740 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7741 | /* For each target of switching rules, we update |
| 7742 | * their tot_fe_maxconn, except if a previous rule point |
| 7743 | * on the same backend or on the default backend */ |
| 7744 | if (rule->be.backend != curproxy->defbe.be) { |
| 7745 | struct switching_rule *swrule; |
| 7746 | |
| 7747 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7748 | if (rule == swrule) { |
| 7749 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7750 | break; |
| 7751 | } |
| 7752 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7753 | /* there is multiple ref of this backend */ |
| 7754 | break; |
| 7755 | } |
| 7756 | } |
| 7757 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7758 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7759 | } |
| 7760 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7761 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7762 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7763 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7764 | |
| 7765 | if (!target) { |
| 7766 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7767 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7768 | cfgerr++; |
| 7769 | continue; |
| 7770 | } |
| 7771 | free((void *)srule->srv.name); |
| 7772 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7773 | } |
| 7774 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7775 | /* find the target table for 'stick' rules */ |
| 7776 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7777 | struct proxy *target; |
| 7778 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7779 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7780 | if (mrule->flags & STK_IS_STORE) |
| 7781 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7782 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7783 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7784 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7785 | else |
| 7786 | target = curproxy; |
| 7787 | |
| 7788 | if (!target) { |
| 7789 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7790 | curproxy->id, mrule->table.name); |
| 7791 | cfgerr++; |
| 7792 | } |
| 7793 | else if (target->table.size == 0) { |
| 7794 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7795 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7796 | cfgerr++; |
| 7797 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7798 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7799 | 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] | 7800 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7801 | cfgerr++; |
| 7802 | } |
| 7803 | else { |
| 7804 | free((void *)mrule->table.name); |
| 7805 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7806 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7807 | } |
| 7808 | } |
| 7809 | |
| 7810 | /* find the target table for 'store response' rules */ |
| 7811 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7812 | struct proxy *target; |
| 7813 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7814 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7815 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7816 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7817 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7818 | else |
| 7819 | target = curproxy; |
| 7820 | |
| 7821 | if (!target) { |
| 7822 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7823 | curproxy->id, mrule->table.name); |
| 7824 | cfgerr++; |
| 7825 | } |
| 7826 | else if (target->table.size == 0) { |
| 7827 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7828 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7829 | cfgerr++; |
| 7830 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7831 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7832 | 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] | 7833 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7834 | cfgerr++; |
| 7835 | } |
| 7836 | else { |
| 7837 | free((void *)mrule->table.name); |
| 7838 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7839 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7840 | } |
| 7841 | } |
| 7842 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7843 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7844 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7845 | struct proxy *target; |
| 7846 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7847 | 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] | 7848 | continue; |
| 7849 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7850 | if (trule->arg.trk_ctr.table.n) |
| 7851 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7852 | else |
| 7853 | target = curproxy; |
| 7854 | |
| 7855 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7856 | 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] | 7857 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7858 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7859 | cfgerr++; |
| 7860 | } |
| 7861 | else if (target->table.size == 0) { |
| 7862 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7863 | 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] | 7864 | cfgerr++; |
| 7865 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7866 | 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] | 7867 | 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] | 7868 | 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] | 7869 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7870 | cfgerr++; |
| 7871 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7872 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7873 | free(trule->arg.trk_ctr.table.n); |
| 7874 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7875 | /* 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] | 7876 | * to pass a list of counters to track and allocate them right here using |
| 7877 | * stktable_alloc_data_type(). |
| 7878 | */ |
| 7879 | } |
| 7880 | } |
| 7881 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7882 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7883 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7884 | struct proxy *target; |
| 7885 | |
| 7886 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7887 | continue; |
| 7888 | |
| 7889 | if (trule->arg.trk_ctr.table.n) |
| 7890 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7891 | else |
| 7892 | target = curproxy; |
| 7893 | |
| 7894 | if (!target) { |
| 7895 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7896 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7897 | tcp_trk_idx(trule->action)); |
| 7898 | cfgerr++; |
| 7899 | } |
| 7900 | else if (target->table.size == 0) { |
| 7901 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7902 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7903 | cfgerr++; |
| 7904 | } |
| 7905 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7906 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7907 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7908 | tcp_trk_idx(trule->action)); |
| 7909 | cfgerr++; |
| 7910 | } |
| 7911 | else { |
| 7912 | free(trule->arg.trk_ctr.table.n); |
| 7913 | trule->arg.trk_ctr.table.t = &target->table; |
| 7914 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7915 | * to pass a list of counters to track and allocate them right here using |
| 7916 | * stktable_alloc_data_type(). |
| 7917 | */ |
| 7918 | } |
| 7919 | } |
| 7920 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7921 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7922 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7923 | struct proxy *target; |
| 7924 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7925 | 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] | 7926 | continue; |
| 7927 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7928 | if (trule->arg.trk_ctr.table.n) |
| 7929 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7930 | else |
| 7931 | target = curproxy; |
| 7932 | |
| 7933 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7934 | 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] | 7935 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7936 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7937 | cfgerr++; |
| 7938 | } |
| 7939 | else if (target->table.size == 0) { |
| 7940 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7941 | 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] | 7942 | cfgerr++; |
| 7943 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7944 | 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] | 7945 | 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] | 7946 | 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] | 7947 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7948 | cfgerr++; |
| 7949 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7950 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7951 | free(trule->arg.trk_ctr.table.n); |
| 7952 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7953 | /* 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] | 7954 | * to pass a list of counters to track and allocate them right here using |
| 7955 | * stktable_alloc_data_type(). |
| 7956 | */ |
| 7957 | } |
| 7958 | } |
| 7959 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7960 | /* parse http-request capture rules to ensure id really exists */ |
| 7961 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7962 | if (hrqrule->action != ACT_CUSTOM || |
| 7963 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 7964 | continue; |
| 7965 | |
| 7966 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 7967 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 7968 | curproxy->id, hrqrule->arg.capid.idx); |
| 7969 | cfgerr++; |
| 7970 | } |
| 7971 | } |
| 7972 | |
| 7973 | /* parse http-response capture rules to ensure id really exists */ |
| 7974 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7975 | if (hrqrule->action != ACT_CUSTOM || |
| 7976 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 7977 | continue; |
| 7978 | |
| 7979 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 7980 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 7981 | curproxy->id, hrqrule->arg.capid.idx); |
| 7982 | cfgerr++; |
| 7983 | } |
| 7984 | } |
| 7985 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7986 | /* find the target table for 'http-request' layer 7 rules */ |
| 7987 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7988 | struct proxy *target; |
| 7989 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7990 | 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] | 7991 | continue; |
| 7992 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7993 | if (hrqrule->arg.trk_ctr.table.n) |
| 7994 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7995 | else |
| 7996 | target = curproxy; |
| 7997 | |
| 7998 | if (!target) { |
| 7999 | 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] | 8000 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8001 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8002 | cfgerr++; |
| 8003 | } |
| 8004 | else if (target->table.size == 0) { |
| 8005 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8006 | 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] | 8007 | cfgerr++; |
| 8008 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8009 | 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] | 8010 | 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] | 8011 | 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] | 8012 | http_trk_idx(hrqrule->action)); |
| 8013 | cfgerr++; |
| 8014 | } |
| 8015 | else { |
| 8016 | free(hrqrule->arg.trk_ctr.table.n); |
| 8017 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 8018 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8019 | * to pass a list of counters to track and allocate them right here using |
| 8020 | * stktable_alloc_data_type(). |
| 8021 | */ |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | /* find the target table for 'http-response' layer 7 rules */ |
| 8026 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8027 | struct proxy *target; |
| 8028 | |
| 8029 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 8030 | continue; |
| 8031 | |
| 8032 | if (hrqrule->arg.trk_ctr.table.n) |
| 8033 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 8034 | else |
| 8035 | target = curproxy; |
| 8036 | |
| 8037 | if (!target) { |
| 8038 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 8039 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 8040 | http_trk_idx(hrqrule->action)); |
| 8041 | cfgerr++; |
| 8042 | } |
| 8043 | else if (target->table.size == 0) { |
| 8044 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 8045 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 8046 | cfgerr++; |
| 8047 | } |
| 8048 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 8049 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 8050 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 8051 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8052 | cfgerr++; |
| 8053 | } |
| 8054 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8055 | free(hrqrule->arg.trk_ctr.table.n); |
| 8056 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8057 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8058 | * to pass a list of counters to track and allocate them right here using |
| 8059 | * stktable_alloc_data_type(). |
| 8060 | */ |
| 8061 | } |
| 8062 | } |
| 8063 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8064 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8065 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8066 | /* insert block_rules into http_req_rules at the beginning */ |
| 8067 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8068 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8069 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8070 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8071 | LIST_INIT(&curproxy->block_rules); |
| 8072 | } |
| 8073 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8074 | if (curproxy->table.peers.name) { |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8075 | struct peers *curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8076 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8077 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8078 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8079 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8080 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8081 | break; |
| 8082 | } |
| 8083 | } |
| 8084 | |
| 8085 | if (!curpeers) { |
| 8086 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8087 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8088 | free((void *)curproxy->table.peers.name); |
| 8089 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8090 | cfgerr++; |
| 8091 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8092 | else if (curpeers->state == PR_STSTOPPED) { |
| 8093 | /* silently disable this peers section */ |
| 8094 | curproxy->table.peers.p = NULL; |
| 8095 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8096 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8097 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8098 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8099 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8100 | cfgerr++; |
| 8101 | } |
| 8102 | } |
| 8103 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8104 | |
| 8105 | if (curproxy->email_alert.mailers.name) { |
| 8106 | struct mailers *curmailers = mailers; |
| 8107 | |
| 8108 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 8109 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8110 | free(curproxy->email_alert.mailers.name); |
| 8111 | curproxy->email_alert.mailers.m = curmailers; |
| 8112 | curmailers->users++; |
| 8113 | break; |
| 8114 | } |
| 8115 | } |
| 8116 | |
| 8117 | if (!curmailers) { |
| 8118 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8119 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8120 | free_email_alert(curproxy); |
| 8121 | cfgerr++; |
| 8122 | } |
| 8123 | } |
| 8124 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8125 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8126 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8127 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8128 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8129 | "proxy", curproxy->id); |
| 8130 | cfgerr++; |
| 8131 | goto out_uri_auth_compat; |
| 8132 | } |
| 8133 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8134 | 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] | 8135 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8136 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8137 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8138 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8139 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8140 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8141 | |
| 8142 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8143 | uri_auth_compat_req[i++] = "realm"; |
| 8144 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8145 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8146 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8147 | uri_auth_compat_req[i++] = "unless"; |
| 8148 | uri_auth_compat_req[i++] = "{"; |
| 8149 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8150 | uri_auth_compat_req[i++] = "}"; |
| 8151 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8152 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8153 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8154 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8155 | cfgerr++; |
| 8156 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8157 | } |
| 8158 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8159 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8160 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8161 | if (curproxy->uri_auth->auth_realm) { |
| 8162 | free(curproxy->uri_auth->auth_realm); |
| 8163 | curproxy->uri_auth->auth_realm = NULL; |
| 8164 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8165 | |
| 8166 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8167 | } |
| 8168 | out_uri_auth_compat: |
| 8169 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8170 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8171 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8172 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8173 | if (!curproxy->conf.logformat_sd_string) { |
| 8174 | /* set the default logformat_sd_string */ |
| 8175 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8176 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8177 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8178 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8179 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8180 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8181 | /* compile the log format */ |
| 8182 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8183 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8184 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8185 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8186 | free(curproxy->conf.logformat_string); |
| 8187 | curproxy->conf.logformat_string = NULL; |
| 8188 | free(curproxy->conf.lfs_file); |
| 8189 | curproxy->conf.lfs_file = NULL; |
| 8190 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8191 | |
| 8192 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8193 | free(curproxy->conf.logformat_sd_string); |
| 8194 | curproxy->conf.logformat_sd_string = NULL; |
| 8195 | free(curproxy->conf.lfsd_file); |
| 8196 | curproxy->conf.lfsd_file = NULL; |
| 8197 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8198 | } |
| 8199 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8200 | if (curproxy->conf.logformat_string) { |
| 8201 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8202 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8203 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8204 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8205 | if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8206 | SMP_VAL_FE_LOG_END, &err)) { |
| 8207 | Alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8208 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8209 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8210 | cfgerr++; |
| 8211 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8212 | curproxy->conf.args.file = NULL; |
| 8213 | curproxy->conf.args.line = 0; |
| 8214 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8215 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8216 | if (curproxy->conf.logformat_sd_string) { |
| 8217 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8218 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8219 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8220 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8221 | if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8222 | SMP_VAL_FE_LOG_END, &err)) { |
| 8223 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8224 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8225 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8226 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8227 | } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) { |
| 8228 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8229 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8230 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8231 | cfgerr++; |
| 8232 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8233 | curproxy->conf.args.file = NULL; |
| 8234 | curproxy->conf.args.line = 0; |
| 8235 | } |
| 8236 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8237 | if (curproxy->conf.uniqueid_format_string) { |
| 8238 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8239 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8240 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8241 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8242 | if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8243 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) { |
| 8244 | Alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8245 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
| 8246 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8247 | cfgerr++; |
| 8248 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8249 | curproxy->conf.args.file = NULL; |
| 8250 | curproxy->conf.args.line = 0; |
| 8251 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8252 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8253 | /* only now we can check if some args remain unresolved. |
| 8254 | * This must be done after the users and groups resolution. |
| 8255 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8256 | cfgerr += smp_resolve_args(curproxy); |
| 8257 | if (!cfgerr) |
| 8258 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8259 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8260 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8261 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8262 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8263 | (!curproxy->timeout.connect || |
| 8264 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8265 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8266 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8267 | " | 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] | 8268 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8269 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8270 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8271 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8272 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8273 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8274 | * We must still support older configurations, so let's find out whether those |
| 8275 | * parameters have been set or must be copied from contimeouts. |
| 8276 | */ |
| 8277 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8278 | if (!curproxy->timeout.tarpit || |
| 8279 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8280 | /* tarpit timeout not set. We search in the following order: |
| 8281 | * default.tarpit, curr.connect, default.connect. |
| 8282 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8283 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8284 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8285 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8286 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8287 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8288 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8289 | } |
| 8290 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8291 | (!curproxy->timeout.queue || |
| 8292 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8293 | /* queue timeout not set. We search in the following order: |
| 8294 | * default.queue, curr.connect, default.connect. |
| 8295 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8296 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8297 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8298 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8299 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8300 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8301 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8302 | } |
| 8303 | } |
| 8304 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8305 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8306 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8307 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8308 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8309 | } |
| 8310 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8311 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8312 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8313 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8314 | proxy_type_str(curproxy), curproxy->id); |
| 8315 | err_code |= ERR_WARN; |
| 8316 | } |
| 8317 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8318 | /* ensure that cookie capture length is not too large */ |
| 8319 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8320 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8321 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8322 | err_code |= ERR_WARN; |
| 8323 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8324 | } |
| 8325 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8326 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8327 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8328 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8329 | curproxy->nb_req_cap * sizeof(char *), |
| 8330 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8334 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8335 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8336 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8337 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8338 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8339 | switch (curproxy->load_server_state_from_file) { |
| 8340 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8341 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8342 | break; |
| 8343 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8344 | if (!global.server_state_file) { |
| 8345 | 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", |
| 8346 | curproxy->id); |
| 8347 | err_code |= ERR_WARN; |
| 8348 | } |
| 8349 | break; |
| 8350 | } |
| 8351 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8352 | /* first, we will invert the servers list order */ |
| 8353 | newsrv = NULL; |
| 8354 | while (curproxy->srv) { |
| 8355 | struct server *next; |
| 8356 | |
| 8357 | next = curproxy->srv->next; |
| 8358 | curproxy->srv->next = newsrv; |
| 8359 | newsrv = curproxy->srv; |
| 8360 | if (!next) |
| 8361 | break; |
| 8362 | curproxy->srv = next; |
| 8363 | } |
| 8364 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8365 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8366 | * We only emit a warning for the first conflict affecting each server, |
| 8367 | * in order to avoid combinatory explosion if all servers have the same |
| 8368 | * name. We do that only for servers which do not have an explicit ID, |
| 8369 | * because these IDs were made also for distinguishing them and we don't |
| 8370 | * want to annoy people who correctly manage them. |
| 8371 | */ |
| 8372 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8373 | struct server *other_srv; |
| 8374 | |
| 8375 | if (newsrv->puid) |
| 8376 | continue; |
| 8377 | |
| 8378 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8379 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8380 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8381 | newsrv->conf.file, newsrv->conf.line, |
| 8382 | proxy_type_str(curproxy), curproxy->id, |
| 8383 | newsrv->id, other_srv->conf.line); |
| 8384 | break; |
| 8385 | } |
| 8386 | } |
| 8387 | } |
| 8388 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8389 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8390 | next_id = 1; |
| 8391 | newsrv = curproxy->srv; |
| 8392 | while (newsrv != NULL) { |
| 8393 | if (!newsrv->puid) { |
| 8394 | /* server ID not set, use automatic numbering with first |
| 8395 | * spare entry starting with next_svid. |
| 8396 | */ |
| 8397 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8398 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8399 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8400 | } |
| 8401 | next_id++; |
| 8402 | newsrv = newsrv->next; |
| 8403 | } |
| 8404 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8405 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8406 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8407 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8408 | /* |
| 8409 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8410 | * tasks to fill the emptied slots when a connection leaves. |
| 8411 | * Also, resolve deferred tracking dependency if needed. |
| 8412 | */ |
| 8413 | newsrv = curproxy->srv; |
| 8414 | while (newsrv != NULL) { |
| 8415 | if (newsrv->minconn > newsrv->maxconn) { |
| 8416 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8417 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8418 | * this will avoid further useless expensive computations. |
| 8419 | */ |
| 8420 | newsrv->maxconn = newsrv->minconn; |
| 8421 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8422 | /* minconn was not specified, so we set it to maxconn */ |
| 8423 | newsrv->minconn = newsrv->maxconn; |
| 8424 | } |
| 8425 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8426 | /* this will also properly set the transport layer for prod and checks */ |
| 8427 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8428 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8429 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8430 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8431 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8432 | /* set the check type on the server */ |
| 8433 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8434 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8435 | if (newsrv->trackit) { |
| 8436 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8437 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8438 | char *pname, *sname; |
| 8439 | |
| 8440 | pname = newsrv->trackit; |
| 8441 | sname = strrchr(pname, '/'); |
| 8442 | |
| 8443 | if (sname) |
| 8444 | *sname++ = '\0'; |
| 8445 | else { |
| 8446 | sname = pname; |
| 8447 | pname = NULL; |
| 8448 | } |
| 8449 | |
| 8450 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8451 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8452 | if (!px) { |
| 8453 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8454 | proxy_type_str(curproxy), curproxy->id, |
| 8455 | newsrv->id, pname); |
| 8456 | cfgerr++; |
| 8457 | goto next_srv; |
| 8458 | } |
| 8459 | } else |
| 8460 | px = curproxy; |
| 8461 | |
| 8462 | srv = findserver(px, sname); |
| 8463 | if (!srv) { |
| 8464 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8465 | proxy_type_str(curproxy), curproxy->id, |
| 8466 | newsrv->id, sname); |
| 8467 | cfgerr++; |
| 8468 | goto next_srv; |
| 8469 | } |
| 8470 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8471 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8472 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8473 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8474 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8475 | "tracking as it does not have any check nor agent enabled.\n", |
| 8476 | proxy_type_str(curproxy), curproxy->id, |
| 8477 | newsrv->id, px->id, srv->id); |
| 8478 | cfgerr++; |
| 8479 | goto next_srv; |
| 8480 | } |
| 8481 | |
| 8482 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8483 | |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8484 | if (newsrv == srv || loop) { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8485 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8486 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8487 | proxy_type_str(curproxy), curproxy->id, |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8488 | newsrv->id, px->id, srv->id, px->id, |
| 8489 | newsrv == srv ? srv->id : loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8490 | cfgerr++; |
| 8491 | goto next_srv; |
| 8492 | } |
| 8493 | |
| 8494 | if (curproxy != px && |
| 8495 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8496 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8497 | "tracking: disable-on-404 option inconsistency.\n", |
| 8498 | proxy_type_str(curproxy), curproxy->id, |
| 8499 | newsrv->id, px->id, srv->id); |
| 8500 | cfgerr++; |
| 8501 | goto next_srv; |
| 8502 | } |
| 8503 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8504 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8505 | newsrv->tracknext = srv->trackers; |
| 8506 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8507 | |
| 8508 | free(newsrv->trackit); |
| 8509 | newsrv->trackit = NULL; |
| 8510 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8511 | |
| 8512 | /* |
| 8513 | * resolve server's resolvers name and update the resolvers pointer |
| 8514 | * accordingly |
| 8515 | */ |
| 8516 | if (newsrv->resolvers_id) { |
| 8517 | struct dns_resolvers *curr_resolvers; |
| 8518 | int found; |
| 8519 | |
| 8520 | found = 0; |
| 8521 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8522 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8523 | found = 1; |
| 8524 | break; |
| 8525 | } |
| 8526 | } |
| 8527 | |
| 8528 | if (!found) { |
| 8529 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8530 | proxy_type_str(curproxy), curproxy->id, |
| 8531 | newsrv->id, newsrv->resolvers_id); |
| 8532 | cfgerr++; |
| 8533 | } else { |
Olivier Houchard | 8da5f98 | 2017-08-04 18:35:36 +0200 | [diff] [blame] | 8534 | if (newsrv->srvrq) { |
| 8535 | if (!newsrv->srvrq->resolvers) { |
| 8536 | newsrv->srvrq->resolvers = curr_resolvers; |
| 8537 | if (dns_link_resolution(newsrv->srvrq, |
| 8538 | OBJ_TYPE_SRVRQ, NULL) != 0) { |
| 8539 | Alert("config : %s '%s', server '%s': unable to set DNS resolution\n", |
| 8540 | proxy_type_str(curproxy), curproxy->id, |
| 8541 | newsrv->id); |
| 8542 | cfgerr++; |
| 8543 | } |
| 8544 | } |
| 8545 | |
| 8546 | } |
| 8547 | if (newsrv->srvrq || newsrv->hostname_dn) { |
Baptiste Assmann | 4274637 | 2017-05-03 12:12:02 +0200 | [diff] [blame] | 8548 | newsrv->resolvers = curr_resolvers; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 8549 | if (dns_link_resolution(newsrv, OBJ_TYPE_SERVER, NULL) != 0) { |
| 8550 | Alert("config : %s '%s', server '%s': unable to set DNS resolution\n", |
| 8551 | proxy_type_str(curproxy), curproxy->id, |
| 8552 | newsrv->id); |
| 8553 | cfgerr++; |
| 8554 | } |
| 8555 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8556 | } |
| 8557 | } |
| 8558 | else { |
| 8559 | /* if no resolvers section associated to this server |
| 8560 | * we can clean up the associated resolution structure |
| 8561 | */ |
| 8562 | if (newsrv->resolution) { |
| 8563 | free(newsrv->resolution->hostname_dn); |
| 8564 | newsrv->resolution->hostname_dn = NULL; |
| 8565 | free(newsrv->resolution); |
| 8566 | newsrv->resolution = NULL; |
| 8567 | } |
| 8568 | } |
| 8569 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8570 | next_srv: |
| 8571 | newsrv = newsrv->next; |
| 8572 | } |
| 8573 | |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 8574 | /* |
| 8575 | * Try to generate dynamic cookies for servers now. |
| 8576 | * It couldn't be done earlier, since at the time we parsed |
| 8577 | * the server line, we may not have known yet that we |
| 8578 | * should use dynamic cookies, or the secret key may not |
| 8579 | * have been provided yet. |
| 8580 | */ |
| 8581 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
| 8582 | newsrv = curproxy->srv; |
| 8583 | while (newsrv != NULL) { |
| 8584 | srv_set_dyncookie(newsrv); |
| 8585 | newsrv = newsrv->next; |
| 8586 | } |
| 8587 | |
| 8588 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8589 | /* We have to initialize the server lookup mechanism depending |
| 8590 | * on what LB algorithm was choosen. |
| 8591 | */ |
| 8592 | |
| 8593 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8594 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8595 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8596 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8597 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8598 | init_server_map(curproxy); |
| 8599 | } else { |
| 8600 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8601 | fwrr_init_server_groups(curproxy); |
| 8602 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8603 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8604 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8605 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8606 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8607 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8608 | fwlc_init_server_tree(curproxy); |
| 8609 | } else { |
| 8610 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8611 | fas_init_server_tree(curproxy); |
| 8612 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8613 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8614 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8615 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8616 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8617 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8618 | chash_init_server_tree(curproxy); |
| 8619 | } else { |
| 8620 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8621 | init_server_map(curproxy); |
| 8622 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8623 | break; |
| 8624 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8625 | |
| 8626 | if (curproxy->options & PR_O_LOGASAP) |
| 8627 | curproxy->to_log &= ~LW_BYTES; |
| 8628 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8629 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8630 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8631 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8632 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8633 | proxy_type_str(curproxy), curproxy->id); |
| 8634 | err_code |= ERR_WARN; |
| 8635 | } |
| 8636 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8637 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8638 | int optnum; |
| 8639 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8640 | if (curproxy->uri_auth) { |
| 8641 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8642 | proxy_type_str(curproxy), curproxy->id); |
| 8643 | err_code |= ERR_WARN; |
| 8644 | curproxy->uri_auth = NULL; |
| 8645 | } |
| 8646 | |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8647 | if (curproxy->capture_name) { |
| 8648 | Warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8649 | proxy_type_str(curproxy), curproxy->id); |
| 8650 | err_code |= ERR_WARN; |
| 8651 | } |
| 8652 | |
| 8653 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
| 8654 | Warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8655 | proxy_type_str(curproxy), curproxy->id); |
| 8656 | err_code |= ERR_WARN; |
| 8657 | } |
| 8658 | |
| 8659 | if (!LIST_ISEMPTY(&curproxy->http_res_rules)) { |
| 8660 | Warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8661 | proxy_type_str(curproxy), curproxy->id); |
| 8662 | err_code |= ERR_WARN; |
| 8663 | } |
| 8664 | |
| 8665 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8666 | Warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8667 | proxy_type_str(curproxy), curproxy->id); |
| 8668 | err_code |= ERR_WARN; |
| 8669 | } |
| 8670 | |
| 8671 | if (!LIST_ISEMPTY(&curproxy->redirect_rules)) { |
| 8672 | Warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8673 | proxy_type_str(curproxy), curproxy->id); |
| 8674 | err_code |= ERR_WARN; |
| 8675 | } |
| 8676 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8677 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8678 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8679 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8680 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8681 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8682 | } |
| 8683 | |
| 8684 | if (curproxy->options & PR_O_ORGTO) { |
| 8685 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8686 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8687 | err_code |= ERR_WARN; |
| 8688 | curproxy->options &= ~PR_O_ORGTO; |
| 8689 | } |
| 8690 | |
| 8691 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8692 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8693 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8694 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8695 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8696 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8697 | err_code |= ERR_WARN; |
| 8698 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8699 | } |
| 8700 | } |
| 8701 | |
| 8702 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8703 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8704 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8705 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8706 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8707 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8708 | err_code |= ERR_WARN; |
| 8709 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8710 | } |
| 8711 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8712 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8713 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8714 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8715 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8716 | 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] | 8717 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8718 | err_code |= ERR_WARN; |
| 8719 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8720 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8721 | } |
| 8722 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8723 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8724 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8725 | */ |
| 8726 | newsrv = curproxy->srv; |
| 8727 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8728 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8729 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8730 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8731 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8732 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8733 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8734 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8735 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8736 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8737 | err_code |= ERR_WARN; |
| 8738 | } |
| 8739 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8740 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8741 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8742 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8743 | err_code |= ERR_WARN; |
| 8744 | } |
| 8745 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8746 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8747 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8748 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8749 | 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] | 8750 | 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] | 8751 | err_code |= ERR_WARN; |
| 8752 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8753 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8754 | |
| 8755 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8756 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8757 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8758 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8759 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
| 8760 | Warning("config : %s '%s' : connections to server '%s' use the client's IP address as the source while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'usesrc' and to use the 'forwardfor' option instead.\n", |
| 8761 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8762 | err_code |= ERR_WARN; |
| 8763 | } |
| 8764 | |
| 8765 | |
| 8766 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
| 8767 | Warning("config : %s '%s' : connections to server '%s' will have a PROXY protocol header announcing the first client's IP address while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'send-proxy' and to use the 'forwardfor' option instead.\n", |
| 8768 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8769 | err_code |= ERR_WARN; |
| 8770 | } |
| 8771 | } |
| 8772 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8773 | newsrv = newsrv->next; |
| 8774 | } |
| 8775 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8776 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8777 | * with no inspect-delay |
| 8778 | */ |
| 8779 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8780 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8781 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8782 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8783 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8784 | 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] | 8785 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8786 | break; |
| 8787 | } |
| 8788 | |
| 8789 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8790 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8791 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8792 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8793 | " setting the tcp-request inspect-delay.\n", |
| 8794 | proxy_type_str(curproxy), curproxy->id); |
| 8795 | err_code |= ERR_WARN; |
| 8796 | } |
| 8797 | } |
| 8798 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8799 | /* Check filter configuration, if any */ |
| 8800 | cfgerr += flt_check(curproxy); |
| 8801 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8802 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8803 | if (!curproxy->accept) |
| 8804 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8805 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8806 | if (curproxy->tcp_req.inspect_delay || |
| 8807 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8808 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8809 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8810 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8811 | 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] | 8812 | 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] | 8813 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8814 | |
| 8815 | /* both TCP and HTTP must check switching rules */ |
| 8816 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8817 | |
| 8818 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8819 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8820 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8821 | curproxy->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8822 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8823 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8824 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8825 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8826 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8827 | } |
| 8828 | |
| 8829 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8830 | if (curproxy->tcp_req.inspect_delay || |
| 8831 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8832 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8833 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8834 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8835 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8836 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8837 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8838 | 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] | 8839 | 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] | 8840 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8841 | |
| 8842 | /* If the backend does requires RDP cookie persistence, we have to |
| 8843 | * enable the corresponding analyser. |
| 8844 | */ |
| 8845 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8846 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8847 | |
| 8848 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8849 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8850 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8851 | curproxy->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8852 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8853 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8854 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8855 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8856 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8857 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8858 | } |
| 8859 | |
| 8860 | /***********************************************************/ |
| 8861 | /* At this point, target names have already been resolved. */ |
| 8862 | /***********************************************************/ |
| 8863 | |
| 8864 | /* Check multi-process mode compatibility */ |
| 8865 | |
| 8866 | if (global.nbproc > 1 && global.stats_fe) { |
| 8867 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8868 | unsigned long mask; |
| 8869 | |
| 8870 | mask = nbits(global.nbproc); |
| 8871 | if (global.stats_fe->bind_proc) |
| 8872 | mask &= global.stats_fe->bind_proc; |
| 8873 | |
| 8874 | if (bind_conf->bind_proc) |
| 8875 | mask &= bind_conf->bind_proc; |
| 8876 | |
| 8877 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8878 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8879 | break; |
| 8880 | } |
| 8881 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8882 | 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"); |
| 8883 | } |
| 8884 | } |
| 8885 | |
| 8886 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8887 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8888 | if (curproxy->bind_proc) |
| 8889 | continue; |
| 8890 | |
| 8891 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8892 | unsigned long mask; |
| 8893 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8894 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8895 | curproxy->bind_proc |= mask; |
| 8896 | } |
| 8897 | |
| 8898 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8899 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8900 | } |
| 8901 | |
| 8902 | if (global.stats_fe) { |
| 8903 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8904 | unsigned long mask; |
| 8905 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8906 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8907 | global.stats_fe->bind_proc |= mask; |
| 8908 | } |
| 8909 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8910 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8911 | } |
| 8912 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8913 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8914 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8915 | */ |
| 8916 | if (!cfgerr) { |
| 8917 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8918 | if (curproxy->cap & PR_CAP_FE) |
| 8919 | propagate_processes(curproxy, NULL); |
| 8920 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8921 | } |
| 8922 | |
| 8923 | /* Bind each unbound backend to all processes when not specified. */ |
| 8924 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8925 | if (curproxy->bind_proc) |
| 8926 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8927 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8928 | } |
| 8929 | |
| 8930 | /*******************************************************/ |
| 8931 | /* At this step, all proxies have a non-null bind_proc */ |
| 8932 | /*******************************************************/ |
| 8933 | |
| 8934 | /* perform the final checks before creating tasks */ |
| 8935 | |
| 8936 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8937 | struct listener *listener; |
| 8938 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8939 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8940 | /* Configure SSL for each bind line. |
| 8941 | * Note: if configuration fails at some point, the ->ctx member |
| 8942 | * remains NULL so that listeners can later detach. |
| 8943 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8944 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8945 | if (bind_conf->xprt->prepare_bind_conf && |
| 8946 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8947 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8948 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8949 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8950 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8951 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8952 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8953 | int nbproc; |
| 8954 | |
| 8955 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8956 | (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] | 8957 | nbits(global.nbproc)); |
| 8958 | |
| 8959 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8960 | nbproc = 1; |
| 8961 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8962 | if (!listener->luid) { |
| 8963 | /* listener ID not set, use automatic numbering with first |
| 8964 | * spare entry starting with next_luid. |
| 8965 | */ |
| 8966 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8967 | listener->conf.id.key = listener->luid = next_id; |
| 8968 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8969 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8970 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8971 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8972 | /* enable separate counters */ |
| 8973 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8974 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8975 | if (!listener->name) |
| 8976 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8977 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8978 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8979 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8980 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8981 | if (!listener->maxconn) |
| 8982 | listener->maxconn = curproxy->maxconn; |
| 8983 | if (!listener->backlog) |
| 8984 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8985 | if (!listener->maxaccept) |
| 8986 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8987 | |
| 8988 | /* we want to have an optimal behaviour on single process mode to |
| 8989 | * maximize the work at once, but in multi-process we want to keep |
| 8990 | * some fairness between processes, so we target half of the max |
| 8991 | * number of events to be balanced over all the processes the proxy |
| 8992 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8993 | * used to disable the limit. |
| 8994 | */ |
| 8995 | if (listener->maxaccept > 0) { |
| 8996 | if (nbproc > 1) |
| 8997 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8998 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8999 | } |
| 9000 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 9001 | listener->accept = session_accept_fd; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 9002 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 9003 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 9004 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9005 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 9006 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9007 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 9008 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 9009 | listener->options |= LI_O_TCP_L5_RULES; |
| 9010 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 9011 | if (curproxy->mon_mask.s_addr) |
| 9012 | listener->options |= LI_O_CHK_MONNET; |
| 9013 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9014 | /* smart accept mode is automatic in HTTP mode */ |
| 9015 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9016 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9017 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 9018 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 9019 | } |
| 9020 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9021 | /* Release unused SSL configs */ |
| 9022 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 9023 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 9024 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9025 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9026 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 9027 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9028 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9029 | int count, maxproc = 0; |
| 9030 | |
| 9031 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9032 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9033 | if (count > maxproc) |
| 9034 | maxproc = count; |
| 9035 | } |
| 9036 | /* backends have 0, frontends have 1 or more */ |
| 9037 | if (maxproc != 1) |
| 9038 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 9039 | " limited to process assigned to the current request.\n", |
| 9040 | curproxy->id); |
| 9041 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9042 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 9043 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 9044 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9045 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9046 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9047 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 9048 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 9049 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9050 | } |
| 9051 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9052 | |
| 9053 | /* create the task associated with the proxy */ |
| 9054 | curproxy->task = task_new(); |
| 9055 | if (curproxy->task) { |
| 9056 | curproxy->task->context = curproxy; |
| 9057 | curproxy->task->process = manage_proxy; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9058 | } else { |
| 9059 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 9060 | curproxy->id); |
| 9061 | cfgerr++; |
| 9062 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 9063 | } |
| 9064 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9065 | /* automatically compute fullconn if not set. We must not do it in the |
| 9066 | * loop above because cross-references are not yet fully resolved. |
| 9067 | */ |
| 9068 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9069 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9070 | * the possible incoming frontend's maxconns. |
| 9071 | */ |
| 9072 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9073 | /* we have the sum of the maxconns in <total>. We only |
| 9074 | * keep 10% of that sum to set the default fullconn, with |
| 9075 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9076 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 9077 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9078 | if (!curproxy->fullconn) |
| 9079 | curproxy->fullconn = 1; |
| 9080 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9081 | } |
| 9082 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9083 | /* |
| 9084 | * Recount currently required checks. |
| 9085 | */ |
| 9086 | |
| 9087 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 9088 | int optnum; |
| 9089 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9090 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9091 | if (curproxy->options & cfg_opts[optnum].val) |
| 9092 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9093 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9094 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9095 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9096 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9097 | } |
| 9098 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9099 | /* compute the required process bindings for the peers */ |
| 9100 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 9101 | if (curproxy->table.peers.p) |
| 9102 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9103 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9104 | if (cfg_peers) { |
| 9105 | struct peers *curpeers = cfg_peers, **last; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9106 | struct peer *p, *pb; |
| 9107 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9108 | /* Remove all peers sections which don't have a valid listener, |
| 9109 | * which are not used by any table, or which are bound to more |
| 9110 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9111 | */ |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9112 | last = &cfg_peers; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9113 | while (*last) { |
| 9114 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9115 | |
| 9116 | if (curpeers->state == PR_STSTOPPED) { |
| 9117 | /* the "disabled" keyword was present */ |
| 9118 | if (curpeers->peers_fe) |
| 9119 | stop_proxy(curpeers->peers_fe); |
| 9120 | curpeers->peers_fe = NULL; |
| 9121 | } |
| 9122 | else if (!curpeers->peers_fe) { |
| 9123 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9124 | curpeers->id, localpeer); |
| 9125 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9126 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9127 | /* either it's totally stopped or too much used */ |
| 9128 | if (curpeers->peers_fe->bind_proc) { |
| 9129 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 9130 | "running in different processes (%d different ones). " |
| 9131 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9132 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9133 | cfgerr++; |
| 9134 | } |
| 9135 | stop_proxy(curpeers->peers_fe); |
| 9136 | curpeers->peers_fe = NULL; |
| 9137 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9138 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9139 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9140 | last = &curpeers->next; |
| 9141 | continue; |
| 9142 | } |
| 9143 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9144 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9145 | p = curpeers->remote; |
| 9146 | while (p) { |
| 9147 | pb = p->next; |
| 9148 | free(p->id); |
| 9149 | free(p); |
| 9150 | p = pb; |
| 9151 | } |
| 9152 | |
| 9153 | /* Destroy and unlink this curpeers section. |
| 9154 | * Note: curpeers is backed up into *last. |
| 9155 | */ |
| 9156 | free(curpeers->id); |
| 9157 | curpeers = curpeers->next; |
| 9158 | free(*last); |
| 9159 | *last = curpeers; |
| 9160 | } |
| 9161 | } |
| 9162 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9163 | /* initialize stick-tables on backend capable proxies. This must not |
| 9164 | * be done earlier because the data size may be discovered while parsing |
| 9165 | * other proxies. |
| 9166 | */ |
| 9167 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9168 | if (curproxy->state == PR_STSTOPPED) |
| 9169 | continue; |
| 9170 | |
| 9171 | if (!stktable_init(&curproxy->table)) { |
| 9172 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9173 | cfgerr++; |
| 9174 | } |
| 9175 | } |
| 9176 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9177 | if (mailers) { |
| 9178 | struct mailers *curmailers = mailers, **last; |
| 9179 | struct mailer *m, *mb; |
| 9180 | |
| 9181 | /* Remove all mailers sections which don't have a valid listener. |
| 9182 | * This can happen when a mailers section is never referenced. |
| 9183 | */ |
| 9184 | last = &mailers; |
| 9185 | while (*last) { |
| 9186 | curmailers = *last; |
| 9187 | if (curmailers->users) { |
| 9188 | last = &curmailers->next; |
| 9189 | continue; |
| 9190 | } |
| 9191 | |
| 9192 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9193 | curmailers->id); |
| 9194 | |
| 9195 | m = curmailers->mailer_list; |
| 9196 | while (m) { |
| 9197 | mb = m->next; |
| 9198 | free(m->id); |
| 9199 | free(m); |
| 9200 | m = mb; |
| 9201 | } |
| 9202 | |
| 9203 | /* Destroy and unlink this curmailers section. |
| 9204 | * Note: curmailers is backed up into *last. |
| 9205 | */ |
| 9206 | free(curmailers->id); |
| 9207 | curmailers = curmailers->next; |
| 9208 | free(*last); |
| 9209 | *last = curmailers; |
| 9210 | } |
| 9211 | } |
| 9212 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9213 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9214 | * a server-state file locally defined and none has been provided */ |
| 9215 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9216 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9217 | curproxy->server_state_file_name == NULL) |
| 9218 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9219 | } |
| 9220 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9221 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9222 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9223 | MEM_F_SHARED); |
| 9224 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9225 | if (cfgerr > 0) |
| 9226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9227 | out: |
| 9228 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9229 | } |
| 9230 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9231 | /* |
| 9232 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9233 | * parsing sessions. |
| 9234 | */ |
| 9235 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9236 | { |
| 9237 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9238 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9239 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9240 | /* |
| 9241 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9242 | */ |
| 9243 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9244 | { |
| 9245 | LIST_DEL(&kwl->list); |
| 9246 | LIST_INIT(&kwl->list); |
| 9247 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9248 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9249 | /* this function register new section in the haproxy configuration file. |
| 9250 | * <section_name> is the name of this new section and <section_parser> |
| 9251 | * is the called parser. If two section declaration have the same name, |
| 9252 | * only the first declared is used. |
| 9253 | */ |
| 9254 | int cfg_register_section(char *section_name, |
| 9255 | int (*section_parser)(const char *, int, char **, int)) |
| 9256 | { |
| 9257 | struct cfg_section *cs; |
| 9258 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9259 | list_for_each_entry(cs, §ions, list) { |
| 9260 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9261 | Alert("register section '%s': already registered.\n", section_name); |
| 9262 | return 0; |
| 9263 | } |
| 9264 | } |
| 9265 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9266 | cs = calloc(1, sizeof(*cs)); |
| 9267 | if (!cs) { |
| 9268 | Alert("register section '%s': out of memory.\n", section_name); |
| 9269 | return 0; |
| 9270 | } |
| 9271 | |
| 9272 | cs->section_name = section_name; |
| 9273 | cs->section_parser = section_parser; |
| 9274 | |
| 9275 | LIST_ADDQ(§ions, &cs->list); |
| 9276 | |
| 9277 | return 1; |
| 9278 | } |
| 9279 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9280 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9281 | * free all config section entries |
| 9282 | */ |
| 9283 | void cfg_unregister_sections(void) |
| 9284 | { |
| 9285 | struct cfg_section *cs, *ics; |
| 9286 | |
| 9287 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9288 | LIST_DEL(&cs->list); |
| 9289 | free(cs); |
| 9290 | } |
| 9291 | } |
| 9292 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9293 | void cfg_backup_sections(struct list *backup_sections) |
| 9294 | { |
| 9295 | struct cfg_section *cs, *ics; |
| 9296 | |
| 9297 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9298 | LIST_DEL(&cs->list); |
| 9299 | LIST_ADDQ(backup_sections, &cs->list); |
| 9300 | } |
| 9301 | } |
| 9302 | |
| 9303 | void cfg_restore_sections(struct list *backup_sections) |
| 9304 | { |
| 9305 | struct cfg_section *cs, *ics; |
| 9306 | |
| 9307 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9308 | LIST_DEL(&cs->list); |
| 9309 | LIST_ADDQ(§ions, &cs->list); |
| 9310 | } |
| 9311 | } |
| 9312 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9313 | __attribute__((constructor)) |
| 9314 | static void cfgparse_init(void) |
| 9315 | { |
| 9316 | /* Register internal sections */ |
| 9317 | cfg_register_section("listen", cfg_parse_listen); |
| 9318 | cfg_register_section("frontend", cfg_parse_listen); |
| 9319 | cfg_register_section("backend", cfg_parse_listen); |
| 9320 | cfg_register_section("defaults", cfg_parse_listen); |
| 9321 | cfg_register_section("global", cfg_parse_global); |
| 9322 | cfg_register_section("userlist", cfg_parse_users); |
| 9323 | cfg_register_section("peers", cfg_parse_peers); |
| 9324 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9325 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9326 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9327 | } |
| 9328 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9329 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9330 | * Local variables: |
| 9331 | * c-indent-level: 8 |
| 9332 | * c-basic-offset: 8 |
| 9333 | * End: |
| 9334 | */ |