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> |
Christopher Faulet | 4fce0d8 | 2017-09-18 11:57:31 +0200 | [diff] [blame] | 57 | #include <proto/action.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 58 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 60 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 61 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 62 | #include <proto/compression.h> |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 63 | #include <proto/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 64 | #include <proto/stats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 65 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 66 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 67 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 68 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 69 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 70 | #include <proto/lb_fwlc.h> |
| 71 | #include <proto/lb_fwrr.h> |
| 72 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 73 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 74 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 75 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 76 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 77 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 78 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 79 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 80 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 81 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 82 | #include <proto/stream.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 83 | #include <proto/stick_table.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 84 | #include <proto/task.h> |
| 85 | #include <proto/tcp_rules.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 86 | |
| 87 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 88 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 89 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 90 | * |
| 91 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 92 | */ |
| 93 | const char sslv3_client_hello_pkt[] = { |
| 94 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 95 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 96 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 97 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 98 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 99 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 100 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 101 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 102 | "\x00" /* Session ID length : empty (no session ID) */ |
| 103 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 104 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 105 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 106 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 107 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 108 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 109 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 110 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 111 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 112 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 113 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 114 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 115 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 116 | }; |
| 117 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 118 | /* various keyword modifiers */ |
| 119 | enum kw_mod { |
| 120 | KWM_STD = 0, /* normal */ |
| 121 | KWM_NO, /* "no" prefixed before the keyword */ |
| 122 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 123 | }; |
| 124 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 125 | /* permit to store configuration section */ |
| 126 | struct cfg_section { |
| 127 | struct list list; |
| 128 | char *section_name; |
| 129 | int (*section_parser)(const char *, int, char **, int); |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 130 | int (*post_section_parser)(); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /* Used to chain configuration sections definitions. This list |
| 134 | * stores struct cfg_section |
| 135 | */ |
| 136 | struct list sections = LIST_HEAD_INIT(sections); |
| 137 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 138 | /* store post configuration parsing */ |
| 139 | |
| 140 | struct cfg_postparser { |
| 141 | struct list list; |
| 142 | char *name; |
| 143 | int (*func)(); |
| 144 | }; |
| 145 | |
| 146 | struct list postparsers = LIST_HEAD_INIT(postparsers); |
| 147 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 148 | /* 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] | 149 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 150 | const char *name; |
| 151 | unsigned int val; |
| 152 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 153 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 154 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /* proxy->options */ |
| 158 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 159 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 160 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 161 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 162 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 163 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 164 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 165 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { "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] | 167 | { "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] | 168 | { "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] | 169 | { "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] | 170 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 171 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 172 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 173 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 174 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 175 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 176 | #else |
| 177 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 178 | #endif |
| 179 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 180 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 183 | /* proxy->options2 */ |
| 184 | static const struct cfg_opt cfg_opts2[] = |
| 185 | { |
| 186 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 187 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 188 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 189 | { "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] | 190 | #else |
| 191 | { "splice-request", 0, 0, 0, 0 }, |
| 192 | { "splice-response", 0, 0, 0, 0 }, |
| 193 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 194 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 195 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 196 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 197 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 198 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 199 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 200 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 201 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 202 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 203 | { "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] | 204 | { "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] | 205 | { "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] | 206 | { "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] | 207 | { "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] | 208 | { NULL, 0, 0, 0 } |
| 209 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 210 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 211 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 212 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 213 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 214 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 215 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 217 | /* List head of all known configuration keywords */ |
| 218 | static struct cfg_kw_list cfg_keywords = { |
| 219 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 220 | }; |
| 221 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | /* |
| 223 | * converts <str> to a list of listeners which are dynamically allocated. |
| 224 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 225 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 226 | * - <port> is a numerical port from 1 to 65535 ; |
| 227 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 228 | * 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] | 229 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 230 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 231 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 232 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 233 | 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] | 234 | { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 235 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 236 | int port, end; |
| 237 | |
| 238 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 239 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | while (next && *next) { |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 241 | struct sockaddr_storage *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 242 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 243 | |
| 244 | str = next; |
| 245 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 246 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 247 | *next++ = 0; |
| 248 | } |
| 249 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 250 | ss2 = str2sa_range(str, NULL, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 251 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 252 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 253 | if (!ss2) |
| 254 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 255 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 256 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 257 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 258 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 259 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 260 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 261 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 262 | if (!port || !end) { |
| 263 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 264 | goto fail; |
| 265 | } |
| 266 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 267 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 268 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 269 | goto fail; |
| 270 | } |
| 271 | |
| 272 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 273 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 274 | goto fail; |
| 275 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 276 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 277 | else if (ss2->ss_family == AF_UNSPEC) { |
| 278 | socklen_t addr_len; |
| 279 | |
| 280 | /* We want to attach to an already bound fd whose number |
| 281 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 282 | * Note that by definition there is a single listener. |
| 283 | * We still have to determine the address family to |
| 284 | * register the correct protocol. |
| 285 | */ |
| 286 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 287 | addr_len = sizeof(*ss2); |
| 288 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 289 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 290 | goto fail; |
| 291 | } |
| 292 | |
| 293 | port = end = get_host_port(ss2); |
| 294 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 295 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 296 | /* OK the address looks correct */ |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 297 | if (!create_listeners(bind_conf, ss2, port, end, fd, err)) { |
| 298 | memprintf(err, "%s for address '%s'.\n", *err, str); |
| 299 | goto fail; |
| 300 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 301 | } /* end while(next) */ |
| 302 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 303 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 304 | fail: |
| 305 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 306 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 307 | } |
| 308 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 309 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 310 | * Report an error in <msg> when there are too many arguments. This version is |
| 311 | * intended to be used by keyword parsers so that the message will be included |
| 312 | * into the general error message. The index is the current keyword in args. |
| 313 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 314 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 315 | * message may also be null, it will simply not be produced (useful to check only). |
| 316 | * <msg> and <err_code> are only affected on error. |
| 317 | */ |
| 318 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 319 | { |
| 320 | int i; |
| 321 | |
| 322 | if (!*args[index + maxarg + 1]) |
| 323 | return 0; |
| 324 | |
| 325 | if (msg) { |
| 326 | *msg = NULL; |
| 327 | memprintf(msg, "%s", args[0]); |
| 328 | for (i = 1; i <= index; i++) |
| 329 | memprintf(msg, "%s %s", *msg, args[i]); |
| 330 | |
| 331 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 332 | } |
| 333 | if (err_code) |
| 334 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 335 | |
| 336 | return 1; |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * same as too_many_args_idx with a 0 index |
| 341 | */ |
| 342 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 343 | { |
| 344 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 345 | } |
| 346 | |
| 347 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 348 | * Report a fatal Alert when there is too much arguments |
| 349 | * The index is the current keyword in args |
| 350 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 351 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 352 | */ |
| 353 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 354 | { |
| 355 | char *kw = NULL; |
| 356 | int i; |
| 357 | |
| 358 | if (!*args[index + maxarg + 1]) |
| 359 | return 0; |
| 360 | |
| 361 | memprintf(&kw, "%s", args[0]); |
| 362 | for (i = 1; i <= index; i++) { |
| 363 | memprintf(&kw, "%s %s", kw, args[i]); |
| 364 | } |
| 365 | |
| 366 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 367 | free(kw); |
| 368 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 369 | return 1; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * same as alertif_too_many_args_idx with a 0 index |
| 374 | */ |
| 375 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 376 | { |
| 377 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 378 | } |
| 379 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 380 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 381 | * Return 1 if the warning has been emitted, otherwise 0. |
| 382 | */ |
| 383 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 384 | { |
| 385 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 386 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 387 | file, line, arg); |
| 388 | return 1; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 393 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 394 | * Return 1 if the warning has been emitted, otherwise 0. |
| 395 | */ |
| 396 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 397 | { |
| 398 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 399 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 400 | file, line, arg); |
| 401 | return 1; |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 406 | /* Report a warning if a rule is placed after a 'block' rule. |
| 407 | * Return 1 if the warning has been emitted, otherwise 0. |
| 408 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 409 | 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] | 410 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 411 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 412 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 413 | file, line, arg); |
| 414 | return 1; |
| 415 | } |
| 416 | return 0; |
| 417 | } |
| 418 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 419 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 420 | * Return 1 if the warning has been emitted, otherwise 0. |
| 421 | */ |
| 422 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 423 | { |
| 424 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 425 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 426 | file, line, arg); |
| 427 | return 1; |
| 428 | } |
| 429 | return 0; |
| 430 | } |
| 431 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 432 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 433 | * Return 1 if the warning has been emitted, otherwise 0. |
| 434 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 435 | 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] | 436 | { |
| 437 | if (proxy->req_exp) { |
| 438 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 439 | file, line, arg); |
| 440 | return 1; |
| 441 | } |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | /* Report a warning if a rule is placed after a reqadd rule. |
| 446 | * Return 1 if the warning has been emitted, otherwise 0. |
| 447 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 448 | 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] | 449 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 450 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 451 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 452 | file, line, arg); |
| 453 | return 1; |
| 454 | } |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | /* Report a warning if a rule is placed after a redirect rule. |
| 459 | * Return 1 if the warning has been emitted, otherwise 0. |
| 460 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 461 | 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] | 462 | { |
| 463 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 464 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 465 | file, line, arg); |
| 466 | return 1; |
| 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 472 | * Return 1 if the warning has been emitted, otherwise 0. |
| 473 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 474 | 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] | 475 | { |
| 476 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 477 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 478 | file, line, arg); |
| 479 | return 1; |
| 480 | } |
| 481 | return 0; |
| 482 | } |
| 483 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 484 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 485 | * Return 1 if the warning has been emitted, otherwise 0. |
| 486 | */ |
| 487 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 488 | { |
| 489 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 490 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 491 | file, line, arg); |
| 492 | return 1; |
| 493 | } |
| 494 | return 0; |
| 495 | } |
| 496 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 497 | /* report a warning if a redirect rule is dangerously placed */ |
| 498 | 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] | 499 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 500 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 501 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 502 | } |
| 503 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 504 | /* report a warning if a reqadd rule is dangerously placed */ |
| 505 | 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] | 506 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 507 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 508 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 511 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 512 | 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] | 513 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 514 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 515 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* report a warning if an http-request rule is dangerously placed */ |
| 519 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 520 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 521 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 522 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 525 | /* report a warning if a block rule is dangerously placed */ |
| 526 | 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] | 527 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 528 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 529 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 532 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 533 | 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] | 534 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 535 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 536 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 537 | } |
| 538 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 539 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 540 | 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] | 541 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 542 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 543 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 544 | } |
| 545 | |
| 546 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 547 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 548 | { |
| 549 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 550 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 551 | } |
| 552 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 553 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 554 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 555 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 556 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 557 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 558 | 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] | 559 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 560 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 561 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 562 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 563 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 564 | return 0; |
| 565 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 566 | acl = acl_cond_conflicts(cond, where); |
| 567 | if (acl) { |
| 568 | if (acl->name && *acl->name) |
| 569 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 570 | file, line, acl->name, sample_ckp_names(where)); |
| 571 | else |
| 572 | 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] | 573 | 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] | 574 | return ERR_WARN; |
| 575 | } |
| 576 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 577 | return 0; |
| 578 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 579 | if (acl->name && *acl->name) |
| 580 | 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] | 581 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 582 | else |
| 583 | 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] | 584 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 585 | return ERR_WARN; |
| 586 | } |
| 587 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 588 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 589 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 590 | * any combination of : |
| 591 | * - ERR_ABORT: must abort ASAP |
| 592 | * - ERR_FATAL: we can continue parsing but not start the service |
| 593 | * - ERR_WARN: a warning has been emitted |
| 594 | * - ERR_ALERT: an alert has been emitted |
| 595 | * Only the two first ones can stop processing, the two others are just |
| 596 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 597 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 598 | 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] | 599 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 600 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 601 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 602 | |
| 603 | if (!strcmp(args[0], "global")) { /* new section */ |
| 604 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 605 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 606 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 607 | } |
| 608 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 609 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 610 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 611 | global.mode |= MODE_DAEMON; |
| 612 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 613 | else if (!strcmp(args[0], "master-worker")) { |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 614 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 615 | goto out; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 616 | if (*args[1]) { |
| 617 | if (!strcmp(args[1], "exit-on-failure")) { |
| 618 | global.tune.options |= GTUNE_EXIT_ONFAILURE; |
| 619 | } else { |
| 620 | Alert("parsing [%s:%d] : '%s' only supports 'exit-on-failure' option.\n", file, linenum, args[0]); |
| 621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 622 | goto out; |
| 623 | } |
| 624 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 625 | global.mode |= MODE_MWORKER; |
| 626 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 627 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 628 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 629 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 630 | global.mode |= MODE_DEBUG; |
| 631 | } |
| 632 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 633 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 634 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 635 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 636 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 637 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 638 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 639 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 640 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 641 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 642 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 643 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 644 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 645 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 646 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 647 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 648 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 649 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 650 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 651 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 652 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 653 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 654 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 655 | global.tune.options &= ~GTUNE_USE_GAI; |
| 656 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 657 | else if (!strcmp(args[0], "noreuseport")) { |
| 658 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 659 | goto out; |
| 660 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 661 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 662 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 663 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 664 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 665 | global.mode |= MODE_QUIET; |
| 666 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 667 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 668 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 669 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 670 | if (global.tune.maxpollevents != 0) { |
| 671 | 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] | 672 | err_code |= ERR_ALERT; |
| 673 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 674 | } |
| 675 | if (*(args[1]) == 0) { |
| 676 | 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] | 677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 678 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 679 | } |
| 680 | global.tune.maxpollevents = atol(args[1]); |
| 681 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 682 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 683 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 684 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 685 | if (global.tune.maxaccept != 0) { |
| 686 | 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] | 687 | err_code |= ERR_ALERT; |
| 688 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 689 | } |
| 690 | if (*(args[1]) == 0) { |
| 691 | 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] | 692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 693 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 694 | } |
| 695 | global.tune.maxaccept = atol(args[1]); |
| 696 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 697 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 698 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 699 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 700 | if (*(args[1]) == 0) { |
| 701 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 703 | goto out; |
| 704 | } |
| 705 | global.tune.chksize = atol(args[1]); |
| 706 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 707 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 708 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 709 | goto out; |
| 710 | if (*(args[1]) == 0) { |
| 711 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 713 | goto out; |
| 714 | } |
| 715 | global.tune.recv_enough = atol(args[1]); |
| 716 | } |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 717 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 718 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 719 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 720 | if (*(args[1]) == 0) { |
| 721 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 723 | goto out; |
| 724 | } |
| 725 | global.tune.buf_limit = atol(args[1]); |
| 726 | if (global.tune.buf_limit) { |
| 727 | if (global.tune.buf_limit < 3) |
| 728 | global.tune.buf_limit = 3; |
| 729 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 730 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 731 | } |
| 732 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 733 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 734 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 735 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 736 | if (*(args[1]) == 0) { |
| 737 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 739 | goto out; |
| 740 | } |
| 741 | global.tune.reserved_bufs = atol(args[1]); |
| 742 | if (global.tune.reserved_bufs < 2) |
| 743 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 744 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 745 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 746 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 747 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 748 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 749 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 750 | if (*(args[1]) == 0) { |
| 751 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 753 | goto out; |
| 754 | } |
| 755 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 756 | if (global.tune.bufsize <= 0) { |
| 757 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 759 | goto out; |
| 760 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 761 | } |
| 762 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 763 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 764 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 765 | if (*(args[1]) == 0) { |
| 766 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 767 | err_code |= ERR_ALERT | ERR_FATAL; |
| 768 | goto out; |
| 769 | } |
| 770 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 771 | if (global.tune.maxrewrite < 0) { |
| 772 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 774 | goto out; |
| 775 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 776 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 777 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 778 | unsigned int idle; |
| 779 | const char *res; |
| 780 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 781 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 782 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 783 | if (*(args[1]) == 0) { |
| 784 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 786 | goto out; |
| 787 | } |
| 788 | |
| 789 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 790 | if (res) { |
| 791 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 792 | file, linenum, *res, args[0]); |
| 793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 794 | goto out; |
| 795 | } |
| 796 | |
| 797 | if (idle > 65535) { |
| 798 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 800 | goto out; |
| 801 | } |
| 802 | global.tune.idle_timer = idle; |
| 803 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 804 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 805 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 806 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 807 | if (global.tune.client_rcvbuf != 0) { |
| 808 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 809 | err_code |= ERR_ALERT; |
| 810 | goto out; |
| 811 | } |
| 812 | if (*(args[1]) == 0) { |
| 813 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 815 | goto out; |
| 816 | } |
| 817 | global.tune.client_rcvbuf = atol(args[1]); |
| 818 | } |
| 819 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 820 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 821 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 822 | if (global.tune.server_rcvbuf != 0) { |
| 823 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 824 | err_code |= ERR_ALERT; |
| 825 | goto out; |
| 826 | } |
| 827 | if (*(args[1]) == 0) { |
| 828 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 830 | goto out; |
| 831 | } |
| 832 | global.tune.server_rcvbuf = atol(args[1]); |
| 833 | } |
| 834 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 835 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 836 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 837 | if (global.tune.client_sndbuf != 0) { |
| 838 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 839 | err_code |= ERR_ALERT; |
| 840 | goto out; |
| 841 | } |
| 842 | if (*(args[1]) == 0) { |
| 843 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 845 | goto out; |
| 846 | } |
| 847 | global.tune.client_sndbuf = atol(args[1]); |
| 848 | } |
| 849 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 850 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 851 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 852 | if (global.tune.server_sndbuf != 0) { |
| 853 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 854 | err_code |= ERR_ALERT; |
| 855 | goto out; |
| 856 | } |
| 857 | if (*(args[1]) == 0) { |
| 858 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 860 | goto out; |
| 861 | } |
| 862 | global.tune.server_sndbuf = atol(args[1]); |
| 863 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 864 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 865 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 866 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 867 | if (*(args[1]) == 0) { |
| 868 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 870 | goto out; |
| 871 | } |
| 872 | global.tune.pipesize = atol(args[1]); |
| 873 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 874 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 875 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 876 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 877 | if (*(args[1]) == 0) { |
| 878 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto out; |
| 881 | } |
| 882 | global.tune.cookie_len = atol(args[1]) + 1; |
| 883 | } |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 884 | else if (!strcmp(args[0], "tune.http.logurilen")) { |
| 885 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 886 | goto out; |
| 887 | if (*(args[1]) == 0) { |
| 888 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 890 | goto out; |
| 891 | } |
| 892 | global.tune.requri_len = atol(args[1]) + 1; |
| 893 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 894 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 895 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 896 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 897 | if (*(args[1]) == 0) { |
| 898 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 900 | goto out; |
| 901 | } |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 902 | global.tune.max_http_hdr = atoi(args[1]); |
| 903 | if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) { |
| 904 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 905 | file, linenum, args[0]); |
| 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto out; |
| 908 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 909 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 910 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 911 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 912 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 913 | if (*args[1]) { |
| 914 | global.tune.comp_maxlevel = atoi(args[1]); |
| 915 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 916 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 917 | file, linenum, args[0]); |
| 918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 919 | goto out; |
| 920 | } |
| 921 | } else { |
| 922 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 923 | file, linenum, args[0]); |
| 924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 925 | goto out; |
| 926 | } |
| 927 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 928 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 929 | if (*args[1]) { |
| 930 | global.tune.pattern_cache = atoi(args[1]); |
| 931 | if (global.tune.pattern_cache < 0) { |
| 932 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 933 | file, linenum, args[0]); |
| 934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 935 | goto out; |
| 936 | } |
| 937 | } else { |
| 938 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 939 | file, linenum, args[0]); |
| 940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 941 | goto out; |
| 942 | } |
| 943 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 944 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 945 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 946 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 947 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 948 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 949 | err_code |= ERR_ALERT; |
| 950 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 951 | } |
| 952 | if (*(args[1]) == 0) { |
| 953 | 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] | 954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 955 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 956 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 957 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 958 | 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]); |
| 959 | err_code |= ERR_WARN; |
| 960 | goto out; |
| 961 | } |
| 962 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 963 | } |
| 964 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 965 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 966 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 967 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 968 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 969 | err_code |= ERR_ALERT; |
| 970 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 971 | } |
| 972 | if (*(args[1]) == 0) { |
| 973 | 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] | 974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 976 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 977 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 978 | 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]); |
| 979 | err_code |= ERR_WARN; |
| 980 | goto out; |
| 981 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 982 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 983 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 984 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 985 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 986 | global.external_check = 1; |
| 987 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 988 | /* user/group name handling */ |
| 989 | else if (!strcmp(args[0], "user")) { |
| 990 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 991 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 992 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 993 | if (global.uid != 0) { |
| 994 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 995 | err_code |= ERR_ALERT; |
| 996 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 997 | } |
| 998 | errno = 0; |
| 999 | ha_user = getpwnam(args[1]); |
| 1000 | if (ha_user != NULL) { |
| 1001 | global.uid = (int)ha_user->pw_uid; |
| 1002 | } |
| 1003 | else { |
| 1004 | 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] | 1005 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | else if (!strcmp(args[0], "group")) { |
| 1009 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1010 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1011 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1012 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1013 | 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] | 1014 | err_code |= ERR_ALERT; |
| 1015 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1016 | } |
| 1017 | errno = 0; |
| 1018 | ha_group = getgrnam(args[1]); |
| 1019 | if (ha_group != NULL) { |
| 1020 | global.gid = (int)ha_group->gr_gid; |
| 1021 | } |
| 1022 | else { |
| 1023 | 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] | 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1028 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1029 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1030 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1031 | if (*(args[1]) == 0) { |
| 1032 | 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] | 1033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1034 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1035 | } |
| 1036 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1037 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1038 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1039 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
| 1042 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1043 | } |
| 1044 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1045 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1046 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1047 | if (global.maxconn != 0) { |
| 1048 | 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] | 1049 | err_code |= ERR_ALERT; |
| 1050 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1051 | } |
| 1052 | if (*(args[1]) == 0) { |
| 1053 | 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] | 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1056 | } |
| 1057 | global.maxconn = atol(args[1]); |
| 1058 | #ifdef SYSTEM_MAXCONN |
| 1059 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1060 | 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); |
| 1061 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1062 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1063 | } |
| 1064 | #endif /* SYSTEM_MAXCONN */ |
| 1065 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1066 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1067 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1068 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1069 | if (*(args[1]) == 0) { |
| 1070 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | if (strcmp(args[1],"none") == 0) |
| 1075 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1076 | else if (strcmp(args[1],"required") == 0) |
| 1077 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1078 | else { |
| 1079 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1081 | goto out; |
| 1082 | } |
| 1083 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1084 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1085 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1086 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1087 | if (global.cps_lim != 0) { |
| 1088 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1089 | err_code |= ERR_ALERT; |
| 1090 | goto out; |
| 1091 | } |
| 1092 | if (*(args[1]) == 0) { |
| 1093 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1095 | goto out; |
| 1096 | } |
| 1097 | global.cps_lim = atol(args[1]); |
| 1098 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1099 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1100 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1101 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1102 | if (global.sps_lim != 0) { |
| 1103 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1104 | err_code |= ERR_ALERT; |
| 1105 | goto out; |
| 1106 | } |
| 1107 | if (*(args[1]) == 0) { |
| 1108 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1110 | goto out; |
| 1111 | } |
| 1112 | global.sps_lim = atol(args[1]); |
| 1113 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1114 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1115 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1116 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1117 | if (global.ssl_lim != 0) { |
| 1118 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1119 | err_code |= ERR_ALERT; |
| 1120 | goto out; |
| 1121 | } |
| 1122 | if (*(args[1]) == 0) { |
| 1123 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1125 | goto out; |
| 1126 | } |
| 1127 | global.ssl_lim = atol(args[1]); |
| 1128 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1129 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1130 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1131 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1132 | if (*(args[1]) == 0) { |
| 1133 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1135 | goto out; |
| 1136 | } |
| 1137 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1138 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1139 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1140 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1141 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1142 | if (global.maxpipes != 0) { |
| 1143 | 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] | 1144 | err_code |= ERR_ALERT; |
| 1145 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1146 | } |
| 1147 | if (*(args[1]) == 0) { |
| 1148 | 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] | 1149 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1150 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1151 | } |
| 1152 | global.maxpipes = atol(args[1]); |
| 1153 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1154 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1155 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1156 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1157 | if (*(args[1]) == 0) { |
| 1158 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1160 | goto out; |
| 1161 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1162 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1163 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1164 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1165 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1166 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1167 | if (*(args[1]) == 0) { |
| 1168 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1170 | goto out; |
| 1171 | } |
| 1172 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1173 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1174 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1176 | goto out; |
| 1177 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1178 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1179 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1180 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1181 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1182 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1183 | if (global.rlimit_nofile != 0) { |
| 1184 | 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] | 1185 | err_code |= ERR_ALERT; |
| 1186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1187 | } |
| 1188 | if (*(args[1]) == 0) { |
| 1189 | 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] | 1190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1191 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1192 | } |
| 1193 | global.rlimit_nofile = atol(args[1]); |
| 1194 | } |
| 1195 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1196 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1197 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1198 | if (global.chroot != NULL) { |
| 1199 | 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] | 1200 | err_code |= ERR_ALERT; |
| 1201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1202 | } |
| 1203 | if (*(args[1]) == 0) { |
| 1204 | 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] | 1205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1206 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1207 | } |
| 1208 | global.chroot = strdup(args[1]); |
| 1209 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1210 | else if (!strcmp(args[0], "description")) { |
| 1211 | int i, len=0; |
| 1212 | char *d; |
| 1213 | |
| 1214 | if (!*args[1]) { |
| 1215 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1216 | file, linenum, args[0]); |
| 1217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1218 | goto out; |
| 1219 | } |
| 1220 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1221 | for (i = 1; *args[i]; i++) |
| 1222 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1223 | |
| 1224 | if (global.desc) |
| 1225 | free(global.desc); |
| 1226 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1227 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1228 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1229 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1230 | for (i = 2; *args[i]; i++) |
| 1231 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1232 | } |
| 1233 | else if (!strcmp(args[0], "node")) { |
| 1234 | int i; |
| 1235 | char c; |
| 1236 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1237 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1238 | goto out; |
| 1239 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1240 | for (i=0; args[1][i]; i++) { |
| 1241 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1242 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1243 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | if (!i || args[1][i]) { |
| 1248 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1249 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1250 | file, linenum, args[0]); |
| 1251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1252 | goto out; |
| 1253 | } |
| 1254 | |
| 1255 | if (global.node) |
| 1256 | free(global.node); |
| 1257 | |
| 1258 | global.node = strdup(args[1]); |
| 1259 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1260 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1261 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1262 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1263 | if (global.pidfile != NULL) { |
| 1264 | 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] | 1265 | err_code |= ERR_ALERT; |
| 1266 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1267 | } |
| 1268 | if (*(args[1]) == 0) { |
| 1269 | 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] | 1270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1271 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1272 | } |
| 1273 | global.pidfile = strdup(args[1]); |
| 1274 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1275 | else if (!strcmp(args[0], "unix-bind")) { |
| 1276 | int cur_arg = 1; |
| 1277 | while (*(args[cur_arg])) { |
| 1278 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1279 | if (global.unix_bind.prefix != NULL) { |
| 1280 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1281 | err_code |= ERR_ALERT; |
| 1282 | cur_arg += 2; |
| 1283 | continue; |
| 1284 | } |
| 1285 | |
| 1286 | if (*(args[cur_arg+1]) == 0) { |
| 1287 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1289 | goto out; |
| 1290 | } |
| 1291 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1292 | cur_arg += 2; |
| 1293 | continue; |
| 1294 | } |
| 1295 | |
| 1296 | if (!strcmp(args[cur_arg], "mode")) { |
| 1297 | |
| 1298 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1299 | cur_arg += 2; |
| 1300 | continue; |
| 1301 | } |
| 1302 | |
| 1303 | if (!strcmp(args[cur_arg], "uid")) { |
| 1304 | |
| 1305 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1306 | cur_arg += 2; |
| 1307 | continue; |
| 1308 | } |
| 1309 | |
| 1310 | if (!strcmp(args[cur_arg], "gid")) { |
| 1311 | |
| 1312 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1313 | cur_arg += 2; |
| 1314 | continue; |
| 1315 | } |
| 1316 | |
| 1317 | if (!strcmp(args[cur_arg], "user")) { |
| 1318 | struct passwd *user; |
| 1319 | |
| 1320 | user = getpwnam(args[cur_arg + 1]); |
| 1321 | if (!user) { |
| 1322 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1323 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1325 | goto out; |
| 1326 | } |
| 1327 | |
| 1328 | global.unix_bind.ux.uid = user->pw_uid; |
| 1329 | cur_arg += 2; |
| 1330 | continue; |
| 1331 | } |
| 1332 | |
| 1333 | if (!strcmp(args[cur_arg], "group")) { |
| 1334 | struct group *group; |
| 1335 | |
| 1336 | group = getgrnam(args[cur_arg + 1]); |
| 1337 | if (!group) { |
| 1338 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1339 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1341 | goto out; |
| 1342 | } |
| 1343 | |
| 1344 | global.unix_bind.ux.gid = group->gr_gid; |
| 1345 | cur_arg += 2; |
| 1346 | continue; |
| 1347 | } |
| 1348 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1349 | 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] | 1350 | file, linenum, args[0]); |
| 1351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1352 | goto out; |
| 1353 | } |
| 1354 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1355 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1356 | /* delete previous herited or defined syslog servers */ |
| 1357 | struct logsrv *back; |
| 1358 | struct logsrv *tmp; |
| 1359 | |
| 1360 | if (*(args[1]) != 0) { |
| 1361 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1363 | goto out; |
| 1364 | } |
| 1365 | |
| 1366 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1367 | LIST_DEL(&tmp->list); |
| 1368 | free(tmp); |
| 1369 | } |
| 1370 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1371 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1372 | struct sockaddr_storage *sk; |
| 1373 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1374 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1375 | int arg = 0; |
| 1376 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1377 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1378 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1379 | goto out; |
| 1380 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1381 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1382 | 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] | 1383 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1384 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1385 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1386 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1387 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1388 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1389 | /* just after the address, a length may be specified */ |
| 1390 | if (strcmp(args[arg+2], "len") == 0) { |
| 1391 | len = atoi(args[arg+3]); |
| 1392 | if (len < 80 || len > 65535) { |
| 1393 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1394 | file, linenum, args[arg+3]); |
| 1395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1396 | goto out; |
| 1397 | } |
| 1398 | logsrv->maxlen = len; |
| 1399 | |
| 1400 | /* skip these two args */ |
| 1401 | arg += 2; |
| 1402 | } |
| 1403 | else |
| 1404 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1405 | |
Christopher Faulet | 084aa96 | 2017-08-29 16:54:41 +0200 | [diff] [blame] | 1406 | if (logsrv->maxlen > global.max_syslog_len) |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1407 | global.max_syslog_len = logsrv->maxlen; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1408 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1409 | /* after the length, a format may be specified */ |
| 1410 | if (strcmp(args[arg+2], "format") == 0) { |
| 1411 | logsrv->format = get_log_format(args[arg+3]); |
| 1412 | if (logsrv->format < 0) { |
| 1413 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1414 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1415 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1416 | goto out; |
| 1417 | } |
| 1418 | |
| 1419 | /* skip these two args */ |
| 1420 | arg += 2; |
| 1421 | } |
| 1422 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1423 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1424 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1425 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1426 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1427 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1428 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1429 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1430 | 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] | 1431 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1432 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1433 | } |
| 1434 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1435 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1436 | if (*(args[arg+3])) { |
| 1437 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1438 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1439 | 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] | 1440 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1441 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1445 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1446 | if (*(args[arg+4])) { |
| 1447 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1448 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1449 | 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] | 1450 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1451 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1455 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1456 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1457 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1458 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1459 | free(logsrv); |
| 1460 | goto out; |
| 1461 | } |
| 1462 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1463 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1464 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1465 | if (port1 != port2) { |
| 1466 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1467 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1468 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1469 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1470 | goto out; |
| 1471 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1472 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1473 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1474 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1475 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1476 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1477 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1478 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1479 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1480 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1481 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1482 | |
| 1483 | if (global.log_send_hostname != NULL) { |
| 1484 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1485 | err_code |= ERR_ALERT; |
| 1486 | goto out; |
| 1487 | } |
| 1488 | |
| 1489 | if (*(args[1])) |
| 1490 | name = args[1]; |
| 1491 | else |
| 1492 | name = hostname; |
| 1493 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1494 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1495 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1496 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1497 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1498 | if (global.server_state_base != NULL) { |
| 1499 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1500 | err_code |= ERR_ALERT; |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | if (!*(args[1])) { |
| 1505 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1506 | err_code |= ERR_FATAL; |
| 1507 | goto out; |
| 1508 | } |
| 1509 | |
| 1510 | global.server_state_base = strdup(args[1]); |
| 1511 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1512 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1513 | if (global.server_state_file != NULL) { |
| 1514 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1515 | err_code |= ERR_ALERT; |
| 1516 | goto out; |
| 1517 | } |
| 1518 | |
| 1519 | if (!*(args[1])) { |
| 1520 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1521 | err_code |= ERR_FATAL; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
| 1525 | global.server_state_file = strdup(args[1]); |
| 1526 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1527 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1528 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1529 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1530 | if (*(args[1]) == 0) { |
| 1531 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1533 | goto out; |
| 1534 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1535 | chunk_destroy(&global.log_tag); |
| 1536 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1537 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1538 | 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] | 1539 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1540 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1541 | if (global.spread_checks != 0) { |
| 1542 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1543 | err_code |= ERR_ALERT; |
| 1544 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1545 | } |
| 1546 | if (*(args[1]) == 0) { |
| 1547 | 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] | 1548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1549 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1550 | } |
| 1551 | global.spread_checks = atol(args[1]); |
| 1552 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1553 | 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] | 1554 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1555 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1556 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1557 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1558 | const char *err; |
| 1559 | unsigned int val; |
| 1560 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1561 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1562 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1563 | if (*(args[1]) == 0) { |
| 1564 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1566 | goto out; |
| 1567 | } |
| 1568 | |
| 1569 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1570 | if (err) { |
| 1571 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1573 | } |
| 1574 | global.max_spread_checks = val; |
| 1575 | if (global.max_spread_checks < 0) { |
| 1576 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1578 | } |
| 1579 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1580 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1581 | #ifdef USE_CPU_AFFINITY |
| 1582 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1583 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1584 | unsigned long cpus = 0; |
| 1585 | |
| 1586 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1587 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1588 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1589 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1590 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1591 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1592 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1593 | proc = atol(args[1]); |
| 1594 | if (proc >= 1 && proc <= LONGBITS) |
| 1595 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1599 | 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", |
| 1600 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1602 | goto out; |
| 1603 | } |
| 1604 | |
| 1605 | cur_arg = 2; |
| 1606 | while (*args[cur_arg]) { |
| 1607 | unsigned int low, high; |
| 1608 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1609 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1610 | char *dash = strchr(args[cur_arg], '-'); |
| 1611 | |
| 1612 | low = high = str2uic(args[cur_arg]); |
| 1613 | if (dash) |
| 1614 | high = str2uic(dash + 1); |
| 1615 | |
| 1616 | if (high < low) { |
| 1617 | unsigned int swap = low; |
| 1618 | low = high; |
| 1619 | high = swap; |
| 1620 | } |
| 1621 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1622 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1623 | 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] | 1624 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1626 | goto out; |
| 1627 | } |
| 1628 | |
| 1629 | while (low <= high) |
| 1630 | cpus |= 1UL << low++; |
| 1631 | } |
| 1632 | else { |
| 1633 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1634 | file, linenum, args[0], args[cur_arg]); |
| 1635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1636 | goto out; |
| 1637 | } |
| 1638 | cur_arg++; |
| 1639 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1640 | for (i = 0; i < LONGBITS; i++) |
| 1641 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1642 | global.cpu_map[i] = cpus; |
| 1643 | #else |
| 1644 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1646 | goto out; |
| 1647 | #endif |
| 1648 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1649 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1650 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1651 | goto out; |
| 1652 | |
| 1653 | if (*(args[2]) == 0) { |
| 1654 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1656 | goto out; |
| 1657 | } |
| 1658 | |
| 1659 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1660 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1661 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1663 | goto out; |
| 1664 | } |
| 1665 | } |
| 1666 | else if (!strcmp(args[0], "unsetenv")) { |
| 1667 | int arg; |
| 1668 | |
| 1669 | if (*(args[1]) == 0) { |
| 1670 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1672 | goto out; |
| 1673 | } |
| 1674 | |
| 1675 | for (arg = 1; *args[arg]; arg++) { |
| 1676 | if (unsetenv(args[arg]) != 0) { |
| 1677 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1679 | goto out; |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | else if (!strcmp(args[0], "resetenv")) { |
| 1684 | extern char **environ; |
| 1685 | char **env = environ; |
| 1686 | |
| 1687 | /* args contain variable names to keep, one per argument */ |
| 1688 | while (*env) { |
| 1689 | int arg; |
| 1690 | |
| 1691 | /* look for current variable in among all those we want to keep */ |
| 1692 | for (arg = 1; *args[arg]; arg++) { |
| 1693 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1694 | (*env)[strlen(args[arg])] == '=') |
| 1695 | break; |
| 1696 | } |
| 1697 | |
| 1698 | /* delete this variable */ |
| 1699 | if (!*args[arg]) { |
| 1700 | char *delim = strchr(*env, '='); |
| 1701 | |
| 1702 | if (!delim || delim - *env >= trash.size) { |
| 1703 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1705 | goto out; |
| 1706 | } |
| 1707 | |
| 1708 | memcpy(trash.str, *env, delim - *env); |
| 1709 | trash.str[delim - *env] = 0; |
| 1710 | |
| 1711 | if (unsetenv(trash.str) != 0) { |
| 1712 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1714 | goto out; |
| 1715 | } |
| 1716 | } |
| 1717 | else |
| 1718 | env++; |
| 1719 | } |
| 1720 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1721 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1722 | struct cfg_kw_list *kwl; |
| 1723 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1724 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1725 | |
| 1726 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1727 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1728 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1729 | continue; |
| 1730 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1731 | 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] | 1732 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1733 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1734 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1735 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1736 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1737 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1738 | err_code |= ERR_WARN; |
| 1739 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1740 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1741 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1746 | 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] | 1747 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1748 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1749 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1750 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1751 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1752 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1755 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1756 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1757 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1758 | defproxy.mode = PR_MODE_TCP; |
| 1759 | defproxy.state = PR_STNEW; |
| 1760 | defproxy.maxconn = cfg_maxpconn; |
| 1761 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1762 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1763 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1764 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1765 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1766 | defproxy.defsrv.check.fastinter = 0; |
| 1767 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1768 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1769 | defproxy.defsrv.agent.fastinter = 0; |
| 1770 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1771 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1772 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1773 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1774 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1775 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1776 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1777 | defproxy.defsrv.maxqueue = 0; |
| 1778 | defproxy.defsrv.minconn = 0; |
| 1779 | defproxy.defsrv.maxconn = 0; |
| 1780 | defproxy.defsrv.slowstart = 0; |
| 1781 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1782 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1783 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1784 | |
| 1785 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1786 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1789 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1790 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1791 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1792 | * ERR_FATAL in case of error. |
| 1793 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1794 | static int create_cond_regex_rule(const char *file, int line, |
| 1795 | struct proxy *px, int dir, int action, int flags, |
| 1796 | const char *cmd, const char *reg, const char *repl, |
| 1797 | const char **cond_start) |
| 1798 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1799 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1800 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1801 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1802 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1803 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1804 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1805 | int cs; |
| 1806 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1807 | |
| 1808 | if (px == &defproxy) { |
| 1809 | 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] | 1810 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1811 | goto err; |
| 1812 | } |
| 1813 | |
| 1814 | if (*reg == 0) { |
| 1815 | 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] | 1816 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1817 | goto err; |
| 1818 | } |
| 1819 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1820 | 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] | 1821 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1822 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1823 | if (cond_start && |
| 1824 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 1825 | if ((cond = build_acl_cond(file, line, &px->acl, px, cond_start, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1826 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1827 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1828 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1829 | goto err; |
| 1830 | } |
| 1831 | } |
| 1832 | else if (cond_start && **cond_start) { |
| 1833 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1834 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1835 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1836 | goto err; |
| 1837 | } |
| 1838 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1839 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1840 | (dir == SMP_OPT_DIR_REQ) ? |
| 1841 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1842 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1843 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1844 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1845 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1846 | if (!preg) { |
| 1847 | 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] | 1848 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1849 | goto err; |
| 1850 | } |
| 1851 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1852 | cs = !(flags & REG_ICASE); |
| 1853 | cap = !(flags & REG_NOSUB); |
| 1854 | error = NULL; |
| 1855 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1856 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1857 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1858 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1859 | goto err; |
| 1860 | } |
| 1861 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1862 | 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] | 1863 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1864 | if (repl && err) { |
| 1865 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1866 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1867 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1868 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1871 | 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] | 1872 | ret_code |= ERR_WARN; |
| 1873 | |
| 1874 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1875 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1876 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1877 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1878 | err: |
| 1879 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1880 | free(errmsg); |
| 1881 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1884 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1885 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1886 | * Returns the error code, 0 if OK, or any combination of : |
| 1887 | * - ERR_ABORT: must abort ASAP |
| 1888 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1889 | * - ERR_WARN: a warning has been emitted |
| 1890 | * - ERR_ALERT: an alert has been emitted |
| 1891 | * Only the two first ones can stop processing, the two others are just |
| 1892 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1893 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1894 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1895 | { |
| 1896 | static struct peers *curpeers = NULL; |
| 1897 | struct peer *newpeer = NULL; |
| 1898 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1899 | struct bind_conf *bind_conf; |
| 1900 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1901 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1902 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1903 | |
| 1904 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1905 | if (!*args[1]) { |
| 1906 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1907 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1908 | goto out; |
| 1909 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1910 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1911 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1912 | goto out; |
| 1913 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1914 | err = invalid_char(args[1]); |
| 1915 | if (err) { |
| 1916 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1917 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1918 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1919 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 1922 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1923 | /* |
| 1924 | * If there are two proxies with the same name only following |
| 1925 | * combinations are allowed: |
| 1926 | */ |
| 1927 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1928 | 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] | 1929 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1930 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1931 | } |
| 1932 | } |
| 1933 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1934 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1935 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1936 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1937 | goto out; |
| 1938 | } |
| 1939 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 1940 | curpeers->next = cfg_peers; |
| 1941 | cfg_peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1942 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1943 | curpeers->conf.line = linenum; |
| 1944 | curpeers->last_change = now.tv_sec; |
| 1945 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1946 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1947 | } |
| 1948 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1949 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1950 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1951 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1952 | |
| 1953 | if (!*args[2]) { |
| 1954 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1955 | file, linenum, args[0]); |
| 1956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1957 | goto out; |
| 1958 | } |
| 1959 | |
| 1960 | err = invalid_char(args[1]); |
| 1961 | if (err) { |
| 1962 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1963 | file, linenum, *err, args[1]); |
| 1964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1965 | goto out; |
| 1966 | } |
| 1967 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1968 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1969 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1970 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1971 | goto out; |
| 1972 | } |
| 1973 | |
| 1974 | /* the peers are linked backwards first */ |
| 1975 | curpeers->count++; |
| 1976 | newpeer->next = curpeers->remote; |
| 1977 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1978 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1979 | newpeer->conf.line = linenum; |
| 1980 | |
| 1981 | newpeer->last_change = now.tv_sec; |
| 1982 | newpeer->id = strdup(args[1]); |
| 1983 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1984 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1985 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1986 | 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] | 1987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1988 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1989 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1990 | |
| 1991 | proto = protocol_by_family(sk->ss_family); |
| 1992 | if (!proto || !proto->connect) { |
| 1993 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1994 | file, linenum, args[0], args[1]); |
| 1995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1996 | goto out; |
| 1997 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1998 | |
| 1999 | if (port1 != port2) { |
| 2000 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2001 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2003 | goto out; |
| 2004 | } |
| 2005 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2006 | if (!port1) { |
| 2007 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2008 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2010 | goto out; |
| 2011 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2012 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2013 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2014 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2015 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2016 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2017 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2018 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2019 | /* Current is local peer, it define a frontend */ |
| 2020 | newpeer->local = 1; |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2021 | cfg_peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2022 | |
| 2023 | if (!curpeers->peers_fe) { |
| 2024 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2025 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2026 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2027 | goto out; |
| 2028 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2029 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2030 | init_new_proxy(curpeers->peers_fe); |
| 2031 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2032 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2033 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2034 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2035 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2036 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2037 | 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] | 2038 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2039 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2040 | if (errmsg && *errmsg) { |
| 2041 | indent_msg(&errmsg, 2); |
| 2042 | 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] | 2043 | } |
| 2044 | else |
| 2045 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2046 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2047 | err_code |= ERR_FATAL; |
| 2048 | goto out; |
| 2049 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2050 | |
| 2051 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2052 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2053 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2054 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2055 | l->accept = session_accept_fd; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2056 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2057 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2058 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2059 | global.maxsock += l->maxconn; |
| 2060 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2061 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2062 | else { |
| 2063 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2064 | file, linenum, args[0], args[1], |
| 2065 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2066 | err_code |= ERR_FATAL; |
| 2067 | goto out; |
| 2068 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2069 | } |
| 2070 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2071 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2072 | curpeers->state = PR_STSTOPPED; |
| 2073 | } |
| 2074 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2075 | curpeers->state = PR_STNEW; |
| 2076 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2077 | else if (*args[0] != 0) { |
| 2078 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2080 | goto out; |
| 2081 | } |
| 2082 | |
| 2083 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2084 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2085 | return err_code; |
| 2086 | } |
| 2087 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2088 | /* |
| 2089 | * Parse a <resolvers> section. |
| 2090 | * Returns the error code, 0 if OK, or any combination of : |
| 2091 | * - ERR_ABORT: must abort ASAP |
| 2092 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2093 | * - ERR_WARN: a warning has been emitted |
| 2094 | * - ERR_ALERT: an alert has been emitted |
| 2095 | * Only the two first ones can stop processing, the two others are just |
| 2096 | * indicators. |
| 2097 | */ |
| 2098 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2099 | { |
| 2100 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2101 | struct dns_nameserver *newnameserver = NULL; |
| 2102 | const char *err; |
| 2103 | int err_code = 0; |
| 2104 | char *errmsg = NULL; |
| 2105 | |
| 2106 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2107 | if (!*args[1]) { |
| 2108 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2109 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2110 | goto out; |
| 2111 | } |
| 2112 | |
| 2113 | err = invalid_char(args[1]); |
| 2114 | if (err) { |
| 2115 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2116 | file, linenum, *err, args[0], args[1]); |
| 2117 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2118 | goto out; |
| 2119 | } |
| 2120 | |
| 2121 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2122 | /* Error if two resolvers owns the same name */ |
| 2123 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2124 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2125 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2126 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2127 | } |
| 2128 | } |
| 2129 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2130 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2131 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2132 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2133 | goto out; |
| 2134 | } |
| 2135 | |
| 2136 | /* default values */ |
| 2137 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2138 | curr_resolvers->conf.file = strdup(file); |
| 2139 | curr_resolvers->conf.line = linenum; |
| 2140 | curr_resolvers->id = strdup(args[1]); |
| 2141 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2142 | /* default maximum response size */ |
| 2143 | curr_resolvers->accepted_payload_size = 512; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2144 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2145 | curr_resolvers->hold.nx = 30000; |
| 2146 | curr_resolvers->hold.other = 30000; |
| 2147 | curr_resolvers->hold.refused = 30000; |
| 2148 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 686408b | 2017-08-18 10:15:42 +0200 | [diff] [blame] | 2149 | curr_resolvers->hold.obsolete = 0; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2150 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2151 | curr_resolvers->hold.valid = 10000; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2152 | curr_resolvers->timeout.resolve = 1000; |
| 2153 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2154 | curr_resolvers->resolve_retries = 3; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2155 | curr_resolvers->nb_nameservers = 0; |
| 2156 | LIST_INIT(&curr_resolvers->nameservers); |
| 2157 | LIST_INIT(&curr_resolvers->resolutions.curr); |
| 2158 | LIST_INIT(&curr_resolvers->resolutions.wait); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2159 | } |
| 2160 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2161 | struct sockaddr_storage *sk; |
| 2162 | int port1, port2; |
| 2163 | struct protocol *proto; |
| 2164 | |
| 2165 | if (!*args[2]) { |
| 2166 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2167 | file, linenum, args[0]); |
| 2168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2169 | goto out; |
| 2170 | } |
| 2171 | |
| 2172 | err = invalid_char(args[1]); |
| 2173 | if (err) { |
| 2174 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2175 | file, linenum, *err, args[1]); |
| 2176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2177 | goto out; |
| 2178 | } |
| 2179 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2180 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2181 | /* Error if two resolvers owns the same name */ |
| 2182 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2183 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2184 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2186 | } |
| 2187 | } |
| 2188 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2189 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2190 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2191 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2192 | goto out; |
| 2193 | } |
| 2194 | |
| 2195 | /* the nameservers are linked backward first */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2196 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2197 | newnameserver->resolvers = curr_resolvers; |
| 2198 | newnameserver->conf.file = strdup(file); |
| 2199 | newnameserver->conf.line = linenum; |
| 2200 | newnameserver->id = strdup(args[1]); |
| 2201 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2202 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2203 | if (!sk) { |
| 2204 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2206 | goto out; |
| 2207 | } |
| 2208 | |
| 2209 | proto = protocol_by_family(sk->ss_family); |
| 2210 | if (!proto || !proto->connect) { |
| 2211 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2212 | file, linenum, args[0], args[1]); |
| 2213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2214 | goto out; |
| 2215 | } |
| 2216 | |
| 2217 | if (port1 != port2) { |
| 2218 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2219 | file, linenum, args[0], args[1], args[2]); |
| 2220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2221 | goto out; |
| 2222 | } |
| 2223 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2224 | if (!port1 && !port2) { |
| 2225 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2226 | file, linenum, args[0], args[1]); |
| 2227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2228 | goto out; |
| 2229 | } |
| 2230 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2231 | newnameserver->addr = *sk; |
| 2232 | } |
| 2233 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2234 | const char *res; |
| 2235 | unsigned int time; |
| 2236 | |
| 2237 | if (!*args[2]) { |
| 2238 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2239 | file, linenum, args[0]); |
| 2240 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2242 | goto out; |
| 2243 | } |
| 2244 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2245 | if (res) { |
| 2246 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2247 | file, linenum, *res, args[0]); |
| 2248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2249 | goto out; |
| 2250 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2251 | if (strcmp(args[1], "nx") == 0) |
| 2252 | curr_resolvers->hold.nx = time; |
| 2253 | else if (strcmp(args[1], "other") == 0) |
| 2254 | curr_resolvers->hold.other = time; |
| 2255 | else if (strcmp(args[1], "refused") == 0) |
| 2256 | curr_resolvers->hold.refused = time; |
| 2257 | else if (strcmp(args[1], "timeout") == 0) |
| 2258 | curr_resolvers->hold.timeout = time; |
| 2259 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2260 | curr_resolvers->hold.valid = time; |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2261 | else if (strcmp(args[1], "obsolete") == 0) |
| 2262 | curr_resolvers->hold.obsolete = time; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2263 | else { |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2264 | 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] | 2265 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2267 | goto out; |
| 2268 | } |
| 2269 | |
| 2270 | } |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2271 | else if (strcmp(args[0], "accepted_payload_size") == 0) { |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2272 | int i = 0; |
| 2273 | |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2274 | if (!*args[1]) { |
| 2275 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2276 | file, linenum, args[0]); |
| 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2280 | |
| 2281 | i = atoi(args[1]); |
Willy Tarreau | 0c219be | 2017-08-22 12:01:26 +0200 | [diff] [blame] | 2282 | if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) { |
| 2283 | Alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n", |
| 2284 | 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] | 2285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2286 | goto out; |
| 2287 | } |
| 2288 | |
| 2289 | curr_resolvers->accepted_payload_size = i; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2290 | } |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2291 | else if (strcmp(args[0], "resolution_pool_size") == 0) { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2292 | Warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n", |
| 2293 | file, linenum, args[0]); |
| 2294 | err_code |= ERR_WARN; |
| 2295 | goto out; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2296 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2297 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2298 | if (!*args[1]) { |
| 2299 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2300 | file, linenum, args[0]); |
| 2301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2302 | goto out; |
| 2303 | } |
| 2304 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2305 | } |
| 2306 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2307 | if (!*args[1]) { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2308 | Alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n", |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2309 | file, linenum, args[0]); |
| 2310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2311 | goto out; |
| 2312 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2313 | else if (strcmp(args[1], "retry") == 0 || |
| 2314 | strcmp(args[1], "resolve") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2315 | const char *res; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2316 | unsigned int tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2317 | |
| 2318 | if (!*args[2]) { |
| 2319 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2320 | file, linenum, args[0], args[1]); |
| 2321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2322 | goto out; |
| 2323 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2324 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2325 | if (res) { |
| 2326 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2327 | file, linenum, *res, args[0], args[1]); |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto out; |
| 2330 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2331 | if (args[1][2] == 't') |
| 2332 | curr_resolvers->timeout.retry = tout; |
| 2333 | else |
| 2334 | curr_resolvers->timeout.resolve = tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2335 | } |
| 2336 | else { |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2337 | Alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n", |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2338 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2340 | goto out; |
| 2341 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2342 | } /* neither "nameserver" nor "resolvers" */ |
| 2343 | else if (*args[0] != 0) { |
| 2344 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2346 | goto out; |
| 2347 | } |
| 2348 | |
| 2349 | out: |
| 2350 | free(errmsg); |
| 2351 | return err_code; |
| 2352 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2353 | |
| 2354 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2355 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2356 | * Returns the error code, 0 if OK, or any combination of : |
| 2357 | * - ERR_ABORT: must abort ASAP |
| 2358 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2359 | * - ERR_WARN: a warning has been emitted |
| 2360 | * - ERR_ALERT: an alert has been emitted |
| 2361 | * Only the two first ones can stop processing, the two others are just |
| 2362 | * indicators. |
| 2363 | */ |
| 2364 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2365 | { |
| 2366 | static struct mailers *curmailers = NULL; |
| 2367 | struct mailer *newmailer = NULL; |
| 2368 | const char *err; |
| 2369 | int err_code = 0; |
| 2370 | char *errmsg = NULL; |
| 2371 | |
| 2372 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2373 | if (!*args[1]) { |
| 2374 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2375 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | |
| 2379 | err = invalid_char(args[1]); |
| 2380 | if (err) { |
| 2381 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2382 | file, linenum, *err, args[0], args[1]); |
| 2383 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | |
| 2387 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2388 | /* |
| 2389 | * If there are two proxies with the same name only following |
| 2390 | * combinations are allowed: |
| 2391 | */ |
| 2392 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2393 | 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] | 2394 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2395 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2399 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2400 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2401 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | |
| 2405 | curmailers->next = mailers; |
| 2406 | mailers = curmailers; |
| 2407 | curmailers->conf.file = strdup(file); |
| 2408 | curmailers->conf.line = linenum; |
| 2409 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2410 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2411 | * But need enough time so that timeouts don't occur |
| 2412 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2413 | } |
| 2414 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2415 | struct sockaddr_storage *sk; |
| 2416 | int port1, port2; |
| 2417 | struct protocol *proto; |
| 2418 | |
| 2419 | if (!*args[2]) { |
| 2420 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2421 | file, linenum, args[0]); |
| 2422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2423 | goto out; |
| 2424 | } |
| 2425 | |
| 2426 | err = invalid_char(args[1]); |
| 2427 | if (err) { |
| 2428 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2429 | file, linenum, *err, args[1]); |
| 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
| 2432 | } |
| 2433 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2434 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2435 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2436 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2437 | goto out; |
| 2438 | } |
| 2439 | |
| 2440 | /* the mailers are linked backwards first */ |
| 2441 | curmailers->count++; |
| 2442 | newmailer->next = curmailers->mailer_list; |
| 2443 | curmailers->mailer_list = newmailer; |
| 2444 | newmailer->mailers = curmailers; |
| 2445 | newmailer->conf.file = strdup(file); |
| 2446 | newmailer->conf.line = linenum; |
| 2447 | |
| 2448 | newmailer->id = strdup(args[1]); |
| 2449 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2450 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2451 | if (!sk) { |
| 2452 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2454 | goto out; |
| 2455 | } |
| 2456 | |
| 2457 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2458 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2459 | 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] | 2460 | file, linenum, args[0], args[1]); |
| 2461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2462 | goto out; |
| 2463 | } |
| 2464 | |
| 2465 | if (port1 != port2) { |
| 2466 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2467 | file, linenum, args[0], args[1], args[2]); |
| 2468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2469 | goto out; |
| 2470 | } |
| 2471 | |
| 2472 | if (!port1) { |
| 2473 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2474 | file, linenum, args[0], args[1], args[2]); |
| 2475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2476 | goto out; |
| 2477 | } |
| 2478 | |
| 2479 | newmailer->addr = *sk; |
| 2480 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2481 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2482 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2483 | } |
| 2484 | else if (strcmp(args[0], "timeout") == 0) { |
| 2485 | if (!*args[1]) { |
| 2486 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2487 | file, linenum, args[0]); |
| 2488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2489 | goto out; |
| 2490 | } |
| 2491 | else if (strcmp(args[1], "mail") == 0) { |
| 2492 | const char *res; |
| 2493 | unsigned int timeout_mail; |
| 2494 | if (!*args[2]) { |
| 2495 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2496 | file, linenum, args[0], args[1]); |
| 2497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2498 | goto out; |
| 2499 | } |
| 2500 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2501 | if (res) { |
| 2502 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2503 | file, linenum, *res, args[0]); |
| 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
| 2506 | } |
| 2507 | if (timeout_mail <= 0) { |
| 2508 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2510 | goto out; |
| 2511 | } |
| 2512 | curmailers->timeout.mail = timeout_mail; |
| 2513 | } else { |
| 2514 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2515 | file, linenum, args[0], args[1]); |
| 2516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2517 | goto out; |
| 2518 | } |
| 2519 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2520 | else if (*args[0] != 0) { |
| 2521 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2523 | goto out; |
| 2524 | } |
| 2525 | |
| 2526 | out: |
| 2527 | free(errmsg); |
| 2528 | return err_code; |
| 2529 | } |
| 2530 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2531 | static void free_email_alert(struct proxy *p) |
| 2532 | { |
| 2533 | free(p->email_alert.mailers.name); |
| 2534 | p->email_alert.mailers.name = NULL; |
| 2535 | free(p->email_alert.from); |
| 2536 | p->email_alert.from = NULL; |
| 2537 | free(p->email_alert.to); |
| 2538 | p->email_alert.to = NULL; |
| 2539 | free(p->email_alert.myhostname); |
| 2540 | p->email_alert.myhostname = NULL; |
| 2541 | } |
| 2542 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2543 | 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] | 2544 | { |
| 2545 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2546 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2547 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2548 | int rc; |
| 2549 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2550 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2551 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2552 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2553 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2554 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2555 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2556 | if (!strcmp(args[0], "listen")) |
| 2557 | rc = PR_CAP_LISTEN; |
| 2558 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2559 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2560 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2561 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2562 | else |
| 2563 | rc = PR_CAP_NONE; |
| 2564 | |
| 2565 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2566 | if (!*args[1]) { |
| 2567 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2568 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2569 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2570 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2571 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2572 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2573 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2574 | err = invalid_char(args[1]); |
| 2575 | if (err) { |
| 2576 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2577 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2578 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2579 | } |
| 2580 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2581 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2582 | if (curproxy) { |
| 2583 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2584 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2585 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2586 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2589 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2590 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2591 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2592 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2593 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2594 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2595 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2596 | curproxy->next = proxy; |
| 2597 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2598 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2599 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2600 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2601 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2602 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2603 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2604 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2605 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2606 | if (curproxy->cap & PR_CAP_FE) |
| 2607 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2612 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2613 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2614 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2615 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2616 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2617 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2618 | curproxy->no_options = defproxy.no_options; |
| 2619 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2620 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2621 | curproxy->except_net = defproxy.except_net; |
| 2622 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2623 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2624 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2625 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2626 | if (defproxy.fwdfor_hdr_len) { |
| 2627 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2628 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2629 | } |
| 2630 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2631 | if (defproxy.orgto_hdr_len) { |
| 2632 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2633 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2634 | } |
| 2635 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2636 | if (defproxy.server_id_hdr_len) { |
| 2637 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2638 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2639 | } |
| 2640 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2641 | if (curproxy->cap & PR_CAP_FE) { |
| 2642 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2643 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2644 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2645 | |
| 2646 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2647 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2648 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2649 | |
| 2650 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2651 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2652 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2653 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2654 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2655 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2656 | curproxy->fullconn = defproxy.fullconn; |
| 2657 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2658 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2659 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2660 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2661 | if (defproxy.check_req) { |
| 2662 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2663 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2664 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2665 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2666 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2667 | if (defproxy.expect_str) { |
| 2668 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2669 | if (defproxy.expect_regex) { |
| 2670 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2671 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2672 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2673 | } |
| 2674 | } |
| 2675 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2676 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2677 | if (defproxy.cookie_name) |
| 2678 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2679 | curproxy->cookie_len = defproxy.cookie_len; |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2680 | |
| 2681 | if (defproxy.dyncookie_key) |
| 2682 | curproxy->dyncookie_key = strdup(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2683 | if (defproxy.cookie_domain) |
| 2684 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2685 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2686 | if (defproxy.cookie_maxidle) |
| 2687 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2688 | |
| 2689 | if (defproxy.cookie_maxlife) |
| 2690 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2691 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2692 | if (defproxy.rdp_cookie_name) |
| 2693 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2694 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2695 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2696 | if (defproxy.url_param_name) |
| 2697 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2698 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2699 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2700 | if (defproxy.hh_name) |
| 2701 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2702 | curproxy->hh_len = defproxy.hh_len; |
| 2703 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2704 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2705 | if (defproxy.conn_src.iface_name) |
| 2706 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2707 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2708 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2709 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2710 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2711 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2712 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2713 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2714 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2715 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2716 | if (defproxy.capture_name) |
| 2717 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2718 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2719 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2720 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2721 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2722 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2723 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2724 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2725 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2726 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2727 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2728 | curproxy->mon_net = defproxy.mon_net; |
| 2729 | curproxy->mon_mask = defproxy.mon_mask; |
| 2730 | if (defproxy.monitor_uri) |
| 2731 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2732 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2733 | if (defproxy.defbe.name) |
| 2734 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2735 | |
| 2736 | /* 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] | 2737 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2738 | if (curproxy->conf.logformat_string && |
| 2739 | curproxy->conf.logformat_string != default_http_log_format && |
| 2740 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2741 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2742 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2743 | |
| 2744 | if (defproxy.conf.lfs_file) { |
| 2745 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2746 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2747 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2748 | |
| 2749 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2750 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2751 | if (curproxy->conf.logformat_sd_string && |
| 2752 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2753 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2754 | |
| 2755 | if (defproxy.conf.lfsd_file) { |
| 2756 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2757 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2758 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2762 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2763 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2764 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2765 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2766 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2767 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2768 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2769 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2770 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2771 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2772 | } |
| 2773 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2774 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2775 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2776 | |
| 2777 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2778 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2779 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2780 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2781 | LIST_INIT(&node->list); |
| 2782 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2783 | } |
| 2784 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2785 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2786 | if (curproxy->conf.uniqueid_format_string) |
| 2787 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2788 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2789 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2790 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2791 | if (defproxy.conf.uif_file) { |
| 2792 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2793 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2794 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2795 | |
| 2796 | /* copy default header unique id */ |
| 2797 | if (defproxy.header_unique_id) |
| 2798 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2799 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2800 | /* default compression options */ |
| 2801 | if (defproxy.comp != NULL) { |
| 2802 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2803 | curproxy->comp->algos = defproxy.comp->algos; |
| 2804 | curproxy->comp->types = defproxy.comp->types; |
| 2805 | } |
| 2806 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2807 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2808 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2809 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2810 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2811 | if (defproxy.check_path) |
| 2812 | curproxy->check_path = strdup(defproxy.check_path); |
| 2813 | if (defproxy.check_command) |
| 2814 | curproxy->check_command = strdup(defproxy.check_command); |
| 2815 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2816 | if (defproxy.email_alert.mailers.name) |
| 2817 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 2818 | if (defproxy.email_alert.from) |
| 2819 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 2820 | if (defproxy.email_alert.to) |
| 2821 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 2822 | if (defproxy.email_alert.myhostname) |
| 2823 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2824 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 2825 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2826 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2827 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2828 | } |
| 2829 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2830 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2831 | /* FIXME-20070101: we should do this too at the end of the |
| 2832 | * config parsing to free all default values. |
| 2833 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2834 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2835 | err_code |= ERR_ABORT; |
| 2836 | goto out; |
| 2837 | } |
| 2838 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2839 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2840 | free(defproxy.check_command); |
| 2841 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2842 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2843 | free(defproxy.rdp_cookie_name); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2844 | free(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2845 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2846 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2847 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2848 | free(defproxy.capture_name); |
| 2849 | free(defproxy.monitor_uri); |
| 2850 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2851 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2852 | free(defproxy.fwdfor_hdr_name); |
| 2853 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2854 | free(defproxy.orgto_hdr_name); |
| 2855 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2856 | free(defproxy.server_id_hdr_name); |
| 2857 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2858 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2859 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2860 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2861 | free(defproxy.expect_regex); |
| 2862 | defproxy.expect_regex = NULL; |
| 2863 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2864 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2865 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2866 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2867 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2868 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2869 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2870 | free(defproxy.conf.uniqueid_format_string); |
| 2871 | free(defproxy.conf.lfs_file); |
| 2872 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2873 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2874 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2875 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2876 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2877 | free(defproxy.conf.logformat_sd_string); |
| 2878 | free(defproxy.conf.lfsd_file); |
| 2879 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2880 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2881 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2882 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2883 | /* we cannot free uri_auth because it might already be used */ |
| 2884 | init_default_instance(); |
| 2885 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2886 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2887 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2888 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2889 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2890 | } |
| 2891 | else if (curproxy == NULL) { |
| 2892 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2894 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2895 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2896 | |
| 2897 | /* update the current file and line being parsed */ |
| 2898 | curproxy->conf.args.file = curproxy->conf.file; |
| 2899 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2900 | |
| 2901 | /* Now let's parse the proxy-specific keywords */ |
Frédéric Lécaille | b82f742 | 2017-04-13 18:24:23 +0200 | [diff] [blame] | 2902 | if (!strcmp(args[0], "server") || |
| 2903 | !strcmp(args[0], "default-server") || |
| 2904 | !strcmp(args[0], "server-template")) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2905 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2906 | if (err_code & ERR_FATAL) |
| 2907 | goto out; |
| 2908 | } |
| 2909 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2910 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2911 | int cur_arg; |
| 2912 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2913 | if (curproxy == &defproxy) { |
| 2914 | 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] | 2915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2916 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2917 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2918 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2919 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2920 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2921 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2922 | 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] | 2923 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2926 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2927 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2928 | 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] | 2929 | |
| 2930 | /* use default settings for unix sockets */ |
| 2931 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2932 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2933 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2934 | |
| 2935 | /* NOTE: the following line might create several listeners if there |
| 2936 | * are comma-separated IPs or port ranges. So all further processing |
| 2937 | * will have to be applied to all listeners created after last_listen. |
| 2938 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2939 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2940 | if (errmsg && *errmsg) { |
| 2941 | indent_msg(&errmsg, 2); |
| 2942 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2943 | } |
| 2944 | else |
| 2945 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2946 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2948 | goto out; |
| 2949 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2950 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2951 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2952 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2953 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2954 | } |
| 2955 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2956 | cur_arg = 2; |
| 2957 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2958 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2959 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2960 | char *err; |
| 2961 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2962 | kw = bind_find_kw(args[cur_arg]); |
| 2963 | if (kw) { |
| 2964 | char *err = NULL; |
| 2965 | int code; |
| 2966 | |
| 2967 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2968 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2969 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2970 | cur_arg += 1 + kw->skip ; |
| 2971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2972 | goto out; |
| 2973 | } |
| 2974 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2975 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2976 | err_code |= code; |
| 2977 | |
| 2978 | if (code) { |
| 2979 | if (err && *err) { |
| 2980 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2981 | 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] | 2982 | } |
| 2983 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2984 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2985 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2986 | if (code & ERR_FATAL) { |
| 2987 | free(err); |
| 2988 | cur_arg += 1 + kw->skip; |
| 2989 | goto out; |
| 2990 | } |
| 2991 | } |
| 2992 | free(err); |
| 2993 | cur_arg += 1 + kw->skip; |
| 2994 | continue; |
| 2995 | } |
| 2996 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2997 | err = NULL; |
| 2998 | if (!bind_dumped) { |
| 2999 | bind_dump_kws(&err); |
| 3000 | indent_msg(&err, 4); |
| 3001 | bind_dumped = 1; |
| 3002 | } |
| 3003 | |
| 3004 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3005 | file, linenum, args[0], args[1], args[cur_arg], |
| 3006 | err ? " Registered keywords :" : "", err ? err : ""); |
| 3007 | free(err); |
| 3008 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3010 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3011 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3013 | } |
| 3014 | 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] | 3015 | 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] | 3016 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3017 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3019 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3020 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3021 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3022 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3023 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3024 | /* flush useless bits */ |
| 3025 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3026 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3027 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3028 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3029 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3030 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3031 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3032 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3033 | goto out; |
| 3034 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3035 | if (!*args[1]) { |
| 3036 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3037 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3039 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3040 | } |
| 3041 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3042 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3043 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3044 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3045 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3046 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3047 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3048 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3049 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3050 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3051 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3052 | goto out; |
| 3053 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3054 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3055 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3056 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3057 | else { |
| 3058 | 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] | 3059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3060 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3061 | } |
| 3062 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3063 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3064 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3065 | |
| 3066 | if (curproxy == &defproxy) { |
| 3067 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3068 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3070 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3071 | } |
| 3072 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3073 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3074 | goto out; |
| 3075 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3076 | if (!*args[1]) { |
| 3077 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3078 | file, linenum, args[0]); |
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 | |
| 3083 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3084 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3085 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3086 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3087 | if (curproxy->uuid <= 0) { |
| 3088 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3089 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3091 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3094 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3095 | if (node) { |
| 3096 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3097 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3098 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3099 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3101 | goto out; |
| 3102 | } |
| 3103 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3104 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3105 | else if (!strcmp(args[0], "description")) { |
| 3106 | int i, len=0; |
| 3107 | char *d; |
| 3108 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3109 | if (curproxy == &defproxy) { |
| 3110 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3111 | file, linenum, args[0]); |
| 3112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3113 | goto out; |
| 3114 | } |
| 3115 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3116 | if (!*args[1]) { |
| 3117 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3118 | file, linenum, args[0]); |
| 3119 | return -1; |
| 3120 | } |
| 3121 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3122 | for (i = 1; *args[i]; i++) |
| 3123 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3124 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3125 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3126 | curproxy->desc = d; |
| 3127 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3128 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3129 | for (i = 2; *args[i]; i++) |
| 3130 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3131 | |
| 3132 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3133 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3134 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3135 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3136 | curproxy->state = PR_STSTOPPED; |
| 3137 | } |
| 3138 | 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] | 3139 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3140 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3141 | curproxy->state = PR_STNEW; |
| 3142 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3143 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3144 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3145 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3146 | |
| 3147 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3148 | unsigned int low, high; |
| 3149 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3150 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3151 | set = 0; |
| 3152 | break; |
| 3153 | } |
| 3154 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3155 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3156 | } |
| 3157 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3158 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3159 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3160 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3161 | char *dash = strchr(args[cur_arg], '-'); |
| 3162 | |
| 3163 | low = high = str2uic(args[cur_arg]); |
| 3164 | if (dash) |
| 3165 | high = str2uic(dash + 1); |
| 3166 | |
| 3167 | if (high < low) { |
| 3168 | unsigned int swap = low; |
| 3169 | low = high; |
| 3170 | high = swap; |
| 3171 | } |
| 3172 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3173 | if (low < 1 || high > LONGBITS) { |
| 3174 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3175 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3177 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3178 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3179 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3180 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3181 | } |
| 3182 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3183 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3184 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3185 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3186 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3187 | } |
| 3188 | cur_arg++; |
| 3189 | } |
| 3190 | curproxy->bind_proc = set; |
| 3191 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3192 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3193 | if (curproxy == &defproxy) { |
| 3194 | 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] | 3195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3196 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3197 | } |
| 3198 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3199 | err = invalid_char(args[1]); |
| 3200 | if (err) { |
| 3201 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3202 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3203 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1822e8c | 2017-04-12 18:54:00 +0200 | [diff] [blame] | 3204 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3205 | } |
| 3206 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3207 | 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] | 3208 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3209 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3211 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3212 | } |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3213 | } |
| 3214 | else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */ |
| 3215 | |
| 3216 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3217 | err_code |= ERR_WARN; |
| 3218 | |
| 3219 | if (*(args[1]) == 0) { |
| 3220 | Alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 3221 | file, linenum, args[0]); |
| 3222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3223 | goto out; |
| 3224 | } |
| 3225 | free(curproxy->dyncookie_key); |
| 3226 | curproxy->dyncookie_key = strdup(args[1]); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3227 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3228 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3229 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3230 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3231 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3232 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3233 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3234 | if (*(args[1]) == 0) { |
| 3235 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3236 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3238 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3239 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3240 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3241 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3242 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3243 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3244 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3245 | curproxy->cookie_name = strdup(args[1]); |
| 3246 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3247 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3248 | cur_arg = 2; |
| 3249 | while (*(args[cur_arg])) { |
| 3250 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3251 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3252 | } |
| 3253 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3254 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3255 | } |
| 3256 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3257 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3258 | } |
| 3259 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3260 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3261 | } |
| 3262 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3263 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3264 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3265 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3266 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3267 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3268 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3269 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3270 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3271 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3272 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3273 | } |
| 3274 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3275 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3276 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3277 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3278 | if (!*args[cur_arg + 1]) { |
| 3279 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3280 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3283 | } |
| 3284 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3285 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3286 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3287 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3288 | " dots nor does not start with a dot." |
| 3289 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3290 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3291 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3295 | if (err) { |
| 3296 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3297 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3299 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3300 | } |
| 3301 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3302 | if (!curproxy->cookie_domain) { |
| 3303 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3304 | } else { |
| 3305 | /* one domain was already specified, add another one by |
| 3306 | * building the string which will be returned along with |
| 3307 | * the cookie. |
| 3308 | */ |
| 3309 | char *new_ptr; |
| 3310 | int new_len = strlen(curproxy->cookie_domain) + |
| 3311 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3312 | new_ptr = malloc(new_len); |
| 3313 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3314 | free(curproxy->cookie_domain); |
| 3315 | curproxy->cookie_domain = new_ptr; |
| 3316 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3317 | cur_arg++; |
| 3318 | } |
| 3319 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3320 | unsigned int maxidle; |
| 3321 | const char *res; |
| 3322 | |
| 3323 | if (!*args[cur_arg + 1]) { |
| 3324 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3325 | file, linenum, args[cur_arg]); |
| 3326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3327 | goto out; |
| 3328 | } |
| 3329 | |
| 3330 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3331 | if (res) { |
| 3332 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3333 | file, linenum, *res, args[cur_arg]); |
| 3334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3335 | goto out; |
| 3336 | } |
| 3337 | curproxy->cookie_maxidle = maxidle; |
| 3338 | cur_arg++; |
| 3339 | } |
| 3340 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3341 | unsigned int maxlife; |
| 3342 | const char *res; |
| 3343 | |
| 3344 | if (!*args[cur_arg + 1]) { |
| 3345 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3346 | file, linenum, args[cur_arg]); |
| 3347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3348 | goto out; |
| 3349 | } |
| 3350 | |
| 3351 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3352 | if (res) { |
| 3353 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3354 | file, linenum, *res, args[cur_arg]); |
| 3355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3356 | goto out; |
| 3357 | } |
| 3358 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3359 | cur_arg++; |
| 3360 | } |
Olivier Houchard | a5938f7 | 2017-03-15 15:12:06 +0100 | [diff] [blame] | 3361 | else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */ |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3362 | |
| 3363 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 3364 | err_code |= ERR_WARN; |
| 3365 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 3366 | } |
| 3367 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3368 | else { |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3369 | 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] | 3370 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3372 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3373 | } |
| 3374 | cur_arg++; |
| 3375 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3376 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3377 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3378 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3379 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3380 | } |
| 3381 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3382 | 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] | 3383 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3384 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3385 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3386 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3387 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3388 | 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] | 3389 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3390 | file, linenum); |
| 3391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3392 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3393 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3394 | else if (!strcmp(args[0], "email-alert")) { |
| 3395 | if (*(args[1]) == 0) { |
| 3396 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3397 | file, linenum, args[0]); |
| 3398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3399 | goto out; |
| 3400 | } |
| 3401 | |
| 3402 | if (!strcmp(args[1], "from")) { |
| 3403 | if (*(args[1]) == 0) { |
| 3404 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3405 | file, linenum, args[1]); |
| 3406 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3407 | goto out; |
| 3408 | } |
| 3409 | free(curproxy->email_alert.from); |
| 3410 | curproxy->email_alert.from = strdup(args[2]); |
| 3411 | } |
| 3412 | else if (!strcmp(args[1], "mailers")) { |
| 3413 | if (*(args[1]) == 0) { |
| 3414 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3415 | file, linenum, args[1]); |
| 3416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3417 | goto out; |
| 3418 | } |
| 3419 | free(curproxy->email_alert.mailers.name); |
| 3420 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3421 | } |
| 3422 | else if (!strcmp(args[1], "myhostname")) { |
| 3423 | if (*(args[1]) == 0) { |
| 3424 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3425 | file, linenum, args[1]); |
| 3426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3427 | goto out; |
| 3428 | } |
| 3429 | free(curproxy->email_alert.myhostname); |
| 3430 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3431 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3432 | else if (!strcmp(args[1], "level")) { |
| 3433 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3434 | if (curproxy->email_alert.level < 0) { |
| 3435 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3436 | file, linenum, args[1], args[2]); |
| 3437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3438 | goto out; |
| 3439 | } |
| 3440 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3441 | else if (!strcmp(args[1], "to")) { |
| 3442 | if (*(args[1]) == 0) { |
| 3443 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3444 | file, linenum, args[1]); |
| 3445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3446 | goto out; |
| 3447 | } |
| 3448 | free(curproxy->email_alert.to); |
| 3449 | curproxy->email_alert.to = strdup(args[2]); |
| 3450 | } |
| 3451 | else { |
| 3452 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3453 | file, linenum, args[1]); |
| 3454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3455 | goto out; |
| 3456 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3457 | /* Indicate that the email_alert is at least partially configured */ |
| 3458 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3459 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3460 | else if (!strcmp(args[0], "external-check")) { |
| 3461 | if (*(args[1]) == 0) { |
| 3462 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3463 | file, linenum, args[0]); |
| 3464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3465 | goto out; |
| 3466 | } |
| 3467 | |
| 3468 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3469 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3470 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3471 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3472 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3473 | file, linenum, args[1]); |
| 3474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3475 | goto out; |
| 3476 | } |
| 3477 | free(curproxy->check_command); |
| 3478 | curproxy->check_command = strdup(args[2]); |
| 3479 | } |
| 3480 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3481 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3482 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3483 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3484 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3485 | file, linenum, args[1]); |
| 3486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3487 | goto out; |
| 3488 | } |
| 3489 | free(curproxy->check_path); |
| 3490 | curproxy->check_path = strdup(args[2]); |
| 3491 | } |
| 3492 | else { |
| 3493 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3494 | file, linenum, args[1]); |
| 3495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3496 | goto out; |
| 3497 | } |
| 3498 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3499 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3500 | if (*(args[1]) == 0) { |
| 3501 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3502 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3504 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3508 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3509 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3510 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3511 | const char *beg, *end; |
| 3512 | |
| 3513 | beg = args[1] + 11; |
| 3514 | end = strchr(beg, ')'); |
| 3515 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3516 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3517 | goto out; |
| 3518 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3519 | if (!end || end == beg) { |
| 3520 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3521 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3523 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | free(curproxy->rdp_cookie_name); |
| 3527 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3528 | curproxy->rdp_cookie_len = end-beg; |
| 3529 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3530 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3531 | free(curproxy->rdp_cookie_name); |
| 3532 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3533 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3534 | } |
| 3535 | else { /* syntax */ |
| 3536 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3537 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3539 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3540 | } |
| 3541 | } |
| 3542 | else { |
| 3543 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3544 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3546 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3547 | } |
| 3548 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3549 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3550 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3552 | goto out; |
| 3553 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3554 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3555 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3556 | err_code |= ERR_WARN; |
| 3557 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3558 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3559 | } |
| 3560 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3561 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3562 | } |
| 3563 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3564 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3565 | } |
| 3566 | else { |
| 3567 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3568 | file, linenum, args[0], args[1]); |
| 3569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3570 | goto out; |
| 3571 | } |
| 3572 | } |
| 3573 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3574 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3575 | err_code |= ERR_WARN; |
| 3576 | if (*(args[1]) == 0) { |
| 3577 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3578 | file, linenum, args[0]); |
| 3579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3580 | goto out; |
| 3581 | } |
| 3582 | else if (!strcmp(args[1], "use-backend-name")) |
| 3583 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3584 | else |
| 3585 | curproxy->server_state_file_name = strdup(args[1]); |
| 3586 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3587 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3588 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3589 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3590 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3591 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3592 | if (curproxy == &defproxy) { |
| 3593 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3595 | goto out; |
| 3596 | } |
| 3597 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3598 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3599 | goto out; |
| 3600 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3601 | if (*(args[4]) == 0) { |
| 3602 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3603 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3605 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3606 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3607 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3608 | curproxy->capture_name = strdup(args[2]); |
| 3609 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3610 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3611 | curproxy->to_log |= LW_COOKIE; |
| 3612 | } |
| 3613 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3614 | struct cap_hdr *hdr; |
| 3615 | |
| 3616 | if (curproxy == &defproxy) { |
| 3617 | 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] | 3618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3619 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3620 | } |
| 3621 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3622 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3623 | goto out; |
| 3624 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3625 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3626 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3627 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3629 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3630 | } |
| 3631 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3632 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3633 | hdr->next = curproxy->req_cap; |
| 3634 | hdr->name = strdup(args[3]); |
| 3635 | hdr->namelen = strlen(args[3]); |
| 3636 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3637 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3638 | hdr->index = curproxy->nb_req_cap++; |
| 3639 | curproxy->req_cap = hdr; |
| 3640 | curproxy->to_log |= LW_REQHDR; |
| 3641 | } |
| 3642 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3643 | struct cap_hdr *hdr; |
| 3644 | |
| 3645 | if (curproxy == &defproxy) { |
| 3646 | 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] | 3647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3648 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3649 | } |
| 3650 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3651 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3652 | goto out; |
| 3653 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3654 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3655 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3656 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3658 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3659 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3660 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3661 | hdr->next = curproxy->rsp_cap; |
| 3662 | hdr->name = strdup(args[3]); |
| 3663 | hdr->namelen = strlen(args[3]); |
| 3664 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3665 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3666 | hdr->index = curproxy->nb_rsp_cap++; |
| 3667 | curproxy->rsp_cap = hdr; |
| 3668 | curproxy->to_log |= LW_RSPHDR; |
| 3669 | } |
| 3670 | else { |
| 3671 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3672 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3673 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3674 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3675 | } |
| 3676 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3677 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3678 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3679 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3680 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3681 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3682 | goto out; |
| 3683 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3684 | if (*(args[1]) == 0) { |
| 3685 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3686 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3688 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3689 | } |
| 3690 | curproxy->conn_retries = atol(args[1]); |
| 3691 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3692 | 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] | 3693 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3694 | |
| 3695 | if (curproxy == &defproxy) { |
| 3696 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3698 | goto out; |
| 3699 | } |
| 3700 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3701 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3702 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3703 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3704 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3705 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3706 | 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] | 3707 | 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] | 3708 | file, linenum, args[0]); |
| 3709 | err_code |= ERR_WARN; |
| 3710 | } |
| 3711 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3712 | 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] | 3713 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3714 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3715 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3716 | goto out; |
| 3717 | } |
| 3718 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3719 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3720 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3721 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3722 | file, linenum); |
| 3723 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3724 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3725 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3726 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3727 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3728 | |
| 3729 | if (curproxy == &defproxy) { |
| 3730 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3731 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3732 | goto out; |
| 3733 | } |
| 3734 | |
| 3735 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3736 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3737 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3738 | 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] | 3739 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3740 | file, linenum, args[0]); |
| 3741 | err_code |= ERR_WARN; |
| 3742 | } |
| 3743 | |
| 3744 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3745 | |
| 3746 | if (!rule) { |
| 3747 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3748 | goto out; |
| 3749 | } |
| 3750 | |
| 3751 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3752 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3753 | file, linenum); |
| 3754 | |
| 3755 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3756 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3757 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3758 | /* set the header name and length into the proxy structure */ |
| 3759 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3760 | err_code |= ERR_WARN; |
| 3761 | |
| 3762 | if (!*args[1]) { |
| 3763 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3764 | file, linenum, args[0]); |
| 3765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3766 | goto out; |
| 3767 | } |
| 3768 | |
| 3769 | /* set the desired header name */ |
| 3770 | free(curproxy->server_id_hdr_name); |
| 3771 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3772 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3773 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3774 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3775 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3776 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3777 | if (curproxy == &defproxy) { |
| 3778 | 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] | 3779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3780 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3781 | } |
| 3782 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3783 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3784 | * be processed before all http-request rules, we put them into their own list |
| 3785 | * and will insert them at the end. |
| 3786 | */ |
| 3787 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3788 | if (!rule) { |
| 3789 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3790 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3791 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3792 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3793 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3794 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3795 | file, linenum); |
| 3796 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3797 | |
| 3798 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3799 | 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]); |
| 3800 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3801 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3802 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3803 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3804 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3805 | if (curproxy == &defproxy) { |
| 3806 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3808 | goto out; |
| 3809 | } |
| 3810 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3811 | 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] | 3812 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3813 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3815 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3816 | } |
| 3817 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3818 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3819 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3820 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3821 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3822 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3823 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3824 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3825 | struct switching_rule *rule; |
| 3826 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3827 | if (curproxy == &defproxy) { |
| 3828 | 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] | 3829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3830 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3831 | } |
| 3832 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3833 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3834 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3835 | |
| 3836 | if (*(args[1]) == 0) { |
| 3837 | 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] | 3838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3839 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3840 | } |
| 3841 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3842 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 3843 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3844 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3845 | file, linenum, errmsg); |
| 3846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3847 | goto out; |
| 3848 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3849 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3850 | 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] | 3851 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 3852 | else if (*args[2]) { |
| 3853 | Alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 3854 | file, linenum, args[2]); |
| 3855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3856 | goto out; |
| 3857 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3858 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3859 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 3860 | if (!rule) { |
| 3861 | Alert("Out of memory error.\n"); |
| 3862 | goto out; |
| 3863 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3864 | rule->cond = cond; |
| 3865 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 3866 | rule->line = linenum; |
| 3867 | rule->file = strdup(file); |
| 3868 | if (!rule->file) { |
| 3869 | Alert("Out of memory error.\n"); |
| 3870 | goto out; |
| 3871 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3872 | LIST_INIT(&rule->list); |
| 3873 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3874 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3875 | else if (strcmp(args[0], "use-server") == 0) { |
| 3876 | struct server_rule *rule; |
| 3877 | |
| 3878 | if (curproxy == &defproxy) { |
| 3879 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3881 | goto out; |
| 3882 | } |
| 3883 | |
| 3884 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3885 | err_code |= ERR_WARN; |
| 3886 | |
| 3887 | if (*(args[1]) == 0) { |
| 3888 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3890 | goto out; |
| 3891 | } |
| 3892 | |
| 3893 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3894 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3895 | file, linenum, args[0]); |
| 3896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3897 | goto out; |
| 3898 | } |
| 3899 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 3900 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3901 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3902 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3904 | goto out; |
| 3905 | } |
| 3906 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3907 | 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] | 3908 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3909 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3910 | rule->cond = cond; |
| 3911 | rule->srv.name = strdup(args[1]); |
| 3912 | LIST_INIT(&rule->list); |
| 3913 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3914 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3915 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3916 | else if ((!strcmp(args[0], "force-persist")) || |
| 3917 | (!strcmp(args[0], "ignore-persist"))) { |
| 3918 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3919 | |
| 3920 | if (curproxy == &defproxy) { |
| 3921 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3923 | goto out; |
| 3924 | } |
| 3925 | |
| 3926 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3927 | err_code |= ERR_WARN; |
| 3928 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3929 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3930 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3931 | file, linenum, args[0]); |
| 3932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3933 | goto out; |
| 3934 | } |
| 3935 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 3936 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3937 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3938 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
| 3941 | } |
| 3942 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3943 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3944 | * where force-persist is applied. |
| 3945 | */ |
| 3946 | 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] | 3947 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3948 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3949 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3950 | if (!strcmp(args[0], "force-persist")) { |
| 3951 | rule->type = PERSIST_TYPE_FORCE; |
| 3952 | } else { |
| 3953 | rule->type = PERSIST_TYPE_IGNORE; |
| 3954 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3955 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3956 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3957 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3958 | else if (!strcmp(args[0], "stick-table")) { |
| 3959 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3960 | struct proxy *other; |
| 3961 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 3962 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3963 | if (other) { |
| 3964 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 3965 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 3966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3967 | goto out; |
| 3968 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3969 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3970 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3971 | curproxy->table.type = (unsigned int)-1; |
| 3972 | while (*args[myidx]) { |
| 3973 | const char *err; |
| 3974 | |
| 3975 | if (strcmp(args[myidx], "size") == 0) { |
| 3976 | myidx++; |
| 3977 | if (!*(args[myidx])) { |
| 3978 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3979 | file, linenum, args[myidx-1]); |
| 3980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3981 | goto out; |
| 3982 | } |
| 3983 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3984 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3985 | file, linenum, *err, args[myidx-1]); |
| 3986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3987 | goto out; |
| 3988 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3989 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3990 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3991 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3992 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3993 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3994 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3995 | file, linenum, args[myidx-1]); |
| 3996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3997 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3998 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3999 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4000 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4001 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4002 | myidx++; |
| 4003 | if (!*(args[myidx])) { |
| 4004 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4005 | file, linenum, args[myidx-1]); |
| 4006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4007 | goto out; |
| 4008 | } |
| 4009 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4010 | if (err) { |
| 4011 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4012 | file, linenum, *err, args[myidx-1]); |
| 4013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4014 | goto out; |
| 4015 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4016 | if (val > INT_MAX) { |
| 4017 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4018 | file, linenum, val); |
| 4019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4020 | goto out; |
| 4021 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4022 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4023 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4024 | } |
| 4025 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4026 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4027 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4028 | } |
| 4029 | else if (strcmp(args[myidx], "type") == 0) { |
| 4030 | myidx++; |
| 4031 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4032 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4033 | file, linenum, args[myidx]); |
| 4034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4035 | goto out; |
| 4036 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4037 | /* myidx already points to next arg */ |
| 4038 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4039 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4040 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4041 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4042 | |
| 4043 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4044 | nw = args[myidx]; |
| 4045 | while (*nw) { |
| 4046 | /* the "store" keyword supports a comma-separated list */ |
| 4047 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4048 | sa = NULL; /* store arg */ |
| 4049 | while (*nw && *nw != ',') { |
| 4050 | if (*nw == '(') { |
| 4051 | *nw = 0; |
| 4052 | sa = ++nw; |
| 4053 | while (*nw != ')') { |
| 4054 | if (!*nw) { |
| 4055 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4056 | file, linenum, args[0], cw); |
| 4057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4058 | goto out; |
| 4059 | } |
| 4060 | nw++; |
| 4061 | } |
| 4062 | *nw = '\0'; |
| 4063 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4064 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4065 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4066 | if (*nw) |
| 4067 | *nw++ = '\0'; |
| 4068 | type = stktable_get_data_type(cw); |
| 4069 | if (type < 0) { |
| 4070 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4071 | file, linenum, args[0], cw); |
| 4072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4073 | goto out; |
| 4074 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4075 | |
| 4076 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4077 | switch (err) { |
| 4078 | case PE_NONE: break; |
| 4079 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4080 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4081 | file, linenum, args[0], cw); |
| 4082 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4083 | break; |
| 4084 | |
| 4085 | case PE_ARG_MISSING: |
| 4086 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4087 | file, linenum, args[0], cw); |
| 4088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4089 | goto out; |
| 4090 | |
| 4091 | case PE_ARG_NOT_USED: |
| 4092 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4093 | file, linenum, args[0], cw); |
| 4094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4095 | goto out; |
| 4096 | |
| 4097 | default: |
| 4098 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4099 | file, linenum, args[0], cw); |
| 4100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4101 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4102 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4103 | } |
| 4104 | myidx++; |
| 4105 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4106 | else { |
| 4107 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4108 | file, linenum, args[myidx]); |
| 4109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4110 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4111 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | if (!curproxy->table.size) { |
| 4115 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4116 | file, linenum); |
| 4117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4118 | goto out; |
| 4119 | } |
| 4120 | |
| 4121 | if (curproxy->table.type == (unsigned int)-1) { |
| 4122 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4123 | file, linenum); |
| 4124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4125 | goto out; |
| 4126 | } |
| 4127 | } |
| 4128 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4129 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4130 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4131 | int myidx = 0; |
| 4132 | const char *name = NULL; |
| 4133 | int flags; |
| 4134 | |
| 4135 | if (curproxy == &defproxy) { |
| 4136 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4138 | goto out; |
| 4139 | } |
| 4140 | |
| 4141 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4142 | err_code |= ERR_WARN; |
| 4143 | goto out; |
| 4144 | } |
| 4145 | |
| 4146 | myidx++; |
| 4147 | if ((strcmp(args[myidx], "store") == 0) || |
| 4148 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4149 | myidx++; |
| 4150 | flags = STK_IS_STORE; |
| 4151 | } |
| 4152 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4153 | myidx++; |
| 4154 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4155 | } |
| 4156 | else if (strcmp(args[myidx], "match") == 0) { |
| 4157 | myidx++; |
| 4158 | flags = STK_IS_MATCH; |
| 4159 | } |
| 4160 | else if (strcmp(args[myidx], "on") == 0) { |
| 4161 | myidx++; |
| 4162 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4163 | } |
| 4164 | else { |
| 4165 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4167 | goto out; |
| 4168 | } |
| 4169 | |
| 4170 | if (*(args[myidx]) == 0) { |
| 4171 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4172 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4173 | goto out; |
| 4174 | } |
| 4175 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4176 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4177 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4178 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4179 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4181 | goto out; |
| 4182 | } |
| 4183 | |
| 4184 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4185 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4186 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4187 | 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] | 4188 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4189 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4190 | goto out; |
| 4191 | } |
| 4192 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4193 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4194 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4195 | 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] | 4196 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4197 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4198 | goto out; |
| 4199 | } |
| 4200 | } |
| 4201 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4202 | /* 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] | 4203 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4204 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4205 | if (strcmp(args[myidx], "table") == 0) { |
| 4206 | myidx++; |
| 4207 | name = args[myidx++]; |
| 4208 | } |
| 4209 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4210 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4211 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4212 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4213 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4214 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4215 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4216 | goto out; |
| 4217 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4218 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4219 | else if (*(args[myidx])) { |
| 4220 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4221 | file, linenum, args[0], args[myidx]); |
| 4222 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4223 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4224 | goto out; |
| 4225 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4226 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4227 | 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] | 4228 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4229 | 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] | 4230 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4231 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4232 | rule->cond = cond; |
| 4233 | rule->expr = expr; |
| 4234 | rule->flags = flags; |
| 4235 | rule->table.name = name ? strdup(name) : NULL; |
| 4236 | LIST_INIT(&rule->list); |
| 4237 | if (flags & STK_ON_RSP) |
| 4238 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4239 | else |
| 4240 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4241 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4242 | else if (!strcmp(args[0], "stats")) { |
| 4243 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4244 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4245 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4246 | if (!*args[1]) { |
| 4247 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4248 | } else if (!strcmp(args[1], "admin")) { |
| 4249 | struct stats_admin_rule *rule; |
| 4250 | |
| 4251 | if (curproxy == &defproxy) { |
| 4252 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4254 | goto out; |
| 4255 | } |
| 4256 | |
| 4257 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4258 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4259 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4260 | goto out; |
| 4261 | } |
| 4262 | |
| 4263 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4264 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4265 | file, linenum, args[0], args[1]); |
| 4266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4267 | goto out; |
| 4268 | } |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4269 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4270 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4271 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4273 | goto out; |
| 4274 | } |
| 4275 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4276 | err_code |= warnif_cond_conflicts(cond, |
| 4277 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4278 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4279 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4280 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4281 | rule->cond = cond; |
| 4282 | LIST_INIT(&rule->list); |
| 4283 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4284 | } else if (!strcmp(args[1], "uri")) { |
| 4285 | if (*(args[2]) == 0) { |
| 4286 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4288 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4289 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4290 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4291 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4292 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4293 | } |
| 4294 | } else if (!strcmp(args[1], "realm")) { |
| 4295 | if (*(args[2]) == 0) { |
| 4296 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4298 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4299 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4300 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4301 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4302 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4303 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4304 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4305 | unsigned interval; |
| 4306 | |
| 4307 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4308 | if (err) { |
| 4309 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4310 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4312 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4313 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4314 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4315 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4316 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4317 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4318 | } 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] | 4319 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4320 | |
| 4321 | if (curproxy == &defproxy) { |
| 4322 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4324 | goto out; |
| 4325 | } |
| 4326 | |
| 4327 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4328 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4329 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4330 | goto out; |
| 4331 | } |
| 4332 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4333 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4334 | !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] | 4335 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4336 | file, linenum, args[0]); |
| 4337 | err_code |= ERR_WARN; |
| 4338 | } |
| 4339 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4340 | 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] | 4341 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4342 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4343 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4344 | goto out; |
| 4345 | } |
| 4346 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4347 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4348 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4349 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4350 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4351 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4352 | } else if (!strcmp(args[1], "auth")) { |
| 4353 | if (*(args[2]) == 0) { |
| 4354 | 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] | 4355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4356 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4357 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4358 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4359 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4360 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4361 | } |
| 4362 | } else if (!strcmp(args[1], "scope")) { |
| 4363 | if (*(args[2]) == 0) { |
| 4364 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4366 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4367 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4368 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4369 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4370 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4371 | } |
| 4372 | } else if (!strcmp(args[1], "enable")) { |
| 4373 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4374 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4375 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4376 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4377 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4378 | } else if (!strcmp(args[1], "hide-version")) { |
| 4379 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4380 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4381 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4382 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4383 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4384 | } else if (!strcmp(args[1], "show-legends")) { |
| 4385 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4386 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4387 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4388 | goto out; |
| 4389 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4390 | } else if (!strcmp(args[1], "show-node")) { |
| 4391 | |
| 4392 | if (*args[2]) { |
| 4393 | int i; |
| 4394 | char c; |
| 4395 | |
| 4396 | for (i=0; args[2][i]; i++) { |
| 4397 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4398 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4399 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4400 | break; |
| 4401 | } |
| 4402 | |
| 4403 | if (!i || args[2][i]) { |
| 4404 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4405 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4406 | file, linenum, args[0], args[1]); |
| 4407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4408 | goto out; |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4413 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4414 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4415 | goto out; |
| 4416 | } |
| 4417 | } else if (!strcmp(args[1], "show-desc")) { |
| 4418 | char *desc = NULL; |
| 4419 | |
| 4420 | if (*args[2]) { |
| 4421 | int i, len=0; |
| 4422 | char *d; |
| 4423 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4424 | for (i = 2; *args[i]; i++) |
| 4425 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4426 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4427 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4428 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4429 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4430 | for (i = 3; *args[i]; i++) |
| 4431 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | if (!*args[2] && !global.desc) |
| 4435 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4436 | file, linenum, args[1]); |
| 4437 | else { |
| 4438 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4439 | free(desc); |
| 4440 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4441 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4442 | goto out; |
| 4443 | } |
| 4444 | free(desc); |
| 4445 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4446 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4447 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4448 | 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] | 4449 | 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] | 4450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4451 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4455 | int optnum; |
| 4456 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4457 | if (*(args[1]) == '\0') { |
| 4458 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4459 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4461 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4462 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4463 | |
| 4464 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4465 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4466 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4467 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4468 | file, linenum, cfg_opts[optnum].name); |
| 4469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4470 | goto out; |
| 4471 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4472 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4473 | goto out; |
| 4474 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4475 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4476 | err_code |= ERR_WARN; |
| 4477 | goto out; |
| 4478 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4479 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4480 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4481 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4482 | |
| 4483 | switch (kwm) { |
| 4484 | case KWM_STD: |
| 4485 | curproxy->options |= cfg_opts[optnum].val; |
| 4486 | break; |
| 4487 | case KWM_NO: |
| 4488 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4489 | break; |
| 4490 | case KWM_DEF: /* already cleared */ |
| 4491 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4492 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4493 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4494 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4495 | } |
| 4496 | } |
| 4497 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4498 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4499 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4500 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4501 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4502 | file, linenum, cfg_opts2[optnum].name); |
| 4503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4504 | goto out; |
| 4505 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4506 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4507 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4508 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4509 | err_code |= ERR_WARN; |
| 4510 | goto out; |
| 4511 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4512 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4513 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4514 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4515 | |
| 4516 | switch (kwm) { |
| 4517 | case KWM_STD: |
| 4518 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4519 | break; |
| 4520 | case KWM_NO: |
| 4521 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4522 | break; |
| 4523 | case KWM_DEF: /* already cleared */ |
| 4524 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4525 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4526 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4527 | } |
| 4528 | } |
| 4529 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4530 | /* HTTP options override each other. They can be cancelled using |
| 4531 | * "no option xxx" which only switches to default mode if the mode |
| 4532 | * was this one (useful for cancelling options set in defaults |
| 4533 | * sections). |
| 4534 | */ |
| 4535 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4536 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4537 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4538 | if (kwm == KWM_STD) { |
| 4539 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4540 | curproxy->options |= PR_O_HTTP_PCL; |
| 4541 | goto out; |
| 4542 | } |
| 4543 | else if (kwm == KWM_NO) { |
| 4544 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4545 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4546 | goto out; |
| 4547 | } |
| 4548 | } |
| 4549 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4550 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4551 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4552 | if (kwm == KWM_STD) { |
| 4553 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4554 | curproxy->options |= PR_O_HTTP_FCL; |
| 4555 | goto out; |
| 4556 | } |
| 4557 | else if (kwm == KWM_NO) { |
| 4558 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4559 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4560 | goto out; |
| 4561 | } |
| 4562 | } |
| 4563 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4564 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4565 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4566 | if (kwm == KWM_STD) { |
| 4567 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4568 | curproxy->options |= PR_O_HTTP_SCL; |
| 4569 | goto out; |
| 4570 | } |
| 4571 | else if (kwm == KWM_NO) { |
| 4572 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4573 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4574 | goto out; |
| 4575 | } |
| 4576 | } |
| 4577 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4578 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4579 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4580 | if (kwm == KWM_STD) { |
| 4581 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4582 | curproxy->options |= PR_O_HTTP_KAL; |
| 4583 | goto out; |
| 4584 | } |
| 4585 | else if (kwm == KWM_NO) { |
| 4586 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4587 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4588 | goto out; |
| 4589 | } |
| 4590 | } |
| 4591 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4592 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4593 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4594 | if (kwm == KWM_STD) { |
| 4595 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4596 | curproxy->options |= PR_O_HTTP_TUN; |
| 4597 | goto out; |
| 4598 | } |
| 4599 | else if (kwm == KWM_NO) { |
| 4600 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4601 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4602 | goto out; |
| 4603 | } |
| 4604 | } |
| 4605 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4606 | /* Redispatch can take an integer argument that control when the |
| 4607 | * resispatch occurs. All values are relative to the retries option. |
| 4608 | * This can be cancelled using "no option xxx". |
| 4609 | */ |
| 4610 | if (strcmp(args[1], "redispatch") == 0) { |
| 4611 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4612 | err_code |= ERR_WARN; |
| 4613 | goto out; |
| 4614 | } |
| 4615 | |
| 4616 | curproxy->no_options &= ~PR_O_REDISP; |
| 4617 | curproxy->options &= ~PR_O_REDISP; |
| 4618 | |
| 4619 | switch (kwm) { |
| 4620 | case KWM_STD: |
| 4621 | curproxy->options |= PR_O_REDISP; |
| 4622 | curproxy->redispatch_after = -1; |
| 4623 | if(*args[2]) { |
| 4624 | curproxy->redispatch_after = atol(args[2]); |
| 4625 | } |
| 4626 | break; |
| 4627 | case KWM_NO: |
| 4628 | curproxy->no_options |= PR_O_REDISP; |
| 4629 | curproxy->redispatch_after = 0; |
| 4630 | break; |
| 4631 | case KWM_DEF: /* already cleared */ |
| 4632 | break; |
| 4633 | } |
| 4634 | goto out; |
| 4635 | } |
| 4636 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4637 | if (kwm != KWM_STD) { |
| 4638 | 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] | 4639 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4641 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4644 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4645 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4646 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4647 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4648 | if (*(args[2]) != '\0') { |
| 4649 | if (!strcmp(args[2], "clf")) { |
| 4650 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4651 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4652 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4653 | 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] | 4654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4655 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4656 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4657 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4658 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4659 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4660 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4661 | char *oldlogformat = "log-format"; |
| 4662 | char *clflogformat = ""; |
| 4663 | |
| 4664 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4665 | oldlogformat = "option httplog"; |
| 4666 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4667 | oldlogformat = "option tcplog"; |
| 4668 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4669 | oldlogformat = "option httplog clf"; |
| 4670 | if (logformat == clf_http_log_format) |
| 4671 | clflogformat = " clf"; |
| 4672 | Warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 4673 | file, linenum, clflogformat, oldlogformat); |
| 4674 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4675 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4676 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4677 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4678 | free(curproxy->conf.logformat_string); |
| 4679 | curproxy->conf.logformat_string = logformat; |
| 4680 | |
| 4681 | free(curproxy->conf.lfs_file); |
| 4682 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4683 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4684 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4685 | else if (!strcmp(args[1], "tcplog")) { |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4686 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4687 | char *oldlogformat = "log-format"; |
| 4688 | |
| 4689 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4690 | oldlogformat = "option httplog"; |
| 4691 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4692 | oldlogformat = "option tcplog"; |
| 4693 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4694 | oldlogformat = "option httplog clf"; |
| 4695 | Warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 4696 | file, linenum, oldlogformat); |
| 4697 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4698 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4699 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4700 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4701 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4702 | free(curproxy->conf.logformat_string); |
| 4703 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4704 | |
| 4705 | free(curproxy->conf.lfs_file); |
| 4706 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4707 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4708 | |
| 4709 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4710 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4711 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4712 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4713 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4714 | 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] | 4715 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4716 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4717 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4718 | goto out; |
| 4719 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4720 | if (curproxy->cap & PR_CAP_FE) |
| 4721 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4722 | if (curproxy->cap & PR_CAP_BE) |
| 4723 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4724 | } |
| 4725 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4726 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4727 | err_code |= ERR_WARN; |
| 4728 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4729 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4730 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4731 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4732 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4733 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4734 | if (!*args[2]) { /* no argument */ |
| 4735 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4736 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4737 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4738 | 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] | 4739 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4740 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4741 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4742 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4743 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4744 | if (*args[4]) |
| 4745 | reqlen += strlen(args[4]); |
| 4746 | else |
| 4747 | reqlen += strlen("HTTP/1.0"); |
| 4748 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4749 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4750 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4751 | "%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] | 4752 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4753 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4754 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4755 | } |
| 4756 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4757 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4758 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4759 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4760 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4761 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4762 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4763 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4764 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4765 | |
| 4766 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4767 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4768 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4769 | else if (!strcmp(args[1], "smtpchk")) { |
| 4770 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4771 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4772 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4773 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4774 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4775 | |
| 4776 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4777 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4778 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4779 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4780 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4781 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4782 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4783 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4784 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4785 | } else { |
| 4786 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4787 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4788 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4789 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4790 | } |
| 4791 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4792 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4793 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4794 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4795 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4796 | /* use PostgreSQL request to check servers' health */ |
| 4797 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4798 | err_code |= ERR_WARN; |
| 4799 | |
| 4800 | free(curproxy->check_req); |
| 4801 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4802 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4803 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4804 | |
| 4805 | if (*(args[2])) { |
| 4806 | int cur_arg = 2; |
| 4807 | |
| 4808 | while (*(args[cur_arg])) { |
| 4809 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4810 | char * packet; |
| 4811 | uint32_t packet_len; |
| 4812 | uint32_t pv; |
| 4813 | |
| 4814 | /* suboption header - needs additional argument for it */ |
| 4815 | if (*(args[cur_arg+1]) == 0) { |
| 4816 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4817 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4819 | goto out; |
| 4820 | } |
| 4821 | |
| 4822 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4823 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4824 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4825 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4826 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4827 | |
| 4828 | memcpy(packet + 4, &pv, 4); |
| 4829 | |
| 4830 | /* copy "user" */ |
| 4831 | memcpy(packet + 8, "user", 4); |
| 4832 | |
| 4833 | /* copy username */ |
| 4834 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4835 | |
| 4836 | free(curproxy->check_req); |
| 4837 | curproxy->check_req = packet; |
| 4838 | curproxy->check_len = packet_len; |
| 4839 | |
| 4840 | packet_len = htonl(packet_len); |
| 4841 | memcpy(packet, &packet_len, 4); |
| 4842 | cur_arg += 2; |
| 4843 | } else { |
| 4844 | /* unknown suboption - catchall */ |
| 4845 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4846 | file, linenum, args[0], args[1]); |
| 4847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4848 | goto out; |
| 4849 | } |
| 4850 | } /* end while loop */ |
| 4851 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4852 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4853 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4854 | } |
| 4855 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4856 | else if (!strcmp(args[1], "redis-check")) { |
| 4857 | /* use REDIS PING request to check servers' health */ |
| 4858 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4859 | err_code |= ERR_WARN; |
| 4860 | |
| 4861 | free(curproxy->check_req); |
| 4862 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4863 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4864 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4865 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4866 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4867 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4868 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4869 | |
| 4870 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4871 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4874 | else if (!strcmp(args[1], "mysql-check")) { |
| 4875 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4876 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4877 | err_code |= ERR_WARN; |
| 4878 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4879 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4880 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4881 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4882 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4883 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4884 | /* 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] | 4885 | * const char mysql40_client_auth_pkt[] = { |
| 4886 | * "\x0e\x00\x00" // packet length |
| 4887 | * "\x01" // packet number |
| 4888 | * "\x00\x00" // client capabilities |
| 4889 | * "\x00\x00\x01" // max packet |
| 4890 | * "haproxy\x00" // username (null terminated string) |
| 4891 | * "\x00" // filler (always 0x00) |
| 4892 | * "\x01\x00\x00" // packet length |
| 4893 | * "\x00" // packet number |
| 4894 | * "\x01" // COM_QUIT command |
| 4895 | * }; |
| 4896 | */ |
| 4897 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4898 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4899 | * const char mysql41_client_auth_pkt[] = { |
| 4900 | * "\x0e\x00\x00\" // packet length |
| 4901 | * "\x01" // packet number |
| 4902 | * "\x00\x00\x00\x00" // client capabilities |
| 4903 | * "\x00\x00\x00\x01" // max packet |
| 4904 | * "\x21" // character set (UTF-8) |
| 4905 | * char[23] // All zeroes |
| 4906 | * "haproxy\x00" // username (null terminated string) |
| 4907 | * "\x00" // filler (always 0x00) |
| 4908 | * "\x01\x00\x00" // packet length |
| 4909 | * "\x00" // packet number |
| 4910 | * "\x01" // COM_QUIT command |
| 4911 | * }; |
| 4912 | */ |
| 4913 | |
| 4914 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4915 | if (*(args[2])) { |
| 4916 | int cur_arg = 2; |
| 4917 | |
| 4918 | while (*(args[cur_arg])) { |
| 4919 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4920 | char *mysqluser; |
| 4921 | int packetlen, reqlen, userlen; |
| 4922 | |
| 4923 | /* suboption header - needs additional argument for it */ |
| 4924 | if (*(args[cur_arg+1]) == 0) { |
| 4925 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4926 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4927 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4928 | goto out; |
| 4929 | } |
| 4930 | mysqluser = args[cur_arg + 1]; |
| 4931 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4932 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4933 | if (*(args[cur_arg+2])) { |
| 4934 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4935 | packetlen = userlen + 7 + 27; |
| 4936 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4937 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4938 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4939 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4940 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4941 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4942 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4943 | ((unsigned char) packetlen & 0xff), |
| 4944 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4945 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4946 | |
| 4947 | curproxy->check_req[3] = 1; |
| 4948 | curproxy->check_req[5] = 130; |
| 4949 | curproxy->check_req[11] = 1; |
| 4950 | curproxy->check_req[12] = 33; |
| 4951 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4952 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4953 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4954 | cur_arg += 3; |
| 4955 | } else { |
| 4956 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4958 | goto out; |
| 4959 | } |
| 4960 | } else { |
| 4961 | packetlen = userlen + 7; |
| 4962 | reqlen = packetlen + 9; |
| 4963 | |
| 4964 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4965 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4966 | curproxy->check_len = reqlen; |
| 4967 | |
| 4968 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4969 | ((unsigned char) packetlen & 0xff), |
| 4970 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4971 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4972 | |
| 4973 | curproxy->check_req[3] = 1; |
| 4974 | curproxy->check_req[5] = 128; |
| 4975 | curproxy->check_req[8] = 1; |
| 4976 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4977 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4978 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4979 | cur_arg += 2; |
| 4980 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4981 | } else { |
| 4982 | /* unknown suboption - catchall */ |
| 4983 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4984 | file, linenum, args[0], args[1]); |
| 4985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4986 | goto out; |
| 4987 | } |
| 4988 | } /* end while loop */ |
| 4989 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4990 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4991 | else if (!strcmp(args[1], "ldap-check")) { |
| 4992 | /* use LDAP request to check servers' health */ |
| 4993 | free(curproxy->check_req); |
| 4994 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4995 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4996 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4997 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4998 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4999 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5000 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5001 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5002 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5003 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5004 | else if (!strcmp(args[1], "spop-check")) { |
| 5005 | if (curproxy == &defproxy) { |
| 5006 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5007 | file, linenum, args[0], args[1]); |
| 5008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5009 | goto out; |
| 5010 | } |
| 5011 | if (curproxy->cap & PR_CAP_FE) { |
| 5012 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5013 | file, linenum, args[0], args[1]); |
| 5014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5015 | goto out; |
| 5016 | } |
| 5017 | |
| 5018 | /* use SPOE request to check servers' health */ |
| 5019 | free(curproxy->check_req); |
| 5020 | curproxy->check_req = NULL; |
| 5021 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5022 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5023 | |
Christopher Faulet | 8ef7525 | 2017-02-20 22:56:03 +0100 | [diff] [blame] | 5024 | if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5025 | Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
| 5026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5027 | goto out; |
| 5028 | } |
| 5029 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5030 | goto out; |
| 5031 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5032 | else if (!strcmp(args[1], "tcp-check")) { |
| 5033 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5034 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5035 | err_code |= ERR_WARN; |
| 5036 | |
| 5037 | free(curproxy->check_req); |
| 5038 | curproxy->check_req = NULL; |
| 5039 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5040 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5041 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5042 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5043 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5044 | else if (!strcmp(args[1], "external-check")) { |
| 5045 | /* excute an external command to check servers' health */ |
| 5046 | free(curproxy->check_req); |
| 5047 | curproxy->check_req = NULL; |
| 5048 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5049 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5050 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5051 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5052 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5053 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5054 | int cur_arg; |
| 5055 | |
| 5056 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5057 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5058 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5059 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5060 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5061 | |
| 5062 | free(curproxy->fwdfor_hdr_name); |
| 5063 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5064 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5065 | |
| 5066 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5067 | cur_arg = 2; |
| 5068 | while (*(args[cur_arg])) { |
| 5069 | if (!strcmp(args[cur_arg], "except")) { |
| 5070 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5071 | 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] | 5072 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] 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; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5076 | } |
| 5077 | /* flush useless bits */ |
| 5078 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5079 | cur_arg += 2; |
| 5080 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5081 | /* suboption header - needs additional argument for it */ |
| 5082 | if (*(args[cur_arg+1]) == 0) { |
| 5083 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5084 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5085 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5086 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5087 | } |
| 5088 | free(curproxy->fwdfor_hdr_name); |
| 5089 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5090 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5091 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5092 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5093 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5094 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5095 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5096 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5097 | 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] | 5098 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5100 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5101 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5102 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5103 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5104 | else if (!strcmp(args[1], "originalto")) { |
| 5105 | int cur_arg; |
| 5106 | |
| 5107 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5108 | * set default options (ie: bitfield, header name, etc) |
| 5109 | */ |
| 5110 | |
| 5111 | curproxy->options |= PR_O_ORGTO; |
| 5112 | |
| 5113 | free(curproxy->orgto_hdr_name); |
| 5114 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5115 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5116 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5117 | /* 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] | 5118 | cur_arg = 2; |
| 5119 | while (*(args[cur_arg])) { |
| 5120 | if (!strcmp(args[cur_arg], "except")) { |
| 5121 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5122 | 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] | 5123 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] 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 | /* flush useless bits */ |
| 5129 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5130 | cur_arg += 2; |
| 5131 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5132 | /* suboption header - needs additional argument for it */ |
| 5133 | if (*(args[cur_arg+1]) == 0) { |
| 5134 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5135 | file, linenum, args[0], args[1], args[cur_arg]); |
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 | free(curproxy->orgto_hdr_name); |
| 5140 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5141 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5142 | cur_arg += 2; |
| 5143 | } else { |
| 5144 | /* unknown suboption - catchall */ |
| 5145 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5146 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5148 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5149 | } |
| 5150 | } /* end while loop */ |
| 5151 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5152 | else { |
| 5153 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5155 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5156 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5157 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5158 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5159 | else if (!strcmp(args[0], "default_backend")) { |
| 5160 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5161 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5162 | |
| 5163 | if (*(args[1]) == 0) { |
| 5164 | 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] | 5165 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5166 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5167 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5168 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5169 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5170 | |
| 5171 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5172 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5173 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5174 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5175 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5176 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5177 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5178 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5179 | 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] | 5180 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5181 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5182 | /* enable reconnections to dispatch */ |
| 5183 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5184 | |
| 5185 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5186 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5187 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5188 | else if (!strcmp(args[0], "http-reuse")) { |
| 5189 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5190 | err_code |= ERR_WARN; |
| 5191 | |
| 5192 | if (strcmp(args[1], "never") == 0) { |
| 5193 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5194 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5195 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5196 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5197 | goto out; |
| 5198 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5199 | else if (strcmp(args[1], "safe") == 0) { |
| 5200 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5201 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5202 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5203 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5204 | goto out; |
| 5205 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5206 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5207 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5208 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5209 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5210 | goto out; |
| 5211 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5212 | else if (strcmp(args[1], "always") == 0) { |
| 5213 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5214 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5215 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5216 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5217 | goto out; |
| 5218 | } |
| 5219 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5220 | 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] | 5221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5222 | goto out; |
| 5223 | } |
| 5224 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5225 | else if (!strcmp(args[0], "http-check")) { |
| 5226 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5227 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5228 | |
| 5229 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5230 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5231 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5232 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5233 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5234 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5235 | else if (strcmp(args[1], "send-state") == 0) { |
| 5236 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5237 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5238 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5239 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5240 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5241 | else if (strcmp(args[1], "expect") == 0) { |
| 5242 | const char *ptr_arg; |
| 5243 | int cur_arg; |
| 5244 | |
| 5245 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5246 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5247 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5248 | goto out; |
| 5249 | } |
| 5250 | |
| 5251 | cur_arg = 2; |
| 5252 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5253 | while (*(ptr_arg = args[cur_arg])) { |
| 5254 | while (*ptr_arg == '!') { |
| 5255 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5256 | ptr_arg++; |
| 5257 | } |
| 5258 | if (*ptr_arg) |
| 5259 | break; |
| 5260 | cur_arg++; |
| 5261 | } |
| 5262 | /* now ptr_arg points to the beginning of a word past any possible |
| 5263 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5264 | */ |
| 5265 | if (strcmp(ptr_arg, "status") == 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_STS; |
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, "string") == 0) { |
| 5277 | if (!*(args[cur_arg + 1])) { |
| 5278 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> 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_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5284 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5285 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5286 | } |
| 5287 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5288 | if (!*(args[cur_arg + 1])) { |
| 5289 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5290 | file, linenum, args[0], args[1], ptr_arg); |
| 5291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5292 | goto out; |
| 5293 | } |
| 5294 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5295 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5296 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5297 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5298 | free(curproxy->expect_regex); |
| 5299 | curproxy->expect_regex = NULL; |
| 5300 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5301 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5302 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5303 | error = NULL; |
| 5304 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5305 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5306 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5307 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5309 | goto out; |
| 5310 | } |
| 5311 | } |
| 5312 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5313 | if (!*(args[cur_arg + 1])) { |
| 5314 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5315 | file, linenum, args[0], args[1], ptr_arg); |
| 5316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5317 | goto out; |
| 5318 | } |
| 5319 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5320 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5321 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5322 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5323 | free(curproxy->expect_regex); |
| 5324 | curproxy->expect_regex = NULL; |
| 5325 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5326 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5327 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5328 | error = NULL; |
| 5329 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5330 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5331 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5332 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5334 | goto out; |
| 5335 | } |
| 5336 | } |
| 5337 | else { |
| 5338 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5339 | file, linenum, args[0], args[1], ptr_arg); |
| 5340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5341 | goto out; |
| 5342 | } |
| 5343 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5344 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5345 | 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] | 5346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5347 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5348 | } |
| 5349 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5350 | else if (!strcmp(args[0], "tcp-check")) { |
| 5351 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5352 | err_code |= ERR_WARN; |
| 5353 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5354 | if (strcmp(args[1], "comment") == 0) { |
| 5355 | int cur_arg; |
| 5356 | struct tcpcheck_rule *tcpcheck; |
| 5357 | |
| 5358 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5359 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5360 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5361 | |
| 5362 | if (!*args[cur_arg + 1]) { |
| 5363 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5364 | file, linenum, args[cur_arg]); |
| 5365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5366 | goto out; |
| 5367 | } |
| 5368 | |
| 5369 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5370 | |
| 5371 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5372 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5373 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5374 | } |
| 5375 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5376 | const char *ptr_arg; |
| 5377 | int cur_arg; |
| 5378 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5379 | |
| 5380 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5381 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5382 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5383 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5384 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5385 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5386 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5387 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5388 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5389 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5390 | file, linenum); |
| 5391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5392 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5396 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5397 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5398 | |
| 5399 | /* parsing each parameters to fill up the rule */ |
| 5400 | while (*(ptr_arg = args[cur_arg])) { |
| 5401 | /* tcp port */ |
| 5402 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5403 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5404 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5405 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5406 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5407 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5408 | goto out; |
| 5409 | } |
| 5410 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5411 | cur_arg += 2; |
| 5412 | } |
| 5413 | /* send proxy protocol */ |
| 5414 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5415 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5416 | cur_arg++; |
| 5417 | } |
| 5418 | #ifdef USE_OPENSSL |
| 5419 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5420 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5421 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5422 | cur_arg++; |
| 5423 | } |
| 5424 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5425 | /* comment for this tcpcheck line */ |
| 5426 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5427 | if (!*args[cur_arg + 1]) { |
| 5428 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5429 | file, linenum, args[cur_arg]); |
| 5430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5431 | goto out; |
| 5432 | } |
| 5433 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5434 | cur_arg += 2; |
| 5435 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5436 | else { |
| 5437 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5438 | 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] | 5439 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5440 | 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] | 5441 | #endif /* USE_OPENSSL */ |
| 5442 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5444 | goto out; |
| 5445 | } |
| 5446 | |
| 5447 | } |
| 5448 | |
| 5449 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5450 | } |
| 5451 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5452 | if (! *(args[2]) ) { |
| 5453 | /* SEND string expected */ |
| 5454 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5455 | file, linenum, args[0], args[1], args[2]); |
| 5456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5457 | goto out; |
| 5458 | } else { |
| 5459 | struct tcpcheck_rule *tcpcheck; |
| 5460 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5461 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5462 | |
| 5463 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5464 | tcpcheck->string_len = strlen(args[2]); |
| 5465 | tcpcheck->string = strdup(args[2]); |
| 5466 | tcpcheck->expect_regex = NULL; |
| 5467 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5468 | /* comment for this tcpcheck line */ |
| 5469 | if (strcmp(args[3], "comment") == 0) { |
| 5470 | if (!*args[4]) { |
| 5471 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5472 | file, linenum, args[3]); |
| 5473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5474 | goto out; |
| 5475 | } |
| 5476 | tcpcheck->comment = strdup(args[4]); |
| 5477 | } |
| 5478 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5479 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5480 | } |
| 5481 | } |
| 5482 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5483 | if (! *(args[2]) ) { |
| 5484 | /* SEND binary string expected */ |
| 5485 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5486 | file, linenum, args[0], args[1], args[2]); |
| 5487 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5488 | goto out; |
| 5489 | } else { |
| 5490 | struct tcpcheck_rule *tcpcheck; |
| 5491 | char *err = NULL; |
| 5492 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5493 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5494 | |
| 5495 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5496 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5497 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5498 | file, linenum, args[0], args[1], args[2], err); |
| 5499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5500 | goto out; |
| 5501 | } |
| 5502 | tcpcheck->expect_regex = NULL; |
| 5503 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5504 | /* comment for this tcpcheck line */ |
| 5505 | if (strcmp(args[3], "comment") == 0) { |
| 5506 | if (!*args[4]) { |
| 5507 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5508 | file, linenum, args[3]); |
| 5509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5510 | goto out; |
| 5511 | } |
| 5512 | tcpcheck->comment = strdup(args[4]); |
| 5513 | } |
| 5514 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5515 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5516 | } |
| 5517 | } |
| 5518 | else if (strcmp(args[1], "expect") == 0) { |
| 5519 | const char *ptr_arg; |
| 5520 | int cur_arg; |
| 5521 | int inverse = 0; |
| 5522 | |
| 5523 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5524 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5526 | goto out; |
| 5527 | } |
| 5528 | |
| 5529 | cur_arg = 2; |
| 5530 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5531 | while (*(ptr_arg = args[cur_arg])) { |
| 5532 | while (*ptr_arg == '!') { |
| 5533 | inverse = !inverse; |
| 5534 | ptr_arg++; |
| 5535 | } |
| 5536 | if (*ptr_arg) |
| 5537 | break; |
| 5538 | cur_arg++; |
| 5539 | } |
| 5540 | /* now ptr_arg points to the beginning of a word past any possible |
| 5541 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5542 | */ |
| 5543 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5544 | struct tcpcheck_rule *tcpcheck; |
| 5545 | char *err = NULL; |
| 5546 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5547 | if (!*(args[cur_arg + 1])) { |
| 5548 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5549 | file, linenum, args[0], args[1], ptr_arg); |
| 5550 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5551 | goto out; |
| 5552 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5553 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5554 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5555 | |
| 5556 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5557 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5558 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5559 | file, linenum, args[0], args[1], args[2], err); |
| 5560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5561 | goto out; |
| 5562 | } |
| 5563 | tcpcheck->expect_regex = NULL; |
| 5564 | tcpcheck->inverse = inverse; |
| 5565 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5566 | /* tcpcheck comment */ |
| 5567 | cur_arg += 2; |
| 5568 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5569 | if (!*args[cur_arg + 1]) { |
| 5570 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5571 | file, linenum, args[cur_arg + 1]); |
| 5572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5573 | goto out; |
| 5574 | } |
| 5575 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5576 | } |
| 5577 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5578 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5579 | } |
| 5580 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5581 | struct tcpcheck_rule *tcpcheck; |
| 5582 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5583 | if (!*(args[cur_arg + 1])) { |
| 5584 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5585 | file, linenum, args[0], args[1], ptr_arg); |
| 5586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5587 | goto out; |
| 5588 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5589 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5590 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5591 | |
| 5592 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5593 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5594 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5595 | tcpcheck->expect_regex = NULL; |
| 5596 | tcpcheck->inverse = inverse; |
| 5597 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5598 | /* tcpcheck comment */ |
| 5599 | cur_arg += 2; |
| 5600 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5601 | if (!*args[cur_arg + 1]) { |
| 5602 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5603 | file, linenum, args[cur_arg + 1]); |
| 5604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5605 | goto out; |
| 5606 | } |
| 5607 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5608 | } |
| 5609 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5610 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5611 | } |
| 5612 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5613 | struct tcpcheck_rule *tcpcheck; |
| 5614 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5615 | if (!*(args[cur_arg + 1])) { |
| 5616 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5617 | file, linenum, args[0], args[1], ptr_arg); |
| 5618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5619 | goto out; |
| 5620 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5621 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5622 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5623 | |
| 5624 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5625 | tcpcheck->string_len = 0; |
| 5626 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5627 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5628 | error = NULL; |
| 5629 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5630 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5631 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5632 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5634 | goto out; |
| 5635 | } |
| 5636 | tcpcheck->inverse = inverse; |
| 5637 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5638 | /* tcpcheck comment */ |
| 5639 | cur_arg += 2; |
| 5640 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5641 | if (!*args[cur_arg + 1]) { |
| 5642 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5643 | file, linenum, args[cur_arg + 1]); |
| 5644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5645 | goto out; |
| 5646 | } |
| 5647 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5648 | } |
| 5649 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5650 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5651 | } |
| 5652 | else { |
| 5653 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5654 | file, linenum, args[0], args[1], ptr_arg); |
| 5655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5656 | goto out; |
| 5657 | } |
| 5658 | } |
| 5659 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5660 | 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] | 5661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5662 | goto out; |
| 5663 | } |
| 5664 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5665 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5666 | if (curproxy == &defproxy) { |
| 5667 | 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] | 5668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5669 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5670 | } |
| 5671 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5672 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5673 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5674 | |
| 5675 | if (strcmp(args[1], "fail") == 0) { |
| 5676 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5677 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5678 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5679 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5681 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5682 | } |
| 5683 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 5684 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5685 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5686 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5688 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5689 | } |
| 5690 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5691 | } |
| 5692 | else { |
| 5693 | 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] | 5694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5695 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5696 | } |
| 5697 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5698 | #ifdef TPROXY |
| 5699 | else if (!strcmp(args[0], "transparent")) { |
| 5700 | /* enable transparent proxy connections */ |
| 5701 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5702 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5703 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5704 | } |
| 5705 | #endif |
| 5706 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5707 | 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] | 5708 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5709 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5710 | if (*(args[1]) == 0) { |
| 5711 | 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] | 5712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5713 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5714 | } |
| 5715 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5716 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5717 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5718 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5719 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5720 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5721 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5722 | |
| 5723 | if (*(args[1]) == 0) { |
| 5724 | 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] | 5725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5726 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5727 | } |
| 5728 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5729 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5730 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5731 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5732 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5733 | 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] | 5734 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5735 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5736 | if (*(args[1]) == 0) { |
| 5737 | 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] | 5738 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5739 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5740 | } |
| 5741 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5742 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5743 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5744 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5745 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5746 | if (*(args[1]) == 0) { |
| 5747 | 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] | 5748 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5750 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5751 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5752 | if (err) { |
| 5753 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5754 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5756 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5757 | } |
| 5758 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5759 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5760 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5761 | } |
| 5762 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5763 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5764 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5765 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5766 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5767 | if (curproxy == &defproxy) { |
| 5768 | 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] | 5769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5770 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5771 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5772 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5773 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5774 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5775 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5776 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5777 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5778 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5779 | goto out; |
| 5780 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5781 | |
| 5782 | proto = protocol_by_family(sk->ss_family); |
| 5783 | if (!proto || !proto->connect) { |
| 5784 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5785 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5787 | goto out; |
| 5788 | } |
| 5789 | |
| 5790 | if (port1 != port2) { |
| 5791 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5792 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5794 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5795 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5796 | |
| 5797 | if (!port1) { |
| 5798 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5799 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5801 | goto out; |
| 5802 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5803 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5804 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5805 | goto out; |
| 5806 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5807 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5808 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5809 | } |
| 5810 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5811 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5812 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5813 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5814 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5815 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5817 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5818 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5819 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5820 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5821 | /** |
| 5822 | * The syntax for hash-type config element is |
| 5823 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5824 | * |
| 5825 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5826 | */ |
| 5827 | 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] | 5828 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5829 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5830 | err_code |= ERR_WARN; |
| 5831 | |
| 5832 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5833 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5834 | } |
| 5835 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5836 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5837 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5838 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5839 | 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]); |
| 5840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5841 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5842 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5843 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5844 | 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] | 5845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5846 | goto out; |
| 5847 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5848 | |
| 5849 | /* set the hash function to use */ |
| 5850 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5851 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5852 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5853 | |
| 5854 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5855 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5856 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5857 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5858 | /* set the hash function */ |
| 5859 | if (!strcmp(args[2], "sdbm")) { |
| 5860 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5861 | } |
| 5862 | else if (!strcmp(args[2], "djb2")) { |
| 5863 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5864 | } |
| 5865 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5866 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5867 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5868 | else if (!strcmp(args[2], "crc32")) { |
| 5869 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5870 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5871 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5872 | 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] | 5873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5874 | goto out; |
| 5875 | } |
| 5876 | |
| 5877 | /* set the hash modifier */ |
| 5878 | if (!strcmp(args[3], "avalanche")) { |
| 5879 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5880 | } |
| 5881 | else if (*args[3]) { |
| 5882 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5884 | goto out; |
| 5885 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5886 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5887 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 5888 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 5889 | if (*(args[1]) == 0) { |
| 5890 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 5891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5892 | goto out; |
| 5893 | } |
| 5894 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 5895 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 5896 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 5897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5898 | goto out; |
| 5899 | } |
| 5900 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5901 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5902 | if (!*(args[1])) { |
| 5903 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5905 | goto out; |
| 5906 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5907 | if (*(args[2])) { |
| 5908 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5910 | goto out; |
| 5911 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5912 | free(curproxy->conf.uniqueid_format_string); |
| 5913 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5914 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5915 | free(curproxy->conf.uif_file); |
| 5916 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5917 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5918 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5919 | |
| 5920 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5921 | if (!*(args[1])) { |
| 5922 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5924 | goto out; |
| 5925 | } |
| 5926 | free(curproxy->header_unique_id); |
| 5927 | curproxy->header_unique_id = strdup(args[1]); |
| 5928 | } |
| 5929 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5930 | else if (strcmp(args[0], "log-format") == 0) { |
| 5931 | if (!*(args[1])) { |
| 5932 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5934 | goto out; |
| 5935 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5936 | if (*(args[2])) { |
| 5937 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5939 | goto out; |
| 5940 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 5941 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 5942 | char *oldlogformat = "log-format"; |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 5943 | |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 5944 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 5945 | oldlogformat = "option httplog"; |
| 5946 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 5947 | oldlogformat = "option tcplog"; |
| 5948 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 5949 | oldlogformat = "option httplog clf"; |
| 5950 | Warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 5951 | file, linenum, oldlogformat); |
| 5952 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5953 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 5954 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 5955 | curproxy->conf.logformat_string != clf_http_log_format) |
| 5956 | free(curproxy->conf.logformat_string); |
| 5957 | curproxy->conf.logformat_string = strdup(args[1]); |
| 5958 | |
| 5959 | free(curproxy->conf.lfs_file); |
| 5960 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 5961 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5962 | |
| 5963 | /* get a chance to improve log-format error reporting by |
| 5964 | * reporting the correct line-number when possible. |
| 5965 | */ |
| 5966 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5967 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 5968 | file, linenum, curproxy->id); |
| 5969 | err_code |= ERR_WARN; |
| 5970 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5971 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 5972 | else if (!strcmp(args[0], "log-format-sd")) { |
| 5973 | if (!*(args[1])) { |
| 5974 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5976 | goto out; |
| 5977 | } |
| 5978 | if (*(args[2])) { |
| 5979 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5981 | goto out; |
| 5982 | } |
| 5983 | |
| 5984 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 5985 | free(curproxy->conf.logformat_sd_string); |
| 5986 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 5987 | |
| 5988 | free(curproxy->conf.lfsd_file); |
| 5989 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 5990 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 5991 | |
| 5992 | /* get a chance to improve log-format-sd error reporting by |
| 5993 | * reporting the correct line-number when possible. |
| 5994 | */ |
| 5995 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5996 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 5997 | file, linenum, curproxy->id); |
| 5998 | err_code |= ERR_WARN; |
| 5999 | } |
| 6000 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6001 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6002 | if (*(args[1]) == 0) { |
| 6003 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 6004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6005 | goto out; |
| 6006 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6007 | chunk_destroy(&curproxy->log_tag); |
| 6008 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6009 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6010 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6011 | /* delete previous herited or defined syslog servers */ |
| 6012 | struct logsrv *back; |
| 6013 | |
| 6014 | if (*(args[1]) != 0) { |
| 6015 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6017 | goto out; |
| 6018 | } |
| 6019 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6020 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6021 | LIST_DEL(&tmplogsrv->list); |
| 6022 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6023 | } |
| 6024 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6025 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6026 | struct logsrv *logsrv; |
| 6027 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6028 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6029 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6030 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6031 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6032 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6033 | LIST_INIT(&node->list); |
| 6034 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6035 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6036 | } |
| 6037 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6038 | struct sockaddr_storage *sk; |
| 6039 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6040 | int arg = 0; |
| 6041 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6042 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6043 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6044 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6045 | /* just after the address, a length may be specified */ |
| 6046 | if (strcmp(args[arg+2], "len") == 0) { |
| 6047 | len = atoi(args[arg+3]); |
| 6048 | if (len < 80 || len > 65535) { |
| 6049 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6050 | file, linenum, args[arg+3]); |
| 6051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6052 | goto out; |
| 6053 | } |
| 6054 | logsrv->maxlen = len; |
| 6055 | |
| 6056 | /* skip these two args */ |
| 6057 | arg += 2; |
| 6058 | } |
| 6059 | else |
| 6060 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6061 | |
Christopher Faulet | 084aa96 | 2017-08-29 16:54:41 +0200 | [diff] [blame] | 6062 | if (logsrv->maxlen > global.max_syslog_len) |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6063 | global.max_syslog_len = logsrv->maxlen; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6064 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6065 | /* after the length, a format may be specified */ |
| 6066 | if (strcmp(args[arg+2], "format") == 0) { |
| 6067 | logsrv->format = get_log_format(args[arg+3]); |
| 6068 | if (logsrv->format < 0) { |
| 6069 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6071 | goto out; |
| 6072 | } |
| 6073 | |
| 6074 | /* skip these two args */ |
| 6075 | arg += 2; |
| 6076 | } |
| 6077 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6078 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6079 | goto out; |
| 6080 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6081 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6082 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6083 | 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] | 6084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6085 | goto out; |
| 6086 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6087 | } |
| 6088 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6089 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6090 | if (*(args[arg+3])) { |
| 6091 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6092 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6093 | 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] | 6094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6095 | goto out; |
| 6096 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6097 | } |
| 6098 | } |
| 6099 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6100 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6101 | if (*(args[arg+4])) { |
| 6102 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6103 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6104 | 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] | 6105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6106 | goto out; |
| 6107 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6108 | } |
| 6109 | } |
| 6110 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6111 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6112 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6113 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6114 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6115 | goto out; |
| 6116 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6117 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6118 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6119 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6120 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6121 | if (port1 != port2) { |
| 6122 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6123 | file, linenum, args[0], args[1]); |
| 6124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6125 | goto out; |
| 6126 | } |
| 6127 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6128 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6129 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6130 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6131 | |
| 6132 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6133 | } |
| 6134 | else { |
| 6135 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6136 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6138 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | 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] | 6142 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6143 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6144 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6145 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6146 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6147 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6148 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6149 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6150 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6151 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6152 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6154 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6155 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6156 | |
| 6157 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6158 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6159 | free(curproxy->conn_src.iface_name); |
| 6160 | curproxy->conn_src.iface_name = NULL; |
| 6161 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6162 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6163 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6164 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6165 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6166 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6167 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6168 | goto out; |
| 6169 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6170 | |
| 6171 | proto = protocol_by_family(sk->ss_family); |
| 6172 | if (!proto || !proto->connect) { |
| 6173 | 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] | 6174 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6176 | goto out; |
| 6177 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6178 | |
| 6179 | if (port1 != port2) { |
| 6180 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6181 | file, linenum, args[0], args[1]); |
| 6182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6183 | goto out; |
| 6184 | } |
| 6185 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6186 | curproxy->conn_src.source_addr = *sk; |
| 6187 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6188 | |
| 6189 | cur_arg = 2; |
| 6190 | while (*(args[cur_arg])) { |
| 6191 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6192 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6193 | if (!*args[cur_arg + 1]) { |
| 6194 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6195 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6197 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6201 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6202 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6203 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6204 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6205 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6206 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6207 | char *name, *end; |
| 6208 | |
| 6209 | name = args[cur_arg+1] + 7; |
| 6210 | while (isspace(*name)) |
| 6211 | name++; |
| 6212 | |
| 6213 | end = name; |
| 6214 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6215 | end++; |
| 6216 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6217 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6218 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6219 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6220 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6221 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6222 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6223 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6224 | |
| 6225 | /* now look for an occurrence number */ |
| 6226 | while (isspace(*end)) |
| 6227 | end++; |
| 6228 | if (*end == ',') { |
| 6229 | end++; |
| 6230 | name = end; |
| 6231 | if (*end == '-') |
| 6232 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6233 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6234 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6235 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6236 | } |
| 6237 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6238 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6239 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6240 | " occurrences values smaller than %d.\n", |
| 6241 | file, linenum, MAX_HDR_HISTORY); |
| 6242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6243 | goto out; |
| 6244 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6245 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6246 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6247 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6248 | 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] | 6249 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6250 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6251 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6252 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6253 | goto out; |
| 6254 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6255 | |
| 6256 | proto = protocol_by_family(sk->ss_family); |
| 6257 | if (!proto || !proto->connect) { |
| 6258 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6259 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6261 | goto out; |
| 6262 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6263 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6264 | if (port1 != port2) { |
| 6265 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6266 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6268 | goto out; |
| 6269 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6270 | curproxy->conn_src.tproxy_addr = *sk; |
| 6271 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6272 | } |
| 6273 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6274 | #else /* no TPROXY support */ |
| 6275 | 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] | 6276 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6278 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6279 | #endif |
| 6280 | cur_arg += 2; |
| 6281 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6282 | } |
| 6283 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6284 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6285 | #ifdef SO_BINDTODEVICE |
| 6286 | if (!*args[cur_arg + 1]) { |
| 6287 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6288 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6290 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6291 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6292 | free(curproxy->conn_src.iface_name); |
| 6293 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6294 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6295 | global.last_checks |= LSTCHK_NETADM; |
| 6296 | #else |
| 6297 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6298 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6300 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6301 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6302 | cur_arg += 2; |
| 6303 | continue; |
| 6304 | } |
| 6305 | 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] | 6306 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6308 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6309 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6310 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6311 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6312 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6313 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6315 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6316 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6317 | 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] | 6318 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6319 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6320 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6322 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6323 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6324 | |
| 6325 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6326 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6327 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6328 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6329 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6330 | } |
| 6331 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6332 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6333 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6334 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6335 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6336 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6337 | } |
| 6338 | 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] | 6339 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6340 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6341 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6342 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6343 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6344 | } |
| 6345 | 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] | 6346 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6347 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6348 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6349 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6350 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6351 | } |
| 6352 | 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] | 6353 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6354 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6355 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6356 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6357 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6358 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6359 | 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] | 6360 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6361 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6362 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6363 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6364 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6365 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6366 | 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] | 6367 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6368 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6369 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6371 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6372 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6373 | |
| 6374 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6375 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6376 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6377 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6378 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6379 | } |
| 6380 | 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] | 6381 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6382 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6383 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6384 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6385 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6386 | } |
| 6387 | 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] | 6388 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6389 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6390 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6391 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6392 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6393 | } |
| 6394 | 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] | 6395 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6396 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6397 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6398 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6399 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6400 | } |
| 6401 | 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] | 6402 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6403 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6404 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6405 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6406 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6407 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6408 | 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] | 6409 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6410 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6411 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6412 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6413 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6414 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6415 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6416 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6417 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6418 | if (curproxy == &defproxy) { |
| 6419 | 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] | 6420 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6421 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6422 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6423 | 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] | 6424 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6425 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6426 | if (*(args[1]) == 0) { |
| 6427 | 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] | 6428 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6429 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6430 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6431 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6432 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6433 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6434 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6435 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6437 | goto out; |
| 6438 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6439 | err_code |= warnif_cond_conflicts(cond, |
| 6440 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6441 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6442 | } |
| 6443 | else if (*args[2]) { |
| 6444 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6445 | file, linenum, args[0], args[2]); |
| 6446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6447 | goto out; |
| 6448 | } |
| 6449 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6450 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6451 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6452 | wl->s = strdup(args[1]); |
| 6453 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6454 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6455 | } |
| 6456 | 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] | 6457 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6458 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6459 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6461 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6462 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6463 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6464 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6465 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6466 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6467 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6469 | } |
| 6470 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6471 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6472 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6473 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6474 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6475 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6476 | } |
| 6477 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6478 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6479 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6480 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6481 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6483 | } |
| 6484 | 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] | 6485 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6486 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6487 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6489 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6490 | } |
| 6491 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6492 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6493 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6494 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6495 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6496 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6497 | } |
| 6498 | 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] | 6499 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6500 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6501 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6502 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6503 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6504 | } |
| 6505 | 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] | 6506 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6507 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6508 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6509 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6510 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6511 | } |
| 6512 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6513 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6514 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6515 | if (curproxy == &defproxy) { |
| 6516 | 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] | 6517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6519 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6520 | 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] | 6521 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6522 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6523 | if (*(args[1]) == 0) { |
| 6524 | 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] | 6525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6526 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6527 | } |
| 6528 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6529 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6530 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6531 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6532 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6534 | goto out; |
| 6535 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6536 | err_code |= warnif_cond_conflicts(cond, |
| 6537 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6538 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6539 | } |
| 6540 | else if (*args[2]) { |
| 6541 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6542 | file, linenum, args[0], args[2]); |
| 6543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6544 | goto out; |
| 6545 | } |
| 6546 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6547 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6548 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6549 | wl->s = strdup(args[1]); |
| 6550 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6551 | } |
| 6552 | else if (!strcmp(args[0], "errorloc") || |
| 6553 | !strcmp(args[0], "errorloc302") || |
| 6554 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6555 | int errnum, errlen; |
| 6556 | char *err; |
| 6557 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6558 | 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] | 6559 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6560 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6561 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6562 | 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] | 6563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6564 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | errnum = atol(args[1]); |
| 6568 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6569 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6570 | err = malloc(errlen); |
| 6571 | 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] | 6572 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6573 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6574 | err = malloc(errlen); |
| 6575 | 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] | 6576 | } |
| 6577 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6578 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6579 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6580 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6581 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6582 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6583 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6584 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6585 | |
| 6586 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6587 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6588 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6589 | free(err); |
| 6590 | } |
| 6591 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6592 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6593 | int errnum, errlen, fd; |
| 6594 | char *err; |
| 6595 | struct stat stat; |
| 6596 | |
| 6597 | 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] | 6598 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6599 | |
| 6600 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6601 | 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] | 6602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6603 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | fd = open(args[2], O_RDONLY); |
| 6607 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6608 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6609 | file, linenum, args[2], args[1]); |
| 6610 | if (fd >= 0) |
| 6611 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6613 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6614 | } |
| 6615 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6616 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6617 | errlen = stat.st_size; |
| 6618 | } else { |
| 6619 | 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] | 6620 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6621 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6622 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6623 | } |
| 6624 | |
| 6625 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6626 | errnum = read(fd, err, errlen); |
| 6627 | if (errnum != errlen) { |
| 6628 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6629 | file, linenum, args[2], args[1]); |
| 6630 | close(fd); |
| 6631 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6633 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6634 | } |
| 6635 | close(fd); |
| 6636 | |
| 6637 | errnum = atol(args[1]); |
| 6638 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6639 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6640 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6641 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6642 | break; |
| 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6647 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6648 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6649 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6650 | free(err); |
| 6651 | } |
| 6652 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6653 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6654 | struct cfg_kw_list *kwl; |
| 6655 | int index; |
| 6656 | |
| 6657 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6658 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6659 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6660 | continue; |
| 6661 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6662 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6663 | 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] | 6664 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6665 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6666 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6667 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6668 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6669 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6670 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6671 | err_code |= ERR_WARN; |
| 6672 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6673 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6674 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6675 | } |
| 6676 | } |
| 6677 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6678 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6679 | 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] | 6680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6681 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6682 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6683 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6684 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6685 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6686 | } |
| 6687 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6688 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6689 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6690 | { |
| 6691 | #ifdef CONFIG_HAP_NS |
| 6692 | const char *err; |
| 6693 | const char *item = args[0]; |
| 6694 | |
| 6695 | if (!strcmp(item, "namespace_list")) { |
| 6696 | return 0; |
| 6697 | } |
| 6698 | else if (!strcmp(item, "namespace")) { |
| 6699 | size_t idx = 1; |
| 6700 | const char *current; |
| 6701 | while (*(current = args[idx++])) { |
| 6702 | err = invalid_char(current); |
| 6703 | if (err) { |
| 6704 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6705 | file, linenum, *err, item, current); |
| 6706 | return ERR_ALERT | ERR_FATAL; |
| 6707 | } |
| 6708 | |
| 6709 | if (netns_store_lookup(current, strlen(current))) { |
| 6710 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6711 | file, linenum, current); |
| 6712 | return ERR_ALERT | ERR_FATAL; |
| 6713 | } |
| 6714 | if (!netns_store_insert(current)) { |
| 6715 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6716 | file, linenum, current); |
| 6717 | return ERR_ALERT | ERR_FATAL; |
| 6718 | } |
| 6719 | } |
| 6720 | } |
| 6721 | |
| 6722 | return 0; |
| 6723 | #else |
| 6724 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6725 | file, linenum); |
| 6726 | return ERR_ALERT | ERR_FATAL; |
| 6727 | #endif |
| 6728 | } |
| 6729 | |
| 6730 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6731 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6732 | { |
| 6733 | |
| 6734 | int err_code = 0; |
| 6735 | const char *err; |
| 6736 | |
| 6737 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6738 | struct userlist *newul; |
| 6739 | |
| 6740 | if (!*args[1]) { |
| 6741 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6742 | file, linenum, args[0]); |
| 6743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6744 | goto out; |
| 6745 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6746 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6747 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6748 | |
| 6749 | err = invalid_char(args[1]); |
| 6750 | if (err) { |
| 6751 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6752 | file, linenum, *err, args[0], args[1]); |
| 6753 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6754 | goto out; |
| 6755 | } |
| 6756 | |
| 6757 | for (newul = userlist; newul; newul = newul->next) |
| 6758 | if (!strcmp(newul->name, args[1])) { |
| 6759 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6760 | file, linenum, args[1]); |
| 6761 | err_code |= ERR_WARN; |
| 6762 | goto out; |
| 6763 | } |
| 6764 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6765 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6766 | if (!newul) { |
| 6767 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6768 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6769 | goto out; |
| 6770 | } |
| 6771 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6772 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6773 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6774 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6775 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6776 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6777 | goto out; |
| 6778 | } |
| 6779 | |
| 6780 | newul->next = userlist; |
| 6781 | userlist = newul; |
| 6782 | |
| 6783 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6784 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6785 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6786 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6787 | |
| 6788 | if (!*args[1]) { |
| 6789 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6790 | file, linenum, args[0]); |
| 6791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6792 | goto out; |
| 6793 | } |
| 6794 | |
| 6795 | err = invalid_char(args[1]); |
| 6796 | if (err) { |
| 6797 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6798 | file, linenum, *err, args[0], args[1]); |
| 6799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6800 | goto out; |
| 6801 | } |
| 6802 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6803 | if (!userlist) |
| 6804 | goto out; |
| 6805 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6806 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6807 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6808 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6809 | file, linenum, args[1], userlist->name); |
| 6810 | err_code |= ERR_ALERT; |
| 6811 | goto out; |
| 6812 | } |
| 6813 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6814 | ag = calloc(1, sizeof(*ag)); |
| 6815 | if (!ag) { |
| 6816 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6817 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6818 | goto out; |
| 6819 | } |
| 6820 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6821 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6822 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6823 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6824 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6825 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6826 | goto out; |
| 6827 | } |
| 6828 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6829 | cur_arg = 2; |
| 6830 | |
| 6831 | while (*args[cur_arg]) { |
| 6832 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6833 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6834 | cur_arg += 2; |
| 6835 | continue; |
| 6836 | } else { |
| 6837 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6838 | file, linenum, args[0]); |
| 6839 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6840 | free(ag->groupusers); |
| 6841 | free(ag->name); |
| 6842 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6843 | goto out; |
| 6844 | } |
| 6845 | } |
| 6846 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6847 | ag->next = userlist->groups; |
| 6848 | userlist->groups = ag; |
| 6849 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6850 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6851 | struct auth_users *newuser; |
| 6852 | int cur_arg; |
| 6853 | |
| 6854 | if (!*args[1]) { |
| 6855 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6856 | file, linenum, args[0]); |
| 6857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6858 | goto out; |
| 6859 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6860 | if (!userlist) |
| 6861 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6862 | |
| 6863 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6864 | if (!strcmp(newuser->user, args[1])) { |
| 6865 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6866 | file, linenum, args[1], userlist->name); |
| 6867 | err_code |= ERR_ALERT; |
| 6868 | goto out; |
| 6869 | } |
| 6870 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6871 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6872 | if (!newuser) { |
| 6873 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6874 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6875 | goto out; |
| 6876 | } |
| 6877 | |
| 6878 | newuser->user = strdup(args[1]); |
| 6879 | |
| 6880 | newuser->next = userlist->users; |
| 6881 | userlist->users = newuser; |
| 6882 | |
| 6883 | cur_arg = 2; |
| 6884 | |
| 6885 | while (*args[cur_arg]) { |
| 6886 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6887 | #ifdef CONFIG_HAP_CRYPT |
| 6888 | if (!crypt("", args[cur_arg + 1])) { |
| 6889 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6890 | file, linenum, newuser->user); |
| 6891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6892 | goto out; |
| 6893 | } |
| 6894 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6895 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6896 | file, linenum); |
| 6897 | err_code |= ERR_ALERT; |
| 6898 | #endif |
| 6899 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6900 | cur_arg += 2; |
| 6901 | continue; |
| 6902 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6903 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6904 | newuser->flags |= AU_O_INSECURE; |
| 6905 | cur_arg += 2; |
| 6906 | continue; |
| 6907 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6908 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6909 | cur_arg += 2; |
| 6910 | continue; |
| 6911 | } else { |
| 6912 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6913 | file, linenum, args[0]); |
| 6914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6915 | goto out; |
| 6916 | } |
| 6917 | } |
| 6918 | } else { |
| 6919 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6921 | } |
| 6922 | |
| 6923 | out: |
| 6924 | return err_code; |
| 6925 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6926 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6927 | int |
| 6928 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6929 | { |
| 6930 | char *beg, *end, *scope = NULL; |
| 6931 | int err_code = 0; |
| 6932 | const char *err; |
| 6933 | |
| 6934 | beg = line + 1; |
| 6935 | end = strchr(beg, ']'); |
| 6936 | |
| 6937 | /* Detect end of scope declaration */ |
| 6938 | if (!end || end == beg) { |
| 6939 | Alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 6940 | file, linenum); |
| 6941 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6942 | goto out; |
| 6943 | } |
| 6944 | |
| 6945 | /* Get scope name and check its validity */ |
| 6946 | scope = my_strndup(beg, end-beg); |
| 6947 | err = invalid_char(scope); |
| 6948 | if (err) { |
| 6949 | Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 6950 | file, linenum, *err); |
| 6951 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6952 | goto out; |
| 6953 | } |
| 6954 | |
| 6955 | /* Be sure to have a scope declaration alone on its line */ |
| 6956 | line = end+1; |
| 6957 | while (isspace((unsigned char)*line)) |
| 6958 | line++; |
| 6959 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
| 6960 | Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 6961 | file, linenum, *line); |
| 6962 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6963 | goto out; |
| 6964 | } |
| 6965 | |
| 6966 | /* We have a valid scope declaration, save it */ |
| 6967 | free(cfg_scope); |
| 6968 | cfg_scope = scope; |
| 6969 | scope = NULL; |
| 6970 | |
| 6971 | out: |
| 6972 | free(scope); |
| 6973 | return err_code; |
| 6974 | } |
| 6975 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6976 | /* |
| 6977 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6978 | * Returns the error code, 0 if OK, or any combination of : |
| 6979 | * - ERR_ABORT: must abort ASAP |
| 6980 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6981 | * - ERR_WARN: a warning has been emitted |
| 6982 | * - ERR_ALERT: an alert has been emitted |
| 6983 | * Only the two first ones can stop processing, the two others are just |
| 6984 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6985 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 6986 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6987 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6988 | char *thisline; |
| 6989 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6990 | FILE *f; |
| 6991 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6992 | int err_code = 0; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 6993 | struct cfg_section *cs = NULL, *pcs = NULL; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6994 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6995 | int readbytes = 0; |
| 6996 | |
| 6997 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6998 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6999 | return -1; |
| 7000 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7001 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7002 | if ((f=fopen(file,"r")) == NULL) { |
| 7003 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7004 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7005 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7006 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7007 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7008 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7009 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7010 | char *end; |
| 7011 | char *args[MAX_LINE_ARGS + 1]; |
| 7012 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7013 | int dquote = 0; /* double quote */ |
| 7014 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7015 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7016 | linenum++; |
| 7017 | |
| 7018 | end = line + strlen(line); |
| 7019 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7020 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7021 | /* Check if we reached the limit and the last char is not \n. |
| 7022 | * Watch out for the last line without the terminating '\n'! |
| 7023 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7024 | char *newline; |
| 7025 | int newlinesize = linesize * 2; |
| 7026 | |
| 7027 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7028 | if (newline == NULL) { |
| 7029 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7030 | file, linenum); |
| 7031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7032 | continue; |
| 7033 | } |
| 7034 | |
| 7035 | readbytes = linesize - 1; |
| 7036 | linesize = newlinesize; |
| 7037 | thisline = newline; |
| 7038 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7039 | } |
| 7040 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7041 | readbytes = 0; |
| 7042 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7043 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7044 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7045 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7046 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7047 | |
| 7048 | if (*line == '[') {/* This is the begining if a scope */ |
| 7049 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7050 | goto next_line; |
| 7051 | } |
| 7052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7053 | arg = 0; |
| 7054 | args[arg] = line; |
| 7055 | |
| 7056 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7057 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7058 | if (dquote) |
| 7059 | dquote = 0; |
| 7060 | else |
| 7061 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7062 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7063 | end--; |
| 7064 | } |
| 7065 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7066 | if (squote) |
| 7067 | squote = 0; |
| 7068 | else |
| 7069 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7070 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7071 | end--; |
| 7072 | } |
| 7073 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7074 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7075 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7076 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7077 | int skip = 0; |
| 7078 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7079 | *line = line[1]; |
| 7080 | skip = 1; |
| 7081 | } |
| 7082 | else if (line[1] == 'r') { |
| 7083 | *line = '\r'; |
| 7084 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7085 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7086 | else if (line[1] == 'n') { |
| 7087 | *line = '\n'; |
| 7088 | skip = 1; |
| 7089 | } |
| 7090 | else if (line[1] == 't') { |
| 7091 | *line = '\t'; |
| 7092 | skip = 1; |
| 7093 | } |
| 7094 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7095 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7096 | unsigned char hex1, hex2; |
| 7097 | hex1 = toupper(line[2]) - '0'; |
| 7098 | hex2 = toupper(line[3]) - '0'; |
| 7099 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7100 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7101 | *line = (hex1<<4) + hex2; |
| 7102 | skip = 3; |
| 7103 | } |
| 7104 | else { |
| 7105 | 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] | 7106 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7107 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7108 | } else if (line[1] == '"') { |
| 7109 | *line = '"'; |
| 7110 | skip = 1; |
| 7111 | } else if (line[1] == '\'') { |
| 7112 | *line = '\''; |
| 7113 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7114 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7115 | *line = '$'; |
| 7116 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7117 | } |
| 7118 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7119 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7120 | end -= skip; |
| 7121 | } |
| 7122 | line++; |
| 7123 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7124 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7125 | /* end of string, end of loop */ |
| 7126 | *line = 0; |
| 7127 | break; |
| 7128 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7129 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7130 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7131 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7132 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7133 | line++; |
| 7134 | args[++arg] = line; |
| 7135 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7136 | else if (dquote && *line == '$') { |
| 7137 | /* environment variables are evaluated inside double quotes */ |
| 7138 | char *var_beg; |
| 7139 | char *var_end; |
| 7140 | char save_char; |
| 7141 | char *value; |
| 7142 | int val_len; |
| 7143 | int newlinesize; |
| 7144 | int braces = 0; |
| 7145 | |
| 7146 | var_beg = line + 1; |
| 7147 | var_end = var_beg; |
| 7148 | |
| 7149 | if (*var_beg == '{') { |
| 7150 | var_beg++; |
| 7151 | var_end++; |
| 7152 | braces = 1; |
| 7153 | } |
| 7154 | |
| 7155 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7156 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7158 | goto next_line; /* skip current line */ |
| 7159 | } |
| 7160 | |
| 7161 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7162 | var_end++; |
| 7163 | |
| 7164 | save_char = *var_end; |
| 7165 | *var_end = '\0'; |
| 7166 | value = getenv(var_beg); |
| 7167 | *var_end = save_char; |
| 7168 | val_len = value ? strlen(value) : 0; |
| 7169 | |
| 7170 | if (braces) { |
| 7171 | if (*var_end == '}') { |
| 7172 | var_end++; |
| 7173 | braces = 0; |
| 7174 | } else { |
| 7175 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7177 | goto next_line; /* skip current line */ |
| 7178 | } |
| 7179 | } |
| 7180 | |
| 7181 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7182 | |
| 7183 | /* if not enough space in thisline */ |
| 7184 | if (newlinesize > linesize) { |
| 7185 | char *newline; |
| 7186 | |
| 7187 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7188 | if (newline == NULL) { |
| 7189 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7191 | goto next_line; /* slip current line */ |
| 7192 | } |
| 7193 | /* recompute pointers if realloc returns a new pointer */ |
| 7194 | if (newline != thisline) { |
| 7195 | int i; |
| 7196 | int diff; |
| 7197 | |
| 7198 | for (i = 0; i <= arg; i++) { |
| 7199 | diff = args[i] - thisline; |
| 7200 | args[i] = newline + diff; |
| 7201 | } |
| 7202 | |
| 7203 | diff = var_end - thisline; |
| 7204 | var_end = newline + diff; |
| 7205 | diff = end - thisline; |
| 7206 | end = newline + diff; |
| 7207 | diff = line - thisline; |
| 7208 | line = newline + diff; |
| 7209 | thisline = newline; |
| 7210 | } |
| 7211 | linesize = newlinesize; |
| 7212 | } |
| 7213 | |
| 7214 | /* insert value inside the line */ |
| 7215 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7216 | memcpy(line, value, val_len); |
| 7217 | end += val_len - (var_end - line); |
| 7218 | line += val_len; |
| 7219 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7220 | else { |
| 7221 | line++; |
| 7222 | } |
| 7223 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7224 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7225 | if (dquote) { |
| 7226 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7228 | } |
| 7229 | |
| 7230 | if (squote) { |
| 7231 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7233 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7234 | |
| 7235 | /* empty line */ |
| 7236 | if (!**args) |
| 7237 | continue; |
| 7238 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7239 | if (*line) { |
| 7240 | /* we had to stop due to too many args. |
| 7241 | * Let's terminate the string, print the offending part then cut the |
| 7242 | * last arg. |
| 7243 | */ |
| 7244 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7245 | line++; |
| 7246 | *line = '\0'; |
| 7247 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7248 | 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] | 7249 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7251 | args[arg] = line; |
| 7252 | } |
| 7253 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7254 | /* zero out remaining args and ensure that at least one entry |
| 7255 | * is zeroed out. |
| 7256 | */ |
| 7257 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7258 | args[arg] = line; |
| 7259 | } |
| 7260 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7261 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7262 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7263 | char *tmp; |
| 7264 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7265 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7266 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7267 | for (arg=0; *args[arg+1]; arg++) |
| 7268 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7269 | *tmp = '\0'; // fix the next arg to \0 |
| 7270 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7271 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7272 | else if (!strcmp(args[0], "default")) { |
| 7273 | kwm = KWM_DEF; |
| 7274 | for (arg=0; *args[arg+1]; arg++) |
| 7275 | args[arg] = args[arg+1]; // shift args after inversion |
| 7276 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7277 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7278 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7279 | strcmp(args[0], "log") != 0) { |
| 7280 | 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] | 7281 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7282 | } |
| 7283 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7284 | /* detect section start */ |
| 7285 | list_for_each_entry(ics, §ions, list) { |
| 7286 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7287 | cursection = ics->section_name; |
| 7288 | cs = ics; |
| 7289 | break; |
| 7290 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7291 | } |
| 7292 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7293 | if (!cs) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7294 | 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] | 7295 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7296 | } else { |
| 7297 | /* else it's a section keyword */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7298 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7299 | if (pcs != cs && pcs && pcs->post_section_parser) { |
| 7300 | err_code |= pcs->post_section_parser(); |
| 7301 | if (err_code & ERR_ABORT) |
| 7302 | goto err; |
| 7303 | } |
| 7304 | |
| 7305 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7306 | if (err_code & ERR_ABORT) |
| 7307 | goto err; |
| 7308 | } |
| 7309 | pcs = cs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7310 | } |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7311 | |
| 7312 | if (pcs == cs && pcs && pcs->post_section_parser) |
| 7313 | err_code |= pcs->post_section_parser(); |
| 7314 | |
| 7315 | err: |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7316 | free(cfg_scope); |
| 7317 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7318 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7319 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7320 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7321 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7322 | } |
| 7323 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7324 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7325 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7326 | * bound to all of its processes. After that, if the target is a "listen" |
| 7327 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7328 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7329 | * checked first to ensure that <to> is already bound to all processes of |
| 7330 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7331 | * path to the destination. |
| 7332 | * |
| 7333 | * It is possible to set <to> to NULL for the first call so that the function |
| 7334 | * takes care of visiting the initial frontend in <from>. |
| 7335 | * |
| 7336 | * It is important to note that the function relies on the fact that all names |
| 7337 | * have already been resolved. |
| 7338 | */ |
| 7339 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7340 | { |
| 7341 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7342 | |
| 7343 | if (to) { |
| 7344 | /* check whether we need to go down */ |
| 7345 | if (from->bind_proc && |
| 7346 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7347 | return; |
| 7348 | |
| 7349 | if (!from->bind_proc && !to->bind_proc) |
| 7350 | return; |
| 7351 | |
| 7352 | to->bind_proc = from->bind_proc ? |
| 7353 | (to->bind_proc | from->bind_proc) : 0; |
| 7354 | |
| 7355 | /* now propagate down */ |
| 7356 | from = to; |
| 7357 | } |
| 7358 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7359 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7360 | return; |
| 7361 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7362 | if (from->state == PR_STSTOPPED) |
| 7363 | return; |
| 7364 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7365 | /* default_backend */ |
| 7366 | if (from->defbe.be) |
| 7367 | propagate_processes(from, from->defbe.be); |
| 7368 | |
| 7369 | /* use_backend */ |
| 7370 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7371 | if (rule->dynamic) |
| 7372 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7373 | to = rule->be.backend; |
| 7374 | propagate_processes(from, to); |
| 7375 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7376 | } |
| 7377 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7378 | /* |
| 7379 | * Returns the error code, 0 if OK, or any combination of : |
| 7380 | * - ERR_ABORT: must abort ASAP |
| 7381 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7382 | * - ERR_WARN: a warning has been emitted |
| 7383 | * - ERR_ALERT: an alert has been emitted |
| 7384 | * Only the two first ones can stop processing, the two others are just |
| 7385 | * indicators. |
| 7386 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7387 | int check_config_validity() |
| 7388 | { |
| 7389 | int cfgerr = 0; |
| 7390 | struct proxy *curproxy = NULL; |
| 7391 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7392 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7393 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7394 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7395 | char *err; |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 7396 | struct cfg_postparser *postparser; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7397 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7398 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7399 | /* |
| 7400 | * Now, check for the integrity of all that we have collected. |
| 7401 | */ |
| 7402 | |
| 7403 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7404 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7405 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7406 | if (!global.tune.max_http_hdr) |
| 7407 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7408 | |
| 7409 | if (!global.tune.cookie_len) |
| 7410 | global.tune.cookie_len = CAPTURE_LEN; |
| 7411 | |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 7412 | if (!global.tune.requri_len) |
| 7413 | global.tune.requri_len = REQURI_LEN; |
| 7414 | |
Emeric Brun | 96fd926 | 2017-07-05 13:33:16 +0200 | [diff] [blame] | 7415 | pool2_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED); |
| 7416 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7417 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7418 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7419 | /* Post initialisation of the users and groups lists. */ |
| 7420 | err_code = userlist_postinit(); |
| 7421 | if (err_code != ERR_NONE) |
| 7422 | goto out; |
| 7423 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7424 | /* first, we will invert the proxy list order */ |
| 7425 | curproxy = NULL; |
| 7426 | while (proxy) { |
| 7427 | struct proxy *next; |
| 7428 | |
| 7429 | next = proxy->next; |
| 7430 | proxy->next = curproxy; |
| 7431 | curproxy = proxy; |
| 7432 | if (!next) |
| 7433 | break; |
| 7434 | proxy = next; |
| 7435 | } |
| 7436 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7437 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7438 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7439 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7440 | struct sticking_rule *mrule; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7441 | struct act_rule *arule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7442 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7443 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7444 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7445 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7446 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7447 | /* proxy ID not set, use automatic numbering with first |
| 7448 | * spare entry starting with next_pxid. |
| 7449 | */ |
| 7450 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7451 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7452 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7453 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7454 | next_pxid++; |
| 7455 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7456 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7457 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7458 | /* ensure we don't keep listeners uselessly bound */ |
| 7459 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7460 | free((void *)curproxy->table.peers.name); |
| 7461 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7462 | continue; |
| 7463 | } |
| 7464 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7465 | /* Check multi-process mode compatibility for the current proxy */ |
| 7466 | |
| 7467 | if (curproxy->bind_proc) { |
| 7468 | /* an explicit bind-process was specified, let's check how many |
| 7469 | * processes remain. |
| 7470 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7471 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7472 | |
| 7473 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7474 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7475 | 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); |
| 7476 | curproxy->bind_proc = 1; |
| 7477 | } |
| 7478 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7479 | 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); |
| 7480 | curproxy->bind_proc = 0; |
| 7481 | } |
| 7482 | } |
| 7483 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7484 | /* check and reduce the bind-proc of each listener */ |
| 7485 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7486 | unsigned long mask; |
| 7487 | |
| 7488 | if (!bind_conf->bind_proc) |
| 7489 | continue; |
| 7490 | |
| 7491 | mask = nbits(global.nbproc); |
| 7492 | if (curproxy->bind_proc) |
| 7493 | mask &= curproxy->bind_proc; |
| 7494 | /* mask cannot be null here thanks to the previous checks */ |
| 7495 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7496 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7497 | bind_conf->bind_proc &= mask; |
| 7498 | |
| 7499 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7500 | 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", |
| 7501 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7502 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7503 | } |
| 7504 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7505 | 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", |
| 7506 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7507 | bind_conf->bind_proc = 0; |
| 7508 | } |
| 7509 | } |
| 7510 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7511 | switch (curproxy->mode) { |
| 7512 | case PR_MODE_HEALTH: |
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 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7515 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7516 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7517 | cfgerr++; |
| 7518 | } |
| 7519 | |
| 7520 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7521 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7522 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7523 | break; |
| 7524 | |
| 7525 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7526 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7527 | break; |
| 7528 | |
| 7529 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7530 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7531 | break; |
| 7532 | } |
| 7533 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7534 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7535 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7536 | proxy_type_str(curproxy), curproxy->id); |
| 7537 | err_code |= ERR_WARN; |
| 7538 | } |
| 7539 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7540 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7541 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7542 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7543 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7544 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7545 | cfgerr++; |
| 7546 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7547 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7548 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7549 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7550 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7551 | cfgerr++; |
| 7552 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7553 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7554 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7555 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7556 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7557 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7558 | } |
| 7559 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7560 | 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] | 7561 | /* If no LB algo is set in a backend, and we're not in |
| 7562 | * transparent mode, dispatch mode nor proxy mode, we |
| 7563 | * want to use balance roundrobin by default. |
| 7564 | */ |
| 7565 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7566 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7567 | } |
| 7568 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7569 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7570 | if (curproxy->options & PR_O_DISPATCH) |
| 7571 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7572 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7573 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7574 | else if (curproxy->options & PR_O_TRANSP) |
| 7575 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7576 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7577 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7578 | if (curproxy->options & PR_O_DISABLE404) { |
| 7579 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7580 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7581 | err_code |= ERR_WARN; |
| 7582 | curproxy->options &= ~PR_O_DISABLE404; |
| 7583 | } |
| 7584 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7585 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7586 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7587 | err_code |= ERR_WARN; |
| 7588 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7589 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7590 | } |
| 7591 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7592 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7593 | if (!global.external_check) { |
| 7594 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7595 | curproxy->id, "option external-check"); |
| 7596 | cfgerr++; |
| 7597 | } |
| 7598 | if (!curproxy->check_command) { |
| 7599 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7600 | curproxy->id, "option external-check"); |
| 7601 | cfgerr++; |
| 7602 | } |
| 7603 | } |
| 7604 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7605 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7606 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7607 | 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] | 7608 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7609 | "'email-alert myhostname', or 'email-alert to' " |
| 7610 | "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] | 7611 | "to be present).\n", |
| 7612 | proxy_type_str(curproxy), curproxy->id); |
| 7613 | err_code |= ERR_WARN; |
| 7614 | free_email_alert(curproxy); |
| 7615 | } |
| 7616 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7617 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7618 | } |
| 7619 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7620 | if (curproxy->check_command) { |
| 7621 | int clear = 0; |
| 7622 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7623 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7624 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7625 | err_code |= ERR_WARN; |
| 7626 | clear = 1; |
| 7627 | } |
| 7628 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7629 | 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] | 7630 | curproxy->id, "external-check command"); |
| 7631 | cfgerr++; |
| 7632 | } |
| 7633 | if (clear) { |
| 7634 | free(curproxy->check_command); |
| 7635 | curproxy->check_command = NULL; |
| 7636 | } |
| 7637 | } |
| 7638 | |
| 7639 | if (curproxy->check_path) { |
| 7640 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7641 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7642 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7643 | err_code |= ERR_WARN; |
| 7644 | free(curproxy->check_path); |
| 7645 | curproxy->check_path = NULL; |
| 7646 | } |
| 7647 | } |
| 7648 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7649 | /* if a default backend was specified, let's find it */ |
| 7650 | if (curproxy->defbe.name) { |
| 7651 | struct proxy *target; |
| 7652 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7653 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7654 | if (!target) { |
| 7655 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7656 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7657 | cfgerr++; |
| 7658 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7659 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7660 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7661 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7662 | } else if (target->mode != curproxy->mode && |
| 7663 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7664 | |
| 7665 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7666 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7667 | curproxy->conf.file, curproxy->conf.line, |
| 7668 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7669 | target->conf.file, target->conf.line); |
| 7670 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7671 | } else { |
| 7672 | free(curproxy->defbe.name); |
| 7673 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7674 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7675 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7676 | /* Emit a warning if this proxy also has some servers */ |
| 7677 | if (curproxy->srv) { |
| 7678 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7679 | curproxy->id); |
| 7680 | err_code |= ERR_WARN; |
| 7681 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7682 | } |
| 7683 | } |
| 7684 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7685 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7686 | /* Case of listen without default backend |
| 7687 | * The curproxy will be its own default backend |
| 7688 | * so we update tot_fe_maxconn for a further |
| 7689 | * fullconn's computation */ |
| 7690 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7691 | } |
| 7692 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7693 | /* find the target proxy for 'use_backend' rules */ |
| 7694 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7695 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7696 | struct logformat_node *node; |
| 7697 | char *pxname; |
| 7698 | |
| 7699 | /* Try to parse the string as a log format expression. If the result |
| 7700 | * of the parsing is only one entry containing a simple string, then |
| 7701 | * it's a standard string corresponding to a static rule, thus the |
| 7702 | * parsing is cancelled and be.name is restored to be resolved. |
| 7703 | */ |
| 7704 | pxname = rule->be.name; |
| 7705 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7706 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7707 | curproxy->conf.args.file = rule->file; |
| 7708 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7709 | err = NULL; |
| 7710 | if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
| 7711 | Alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7712 | rule->file, rule->line, pxname, err); |
| 7713 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7714 | cfgerr++; |
| 7715 | continue; |
| 7716 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7717 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7718 | |
| 7719 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7720 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7721 | rule->dynamic = 1; |
| 7722 | free(pxname); |
| 7723 | continue; |
| 7724 | } |
| 7725 | /* simple string: free the expression and fall back to static rule */ |
| 7726 | free(node->arg); |
| 7727 | free(node); |
| 7728 | } |
| 7729 | |
| 7730 | rule->dynamic = 0; |
| 7731 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7732 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7733 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7734 | if (!target) { |
| 7735 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7736 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7737 | cfgerr++; |
| 7738 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7739 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7740 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7741 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7742 | } else if (target->mode != curproxy->mode && |
| 7743 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7744 | |
| 7745 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7746 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7747 | curproxy->conf.file, curproxy->conf.line, |
| 7748 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7749 | target->conf.file, target->conf.line); |
| 7750 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7751 | } else { |
| 7752 | free((void *)rule->be.name); |
| 7753 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7754 | /* For each target of switching rules, we update |
| 7755 | * their tot_fe_maxconn, except if a previous rule point |
| 7756 | * on the same backend or on the default backend */ |
| 7757 | if (rule->be.backend != curproxy->defbe.be) { |
| 7758 | struct switching_rule *swrule; |
| 7759 | |
| 7760 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7761 | if (rule == swrule) { |
| 7762 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7763 | break; |
| 7764 | } |
| 7765 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7766 | /* there is multiple ref of this backend */ |
| 7767 | break; |
| 7768 | } |
| 7769 | } |
| 7770 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7771 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7772 | } |
| 7773 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7774 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7775 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7776 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7777 | |
| 7778 | if (!target) { |
| 7779 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7780 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7781 | cfgerr++; |
| 7782 | continue; |
| 7783 | } |
| 7784 | free((void *)srule->srv.name); |
| 7785 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7786 | } |
| 7787 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7788 | /* find the target table for 'stick' rules */ |
| 7789 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7790 | struct proxy *target; |
| 7791 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7792 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7793 | if (mrule->flags & STK_IS_STORE) |
| 7794 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7795 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7796 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7797 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7798 | else |
| 7799 | target = curproxy; |
| 7800 | |
| 7801 | if (!target) { |
| 7802 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7803 | curproxy->id, mrule->table.name); |
| 7804 | cfgerr++; |
| 7805 | } |
| 7806 | else if (target->table.size == 0) { |
| 7807 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7808 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7809 | cfgerr++; |
| 7810 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7811 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7812 | 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] | 7813 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7814 | cfgerr++; |
| 7815 | } |
| 7816 | else { |
| 7817 | free((void *)mrule->table.name); |
| 7818 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7819 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7820 | } |
| 7821 | } |
| 7822 | |
| 7823 | /* find the target table for 'store response' rules */ |
| 7824 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7825 | struct proxy *target; |
| 7826 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7827 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7828 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7829 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7830 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7831 | else |
| 7832 | target = curproxy; |
| 7833 | |
| 7834 | if (!target) { |
| 7835 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7836 | curproxy->id, mrule->table.name); |
| 7837 | cfgerr++; |
| 7838 | } |
| 7839 | else if (target->table.size == 0) { |
| 7840 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7841 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7842 | cfgerr++; |
| 7843 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7844 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7845 | 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] | 7846 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7847 | cfgerr++; |
| 7848 | } |
| 7849 | else { |
| 7850 | free((void *)mrule->table.name); |
| 7851 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7852 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7853 | } |
| 7854 | } |
| 7855 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7856 | /* check validity for 'tcp-request' layer 4 rules */ |
| 7857 | list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) { |
| 7858 | err = NULL; |
| 7859 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
| 7860 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7861 | free(err); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7862 | cfgerr++; |
| 7863 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7864 | } |
| 7865 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7866 | /* check validity for 'tcp-request' layer 5 rules */ |
| 7867 | list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) { |
| 7868 | err = NULL; |
| 7869 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
| 7870 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7871 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7872 | cfgerr++; |
| 7873 | } |
| 7874 | } |
| 7875 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7876 | /* check validity for 'tcp-request' layer 6 rules */ |
| 7877 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 7878 | err = NULL; |
| 7879 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
| 7880 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7881 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7882 | cfgerr++; |
| 7883 | } |
| 7884 | } |
| 7885 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7886 | /* check validity for 'http-request' layer 7 rules */ |
| 7887 | list_for_each_entry(arule, &curproxy->http_req_rules, list) { |
| 7888 | err = NULL; |
| 7889 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
| 7890 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7891 | free(err); |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7892 | cfgerr++; |
| 7893 | } |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7894 | } |
| 7895 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7896 | /* check validity for 'http-response' layer 7 rules */ |
| 7897 | list_for_each_entry(arule, &curproxy->http_res_rules, list) { |
| 7898 | err = NULL; |
| 7899 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
| 7900 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7901 | free(err); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7902 | cfgerr++; |
| 7903 | } |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7904 | } |
| 7905 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 7906 | /* move any "block" rules at the beginning of the http-request rules */ |
| 7907 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 7908 | /* insert block_rules into http_req_rules at the beginning */ |
| 7909 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 7910 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 7911 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 7912 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 7913 | LIST_INIT(&curproxy->block_rules); |
| 7914 | } |
| 7915 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7916 | if (curproxy->table.peers.name) { |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 7917 | struct peers *curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7918 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 7919 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7920 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 7921 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 7922 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7923 | break; |
| 7924 | } |
| 7925 | } |
| 7926 | |
| 7927 | if (!curpeers) { |
| 7928 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 7929 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7930 | free((void *)curproxy->table.peers.name); |
| 7931 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7932 | cfgerr++; |
| 7933 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7934 | else if (curpeers->state == PR_STSTOPPED) { |
| 7935 | /* silently disable this peers section */ |
| 7936 | curproxy->table.peers.p = NULL; |
| 7937 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7938 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7939 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 7940 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7941 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7942 | cfgerr++; |
| 7943 | } |
| 7944 | } |
| 7945 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7946 | |
| 7947 | if (curproxy->email_alert.mailers.name) { |
| 7948 | struct mailers *curmailers = mailers; |
| 7949 | |
| 7950 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 7951 | if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name)) |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7952 | break; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7953 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7954 | if (!curmailers) { |
| 7955 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 7956 | curproxy->id, curproxy->email_alert.mailers.name); |
| 7957 | free_email_alert(curproxy); |
| 7958 | cfgerr++; |
| 7959 | } |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 7960 | else { |
| 7961 | err = NULL; |
| 7962 | if (init_email_alert(curmailers, curproxy, &err)) { |
| 7963 | Alert("Proxy '%s': %s.\n", curproxy->id, err); |
| 7964 | free(err); |
| 7965 | cfgerr++; |
| 7966 | } |
| 7967 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7968 | } |
| 7969 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 7970 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7971 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7972 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 7973 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 7974 | "proxy", curproxy->id); |
| 7975 | cfgerr++; |
| 7976 | goto out_uri_auth_compat; |
| 7977 | } |
| 7978 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 7979 | 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] | 7980 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7981 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7982 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7983 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7984 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 7985 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7986 | |
| 7987 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7988 | uri_auth_compat_req[i++] = "realm"; |
| 7989 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 7990 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7991 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 7992 | uri_auth_compat_req[i++] = "unless"; |
| 7993 | uri_auth_compat_req[i++] = "{"; |
| 7994 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 7995 | uri_auth_compat_req[i++] = "}"; |
| 7996 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 7997 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 7998 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 7999 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8000 | cfgerr++; |
| 8001 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8002 | } |
| 8003 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8004 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8005 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8006 | if (curproxy->uri_auth->auth_realm) { |
| 8007 | free(curproxy->uri_auth->auth_realm); |
| 8008 | curproxy->uri_auth->auth_realm = NULL; |
| 8009 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8010 | |
| 8011 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8012 | } |
| 8013 | out_uri_auth_compat: |
| 8014 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8015 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8016 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8017 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8018 | if (!curproxy->conf.logformat_sd_string) { |
| 8019 | /* set the default logformat_sd_string */ |
| 8020 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8021 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8022 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8023 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8024 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8025 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8026 | /* compile the log format */ |
| 8027 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8028 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8029 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8030 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8031 | free(curproxy->conf.logformat_string); |
| 8032 | curproxy->conf.logformat_string = NULL; |
| 8033 | free(curproxy->conf.lfs_file); |
| 8034 | curproxy->conf.lfs_file = NULL; |
| 8035 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8036 | |
| 8037 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8038 | free(curproxy->conf.logformat_sd_string); |
| 8039 | curproxy->conf.logformat_sd_string = NULL; |
| 8040 | free(curproxy->conf.lfsd_file); |
| 8041 | curproxy->conf.lfsd_file = NULL; |
| 8042 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8043 | } |
| 8044 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8045 | if (curproxy->conf.logformat_string) { |
| 8046 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8047 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8048 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8049 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8050 | 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] | 8051 | SMP_VAL_FE_LOG_END, &err)) { |
| 8052 | Alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8053 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8054 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8055 | cfgerr++; |
| 8056 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8057 | curproxy->conf.args.file = NULL; |
| 8058 | curproxy->conf.args.line = 0; |
| 8059 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8060 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8061 | if (curproxy->conf.logformat_sd_string) { |
| 8062 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8063 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8064 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8065 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8066 | 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] | 8067 | SMP_VAL_FE_LOG_END, &err)) { |
| 8068 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8069 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8070 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8071 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8072 | } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) { |
| 8073 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8074 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8075 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8076 | cfgerr++; |
| 8077 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8078 | curproxy->conf.args.file = NULL; |
| 8079 | curproxy->conf.args.line = 0; |
| 8080 | } |
| 8081 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8082 | if (curproxy->conf.uniqueid_format_string) { |
| 8083 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8084 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8085 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8086 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8087 | 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] | 8088 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) { |
| 8089 | Alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8090 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
| 8091 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8092 | cfgerr++; |
| 8093 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8094 | curproxy->conf.args.file = NULL; |
| 8095 | curproxy->conf.args.line = 0; |
| 8096 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8097 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8098 | /* only now we can check if some args remain unresolved. |
| 8099 | * This must be done after the users and groups resolution. |
| 8100 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8101 | cfgerr += smp_resolve_args(curproxy); |
| 8102 | if (!cfgerr) |
| 8103 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8104 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8105 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8106 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8107 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8108 | (!curproxy->timeout.connect || |
| 8109 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8110 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8111 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8112 | " | 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] | 8113 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8114 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8115 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8116 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8117 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8118 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8119 | * We must still support older configurations, so let's find out whether those |
| 8120 | * parameters have been set or must be copied from contimeouts. |
| 8121 | */ |
| 8122 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8123 | if (!curproxy->timeout.tarpit || |
| 8124 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8125 | /* tarpit timeout not set. We search in the following order: |
| 8126 | * default.tarpit, curr.connect, default.connect. |
| 8127 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8128 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8129 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8130 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8131 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8132 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8133 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8134 | } |
| 8135 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8136 | (!curproxy->timeout.queue || |
| 8137 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8138 | /* queue timeout not set. We search in the following order: |
| 8139 | * default.queue, curr.connect, default.connect. |
| 8140 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8141 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8142 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8143 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8144 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8145 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8146 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8147 | } |
| 8148 | } |
| 8149 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8150 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8151 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8152 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8153 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8154 | } |
| 8155 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8156 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8157 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8158 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8159 | proxy_type_str(curproxy), curproxy->id); |
| 8160 | err_code |= ERR_WARN; |
| 8161 | } |
| 8162 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8163 | /* ensure that cookie capture length is not too large */ |
| 8164 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8165 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8166 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8167 | err_code |= ERR_WARN; |
| 8168 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8169 | } |
| 8170 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8171 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8172 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8173 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8174 | curproxy->nb_req_cap * sizeof(char *), |
| 8175 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8176 | } |
| 8177 | |
| 8178 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8179 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8180 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8181 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8182 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8183 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8184 | switch (curproxy->load_server_state_from_file) { |
| 8185 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8186 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8187 | break; |
| 8188 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8189 | if (!global.server_state_file) { |
| 8190 | 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", |
| 8191 | curproxy->id); |
| 8192 | err_code |= ERR_WARN; |
| 8193 | } |
| 8194 | break; |
| 8195 | } |
| 8196 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8197 | /* first, we will invert the servers list order */ |
| 8198 | newsrv = NULL; |
| 8199 | while (curproxy->srv) { |
| 8200 | struct server *next; |
| 8201 | |
| 8202 | next = curproxy->srv->next; |
| 8203 | curproxy->srv->next = newsrv; |
| 8204 | newsrv = curproxy->srv; |
| 8205 | if (!next) |
| 8206 | break; |
| 8207 | curproxy->srv = next; |
| 8208 | } |
| 8209 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8210 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8211 | * We only emit a warning for the first conflict affecting each server, |
| 8212 | * in order to avoid combinatory explosion if all servers have the same |
| 8213 | * name. We do that only for servers which do not have an explicit ID, |
| 8214 | * because these IDs were made also for distinguishing them and we don't |
| 8215 | * want to annoy people who correctly manage them. |
| 8216 | */ |
| 8217 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8218 | struct server *other_srv; |
| 8219 | |
| 8220 | if (newsrv->puid) |
| 8221 | continue; |
| 8222 | |
| 8223 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8224 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8225 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8226 | newsrv->conf.file, newsrv->conf.line, |
| 8227 | proxy_type_str(curproxy), curproxy->id, |
| 8228 | newsrv->id, other_srv->conf.line); |
| 8229 | break; |
| 8230 | } |
| 8231 | } |
| 8232 | } |
| 8233 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8234 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8235 | next_id = 1; |
| 8236 | newsrv = curproxy->srv; |
| 8237 | while (newsrv != NULL) { |
| 8238 | if (!newsrv->puid) { |
| 8239 | /* server ID not set, use automatic numbering with first |
| 8240 | * spare entry starting with next_svid. |
| 8241 | */ |
| 8242 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8243 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8244 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8245 | } |
| 8246 | next_id++; |
| 8247 | newsrv = newsrv->next; |
| 8248 | } |
| 8249 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8250 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8251 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8252 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8253 | /* |
| 8254 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8255 | * tasks to fill the emptied slots when a connection leaves. |
| 8256 | * Also, resolve deferred tracking dependency if needed. |
| 8257 | */ |
| 8258 | newsrv = curproxy->srv; |
| 8259 | while (newsrv != NULL) { |
| 8260 | if (newsrv->minconn > newsrv->maxconn) { |
| 8261 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8262 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8263 | * this will avoid further useless expensive computations. |
| 8264 | */ |
| 8265 | newsrv->maxconn = newsrv->minconn; |
| 8266 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8267 | /* minconn was not specified, so we set it to maxconn */ |
| 8268 | newsrv->minconn = newsrv->maxconn; |
| 8269 | } |
| 8270 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8271 | /* this will also properly set the transport layer for prod and checks */ |
| 8272 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8273 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8274 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8275 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8276 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8277 | /* set the check type on the server */ |
| 8278 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8279 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8280 | if (newsrv->trackit) { |
| 8281 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8282 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8283 | char *pname, *sname; |
| 8284 | |
| 8285 | pname = newsrv->trackit; |
| 8286 | sname = strrchr(pname, '/'); |
| 8287 | |
| 8288 | if (sname) |
| 8289 | *sname++ = '\0'; |
| 8290 | else { |
| 8291 | sname = pname; |
| 8292 | pname = NULL; |
| 8293 | } |
| 8294 | |
| 8295 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8296 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8297 | if (!px) { |
| 8298 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8299 | proxy_type_str(curproxy), curproxy->id, |
| 8300 | newsrv->id, pname); |
| 8301 | cfgerr++; |
| 8302 | goto next_srv; |
| 8303 | } |
| 8304 | } else |
| 8305 | px = curproxy; |
| 8306 | |
| 8307 | srv = findserver(px, sname); |
| 8308 | if (!srv) { |
| 8309 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8310 | proxy_type_str(curproxy), curproxy->id, |
| 8311 | newsrv->id, sname); |
| 8312 | cfgerr++; |
| 8313 | goto next_srv; |
| 8314 | } |
| 8315 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8316 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8317 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8318 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8319 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8320 | "tracking as it does not have any check nor agent enabled.\n", |
| 8321 | proxy_type_str(curproxy), curproxy->id, |
| 8322 | newsrv->id, px->id, srv->id); |
| 8323 | cfgerr++; |
| 8324 | goto next_srv; |
| 8325 | } |
| 8326 | |
| 8327 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8328 | |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8329 | if (newsrv == srv || loop) { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8330 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8331 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8332 | proxy_type_str(curproxy), curproxy->id, |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8333 | newsrv->id, px->id, srv->id, px->id, |
| 8334 | newsrv == srv ? srv->id : loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8335 | cfgerr++; |
| 8336 | goto next_srv; |
| 8337 | } |
| 8338 | |
| 8339 | if (curproxy != px && |
| 8340 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8341 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8342 | "tracking: disable-on-404 option inconsistency.\n", |
| 8343 | proxy_type_str(curproxy), curproxy->id, |
| 8344 | newsrv->id, px->id, srv->id); |
| 8345 | cfgerr++; |
| 8346 | goto next_srv; |
| 8347 | } |
| 8348 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8349 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8350 | newsrv->tracknext = srv->trackers; |
| 8351 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8352 | |
| 8353 | free(newsrv->trackit); |
| 8354 | newsrv->trackit = NULL; |
| 8355 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8356 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8357 | next_srv: |
| 8358 | newsrv = newsrv->next; |
| 8359 | } |
| 8360 | |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 8361 | /* |
| 8362 | * Try to generate dynamic cookies for servers now. |
| 8363 | * It couldn't be done earlier, since at the time we parsed |
| 8364 | * the server line, we may not have known yet that we |
| 8365 | * should use dynamic cookies, or the secret key may not |
| 8366 | * have been provided yet. |
| 8367 | */ |
| 8368 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
| 8369 | newsrv = curproxy->srv; |
| 8370 | while (newsrv != NULL) { |
| 8371 | srv_set_dyncookie(newsrv); |
| 8372 | newsrv = newsrv->next; |
| 8373 | } |
| 8374 | |
| 8375 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8376 | /* We have to initialize the server lookup mechanism depending |
| 8377 | * on what LB algorithm was choosen. |
| 8378 | */ |
| 8379 | |
| 8380 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8381 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8382 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8383 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8384 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8385 | init_server_map(curproxy); |
| 8386 | } else { |
| 8387 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8388 | fwrr_init_server_groups(curproxy); |
| 8389 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8390 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8391 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8392 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8393 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8394 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8395 | fwlc_init_server_tree(curproxy); |
| 8396 | } else { |
| 8397 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8398 | fas_init_server_tree(curproxy); |
| 8399 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8400 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8401 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8402 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8403 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8404 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8405 | chash_init_server_tree(curproxy); |
| 8406 | } else { |
| 8407 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8408 | init_server_map(curproxy); |
| 8409 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8410 | break; |
| 8411 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8412 | |
| 8413 | if (curproxy->options & PR_O_LOGASAP) |
| 8414 | curproxy->to_log &= ~LW_BYTES; |
| 8415 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8416 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8417 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8418 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8419 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8420 | proxy_type_str(curproxy), curproxy->id); |
| 8421 | err_code |= ERR_WARN; |
| 8422 | } |
| 8423 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8424 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8425 | int optnum; |
| 8426 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8427 | if (curproxy->uri_auth) { |
| 8428 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8429 | proxy_type_str(curproxy), curproxy->id); |
| 8430 | err_code |= ERR_WARN; |
| 8431 | curproxy->uri_auth = NULL; |
| 8432 | } |
| 8433 | |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8434 | if (curproxy->capture_name) { |
| 8435 | Warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8436 | proxy_type_str(curproxy), curproxy->id); |
| 8437 | err_code |= ERR_WARN; |
| 8438 | } |
| 8439 | |
| 8440 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
| 8441 | Warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8442 | proxy_type_str(curproxy), curproxy->id); |
| 8443 | err_code |= ERR_WARN; |
| 8444 | } |
| 8445 | |
| 8446 | if (!LIST_ISEMPTY(&curproxy->http_res_rules)) { |
| 8447 | Warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8448 | proxy_type_str(curproxy), curproxy->id); |
| 8449 | err_code |= ERR_WARN; |
| 8450 | } |
| 8451 | |
| 8452 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8453 | Warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8454 | proxy_type_str(curproxy), curproxy->id); |
| 8455 | err_code |= ERR_WARN; |
| 8456 | } |
| 8457 | |
| 8458 | if (!LIST_ISEMPTY(&curproxy->redirect_rules)) { |
| 8459 | Warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8460 | proxy_type_str(curproxy), curproxy->id); |
| 8461 | err_code |= ERR_WARN; |
| 8462 | } |
| 8463 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8464 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8465 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8466 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8467 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8468 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8469 | } |
| 8470 | |
| 8471 | if (curproxy->options & PR_O_ORGTO) { |
| 8472 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8473 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8474 | err_code |= ERR_WARN; |
| 8475 | curproxy->options &= ~PR_O_ORGTO; |
| 8476 | } |
| 8477 | |
| 8478 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8479 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8480 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8481 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8482 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8483 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8484 | err_code |= ERR_WARN; |
| 8485 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8486 | } |
| 8487 | } |
| 8488 | |
| 8489 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8490 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8491 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8492 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8493 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8494 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8495 | err_code |= ERR_WARN; |
| 8496 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8497 | } |
| 8498 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8499 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8500 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8501 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8502 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8503 | 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] | 8504 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8505 | err_code |= ERR_WARN; |
| 8506 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8507 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8508 | } |
| 8509 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8510 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8511 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8512 | */ |
| 8513 | newsrv = curproxy->srv; |
| 8514 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8515 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8516 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8517 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8518 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8519 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8520 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8521 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8522 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8523 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8524 | err_code |= ERR_WARN; |
| 8525 | } |
| 8526 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8527 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8528 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8529 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8530 | err_code |= ERR_WARN; |
| 8531 | } |
| 8532 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8533 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8534 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8535 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8536 | 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] | 8537 | 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] | 8538 | err_code |= ERR_WARN; |
| 8539 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8540 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8541 | |
| 8542 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8543 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8544 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8545 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8546 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
| 8547 | 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", |
| 8548 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8549 | err_code |= ERR_WARN; |
| 8550 | } |
| 8551 | |
| 8552 | |
| 8553 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
| 8554 | 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", |
| 8555 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8556 | err_code |= ERR_WARN; |
| 8557 | } |
| 8558 | } |
| 8559 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8560 | newsrv = newsrv->next; |
| 8561 | } |
| 8562 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8563 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8564 | * with no inspect-delay |
| 8565 | */ |
| 8566 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8567 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8568 | if (arule->action == ACT_TCP_CAPTURE && |
| 8569 | !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8570 | break; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8571 | if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) && |
| 8572 | !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8573 | break; |
| 8574 | } |
| 8575 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8576 | if (&arule->list != &curproxy->tcp_req.inspect_rules) { |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8577 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8578 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8579 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8580 | " setting the tcp-request inspect-delay.\n", |
| 8581 | proxy_type_str(curproxy), curproxy->id); |
| 8582 | err_code |= ERR_WARN; |
| 8583 | } |
| 8584 | } |
| 8585 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8586 | /* Check filter configuration, if any */ |
| 8587 | cfgerr += flt_check(curproxy); |
| 8588 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8589 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8590 | if (!curproxy->accept) |
| 8591 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8592 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8593 | if (curproxy->tcp_req.inspect_delay || |
| 8594 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8595 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8596 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8597 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8598 | 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] | 8599 | 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] | 8600 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8601 | |
| 8602 | /* both TCP and HTTP must check switching rules */ |
| 8603 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8604 | |
| 8605 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8606 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8607 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8608 | 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] | 8609 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8610 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8611 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8612 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8613 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8614 | } |
| 8615 | |
| 8616 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8617 | if (curproxy->tcp_req.inspect_delay || |
| 8618 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8619 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8620 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8621 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8622 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8623 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8624 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8625 | 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] | 8626 | 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] | 8627 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8628 | |
| 8629 | /* If the backend does requires RDP cookie persistence, we have to |
| 8630 | * enable the corresponding analyser. |
| 8631 | */ |
| 8632 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8633 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8634 | |
| 8635 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8636 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8637 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8638 | 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] | 8639 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8640 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8641 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8642 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8643 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8644 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8645 | } |
| 8646 | |
| 8647 | /***********************************************************/ |
| 8648 | /* At this point, target names have already been resolved. */ |
| 8649 | /***********************************************************/ |
| 8650 | |
| 8651 | /* Check multi-process mode compatibility */ |
| 8652 | |
| 8653 | if (global.nbproc > 1 && global.stats_fe) { |
| 8654 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8655 | unsigned long mask; |
| 8656 | |
| 8657 | mask = nbits(global.nbproc); |
| 8658 | if (global.stats_fe->bind_proc) |
| 8659 | mask &= global.stats_fe->bind_proc; |
| 8660 | |
| 8661 | if (bind_conf->bind_proc) |
| 8662 | mask &= bind_conf->bind_proc; |
| 8663 | |
| 8664 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8665 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8666 | break; |
| 8667 | } |
| 8668 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8669 | 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"); |
| 8670 | } |
| 8671 | } |
| 8672 | |
| 8673 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8674 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8675 | if (curproxy->bind_proc) |
| 8676 | continue; |
| 8677 | |
| 8678 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8679 | unsigned long mask; |
| 8680 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8681 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8682 | curproxy->bind_proc |= mask; |
| 8683 | } |
| 8684 | |
| 8685 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8686 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8687 | } |
| 8688 | |
| 8689 | if (global.stats_fe) { |
| 8690 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8691 | unsigned long mask; |
| 8692 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8693 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8694 | global.stats_fe->bind_proc |= mask; |
| 8695 | } |
| 8696 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8697 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8698 | } |
| 8699 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8700 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8701 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8702 | */ |
| 8703 | if (!cfgerr) { |
| 8704 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8705 | if (curproxy->cap & PR_CAP_FE) |
| 8706 | propagate_processes(curproxy, NULL); |
| 8707 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8708 | } |
| 8709 | |
| 8710 | /* Bind each unbound backend to all processes when not specified. */ |
| 8711 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8712 | if (curproxy->bind_proc) |
| 8713 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8714 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8715 | } |
| 8716 | |
| 8717 | /*******************************************************/ |
| 8718 | /* At this step, all proxies have a non-null bind_proc */ |
| 8719 | /*******************************************************/ |
| 8720 | |
| 8721 | /* perform the final checks before creating tasks */ |
| 8722 | |
| 8723 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8724 | struct listener *listener; |
| 8725 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8726 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8727 | /* Configure SSL for each bind line. |
| 8728 | * Note: if configuration fails at some point, the ->ctx member |
| 8729 | * remains NULL so that listeners can later detach. |
| 8730 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8731 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8732 | if (bind_conf->xprt->prepare_bind_conf && |
| 8733 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8734 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8735 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8736 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8737 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8738 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8739 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8740 | int nbproc; |
| 8741 | |
| 8742 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8743 | (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] | 8744 | nbits(global.nbproc)); |
| 8745 | |
| 8746 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8747 | nbproc = 1; |
| 8748 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8749 | if (!listener->luid) { |
| 8750 | /* listener ID not set, use automatic numbering with first |
| 8751 | * spare entry starting with next_luid. |
| 8752 | */ |
| 8753 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8754 | listener->conf.id.key = listener->luid = next_id; |
| 8755 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8756 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8757 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8758 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8759 | /* enable separate counters */ |
| 8760 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8761 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8762 | if (!listener->name) |
| 8763 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8764 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8765 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8766 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8767 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8768 | if (!listener->maxconn) |
| 8769 | listener->maxconn = curproxy->maxconn; |
| 8770 | if (!listener->backlog) |
| 8771 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8772 | if (!listener->maxaccept) |
| 8773 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8774 | |
| 8775 | /* we want to have an optimal behaviour on single process mode to |
| 8776 | * maximize the work at once, but in multi-process we want to keep |
| 8777 | * some fairness between processes, so we target half of the max |
| 8778 | * number of events to be balanced over all the processes the proxy |
| 8779 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8780 | * used to disable the limit. |
| 8781 | */ |
| 8782 | if (listener->maxaccept > 0) { |
| 8783 | if (nbproc > 1) |
| 8784 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8785 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8786 | } |
| 8787 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8788 | listener->accept = session_accept_fd; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8789 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8790 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8791 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8792 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8793 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8794 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8795 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8796 | listener->options |= LI_O_TCP_L5_RULES; |
| 8797 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8798 | if (curproxy->mon_mask.s_addr) |
| 8799 | listener->options |= LI_O_CHK_MONNET; |
| 8800 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8801 | /* smart accept mode is automatic in HTTP mode */ |
| 8802 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8803 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8804 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8805 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8806 | } |
| 8807 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8808 | /* Release unused SSL configs */ |
| 8809 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 8810 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 8811 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8812 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8813 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8814 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8815 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8816 | int count, maxproc = 0; |
| 8817 | |
| 8818 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8819 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8820 | if (count > maxproc) |
| 8821 | maxproc = count; |
| 8822 | } |
| 8823 | /* backends have 0, frontends have 1 or more */ |
| 8824 | if (maxproc != 1) |
| 8825 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 8826 | " limited to process assigned to the current request.\n", |
| 8827 | curproxy->id); |
| 8828 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8829 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 8830 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8831 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8832 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8833 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8834 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 8835 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8836 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8837 | } |
| 8838 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8839 | |
| 8840 | /* create the task associated with the proxy */ |
| 8841 | curproxy->task = task_new(); |
| 8842 | if (curproxy->task) { |
| 8843 | curproxy->task->context = curproxy; |
| 8844 | curproxy->task->process = manage_proxy; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8845 | } else { |
| 8846 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8847 | curproxy->id); |
| 8848 | cfgerr++; |
| 8849 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8850 | } |
| 8851 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8852 | /* automatically compute fullconn if not set. We must not do it in the |
| 8853 | * loop above because cross-references are not yet fully resolved. |
| 8854 | */ |
| 8855 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8856 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 8857 | * the possible incoming frontend's maxconns. |
| 8858 | */ |
| 8859 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8860 | /* we have the sum of the maxconns in <total>. We only |
| 8861 | * keep 10% of that sum to set the default fullconn, with |
| 8862 | * a hard minimum of 1 (to avoid a divide by zero). |
| 8863 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 8864 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8865 | if (!curproxy->fullconn) |
| 8866 | curproxy->fullconn = 1; |
| 8867 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 8868 | } |
| 8869 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8870 | /* |
| 8871 | * Recount currently required checks. |
| 8872 | */ |
| 8873 | |
| 8874 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 8875 | int optnum; |
| 8876 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8877 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 8878 | if (curproxy->options & cfg_opts[optnum].val) |
| 8879 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8880 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8881 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 8882 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 8883 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8884 | } |
| 8885 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 8886 | /* compute the required process bindings for the peers */ |
| 8887 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 8888 | if (curproxy->table.peers.p) |
| 8889 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 8890 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8891 | if (cfg_peers) { |
| 8892 | struct peers *curpeers = cfg_peers, **last; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8893 | struct peer *p, *pb; |
| 8894 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8895 | /* Remove all peers sections which don't have a valid listener, |
| 8896 | * which are not used by any table, or which are bound to more |
| 8897 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8898 | */ |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8899 | last = &cfg_peers; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8900 | while (*last) { |
| 8901 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8902 | |
| 8903 | if (curpeers->state == PR_STSTOPPED) { |
| 8904 | /* the "disabled" keyword was present */ |
| 8905 | if (curpeers->peers_fe) |
| 8906 | stop_proxy(curpeers->peers_fe); |
| 8907 | curpeers->peers_fe = NULL; |
| 8908 | } |
| 8909 | else if (!curpeers->peers_fe) { |
| 8910 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 8911 | curpeers->id, localpeer); |
| 8912 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8913 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8914 | /* either it's totally stopped or too much used */ |
| 8915 | if (curpeers->peers_fe->bind_proc) { |
| 8916 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 8917 | "running in different processes (%d different ones). " |
| 8918 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8919 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8920 | cfgerr++; |
| 8921 | } |
| 8922 | stop_proxy(curpeers->peers_fe); |
| 8923 | curpeers->peers_fe = NULL; |
| 8924 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8925 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 8926 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8927 | last = &curpeers->next; |
| 8928 | continue; |
| 8929 | } |
| 8930 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8931 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8932 | p = curpeers->remote; |
| 8933 | while (p) { |
| 8934 | pb = p->next; |
| 8935 | free(p->id); |
| 8936 | free(p); |
| 8937 | p = pb; |
| 8938 | } |
| 8939 | |
| 8940 | /* Destroy and unlink this curpeers section. |
| 8941 | * Note: curpeers is backed up into *last. |
| 8942 | */ |
| 8943 | free(curpeers->id); |
| 8944 | curpeers = curpeers->next; |
| 8945 | free(*last); |
| 8946 | *last = curpeers; |
| 8947 | } |
| 8948 | } |
| 8949 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 8950 | /* initialize stick-tables on backend capable proxies. This must not |
| 8951 | * be done earlier because the data size may be discovered while parsing |
| 8952 | * other proxies. |
| 8953 | */ |
| 8954 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8955 | if (curproxy->state == PR_STSTOPPED) |
| 8956 | continue; |
| 8957 | |
| 8958 | if (!stktable_init(&curproxy->table)) { |
| 8959 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 8960 | cfgerr++; |
| 8961 | } |
| 8962 | } |
| 8963 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 8964 | if (mailers) { |
| 8965 | struct mailers *curmailers = mailers, **last; |
| 8966 | struct mailer *m, *mb; |
| 8967 | |
| 8968 | /* Remove all mailers sections which don't have a valid listener. |
| 8969 | * This can happen when a mailers section is never referenced. |
| 8970 | */ |
| 8971 | last = &mailers; |
| 8972 | while (*last) { |
| 8973 | curmailers = *last; |
| 8974 | if (curmailers->users) { |
| 8975 | last = &curmailers->next; |
| 8976 | continue; |
| 8977 | } |
| 8978 | |
| 8979 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 8980 | curmailers->id); |
| 8981 | |
| 8982 | m = curmailers->mailer_list; |
| 8983 | while (m) { |
| 8984 | mb = m->next; |
| 8985 | free(m->id); |
| 8986 | free(m); |
| 8987 | m = mb; |
| 8988 | } |
| 8989 | |
| 8990 | /* Destroy and unlink this curmailers section. |
| 8991 | * Note: curmailers is backed up into *last. |
| 8992 | */ |
| 8993 | free(curmailers->id); |
| 8994 | curmailers = curmailers->next; |
| 8995 | free(*last); |
| 8996 | *last = curmailers; |
| 8997 | } |
| 8998 | } |
| 8999 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9000 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9001 | * a server-state file locally defined and none has been provided */ |
| 9002 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9003 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9004 | curproxy->server_state_file_name == NULL) |
| 9005 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9006 | } |
| 9007 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9008 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9009 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9010 | MEM_F_SHARED); |
| 9011 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9012 | list_for_each_entry(postparser, &postparsers, list) { |
| 9013 | if (postparser->func) |
| 9014 | cfgerr += postparser->func(); |
| 9015 | } |
| 9016 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9017 | if (cfgerr > 0) |
| 9018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9019 | out: |
| 9020 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9021 | } |
| 9022 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9023 | /* |
| 9024 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9025 | * parsing sessions. |
| 9026 | */ |
| 9027 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9028 | { |
| 9029 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9030 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9031 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9032 | /* |
| 9033 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9034 | */ |
| 9035 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9036 | { |
| 9037 | LIST_DEL(&kwl->list); |
| 9038 | LIST_INIT(&kwl->list); |
| 9039 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9040 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9041 | /* this function register new section in the haproxy configuration file. |
| 9042 | * <section_name> is the name of this new section and <section_parser> |
| 9043 | * is the called parser. If two section declaration have the same name, |
| 9044 | * only the first declared is used. |
| 9045 | */ |
| 9046 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9047 | int (*section_parser)(const char *, int, char **, int), |
| 9048 | int (*post_section_parser)()) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9049 | { |
| 9050 | struct cfg_section *cs; |
| 9051 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9052 | list_for_each_entry(cs, §ions, list) { |
| 9053 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9054 | Alert("register section '%s': already registered.\n", section_name); |
| 9055 | return 0; |
| 9056 | } |
| 9057 | } |
| 9058 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9059 | cs = calloc(1, sizeof(*cs)); |
| 9060 | if (!cs) { |
| 9061 | Alert("register section '%s': out of memory.\n", section_name); |
| 9062 | return 0; |
| 9063 | } |
| 9064 | |
| 9065 | cs->section_name = section_name; |
| 9066 | cs->section_parser = section_parser; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9067 | cs->post_section_parser = post_section_parser; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9068 | |
| 9069 | LIST_ADDQ(§ions, &cs->list); |
| 9070 | |
| 9071 | return 1; |
| 9072 | } |
| 9073 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9074 | /* this function register a new function which will be called once the haproxy |
| 9075 | * configuration file has been parsed. It's useful to check dependencies |
| 9076 | * between sections or to resolve items once everything is parsed. |
| 9077 | */ |
| 9078 | int cfg_register_postparser(char *name, int (*func)()) |
| 9079 | { |
| 9080 | struct cfg_postparser *cp; |
| 9081 | |
| 9082 | cp = calloc(1, sizeof(*cp)); |
| 9083 | if (!cp) { |
| 9084 | Alert("register postparser '%s': out of memory.\n", name); |
| 9085 | return 0; |
| 9086 | } |
| 9087 | cp->name = name; |
| 9088 | cp->func = func; |
| 9089 | |
| 9090 | LIST_ADDQ(&postparsers, &cp->list); |
| 9091 | |
| 9092 | return 1; |
| 9093 | } |
| 9094 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9095 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9096 | * free all config section entries |
| 9097 | */ |
| 9098 | void cfg_unregister_sections(void) |
| 9099 | { |
| 9100 | struct cfg_section *cs, *ics; |
| 9101 | |
| 9102 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9103 | LIST_DEL(&cs->list); |
| 9104 | free(cs); |
| 9105 | } |
| 9106 | } |
| 9107 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9108 | void cfg_backup_sections(struct list *backup_sections) |
| 9109 | { |
| 9110 | struct cfg_section *cs, *ics; |
| 9111 | |
| 9112 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9113 | LIST_DEL(&cs->list); |
| 9114 | LIST_ADDQ(backup_sections, &cs->list); |
| 9115 | } |
| 9116 | } |
| 9117 | |
| 9118 | void cfg_restore_sections(struct list *backup_sections) |
| 9119 | { |
| 9120 | struct cfg_section *cs, *ics; |
| 9121 | |
| 9122 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9123 | LIST_DEL(&cs->list); |
| 9124 | LIST_ADDQ(§ions, &cs->list); |
| 9125 | } |
| 9126 | } |
| 9127 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9128 | __attribute__((constructor)) |
| 9129 | static void cfgparse_init(void) |
| 9130 | { |
| 9131 | /* Register internal sections */ |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9132 | cfg_register_section("listen", cfg_parse_listen, NULL); |
| 9133 | cfg_register_section("frontend", cfg_parse_listen, NULL); |
| 9134 | cfg_register_section("backend", cfg_parse_listen, NULL); |
| 9135 | cfg_register_section("defaults", cfg_parse_listen, NULL); |
| 9136 | cfg_register_section("global", cfg_parse_global, NULL); |
| 9137 | cfg_register_section("userlist", cfg_parse_users, NULL); |
| 9138 | cfg_register_section("peers", cfg_parse_peers, NULL); |
| 9139 | cfg_register_section("mailers", cfg_parse_mailers, NULL); |
| 9140 | cfg_register_section("namespace_list", cfg_parse_netns, NULL); |
| 9141 | cfg_register_section("resolvers", cfg_parse_resolvers, NULL); |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9142 | } |
| 9143 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9144 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9145 | * Local variables: |
| 9146 | * c-indent-level: 8 |
| 9147 | * c-basic-offset: 8 |
| 9148 | * End: |
| 9149 | */ |