Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_HAP_CRYPT |
| 14 | /* This is to have crypt() defined on Linux */ |
| 15 | #define _GNU_SOURCE |
| 16 | |
| 17 | #ifdef NEED_CRYPT_H |
| 18 | /* some platforms such as Solaris need this */ |
| 19 | #include <crypt.h> |
| 20 | #endif |
| 21 | #endif /* CONFIG_HAP_CRYPT */ |
| 22 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 44 | #include <common/namespace.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
| 46 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 47 | #include <types/compression.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 48 | #include <types/filters.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 50 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 51 | #include <types/peers.h> |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 52 | #include <types/mailers.h> |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 53 | #include <types/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 54 | #include <types/stats.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 56 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 57 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 59 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 61 | #include <proto/compression.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 62 | #include <proto/stats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 63 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 64 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 65 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 66 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 67 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 68 | #include <proto/lb_fwlc.h> |
| 69 | #include <proto/lb_fwrr.h> |
| 70 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 71 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 72 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 73 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 74 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 75 | #include <proto/proto_uxst.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); |
| 130 | }; |
| 131 | |
| 132 | /* Used to chain configuration sections definitions. This list |
| 133 | * stores struct cfg_section |
| 134 | */ |
| 135 | struct list sections = LIST_HEAD_INIT(sections); |
| 136 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 137 | /* 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] | 138 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 139 | const char *name; |
| 140 | unsigned int val; |
| 141 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 142 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 143 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | /* proxy->options */ |
| 147 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 148 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 149 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 150 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 151 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 152 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 153 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 154 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 155 | { "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] | 156 | { "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] | 157 | { "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] | 158 | { "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] | 159 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 160 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 161 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 162 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 163 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 164 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 165 | #else |
| 166 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 167 | #endif |
| 168 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 169 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 172 | /* proxy->options2 */ |
| 173 | static const struct cfg_opt cfg_opts2[] = |
| 174 | { |
| 175 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 176 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 177 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 178 | { "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] | 179 | #else |
| 180 | { "splice-request", 0, 0, 0, 0 }, |
| 181 | { "splice-response", 0, 0, 0, 0 }, |
| 182 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 183 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 184 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 185 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 186 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 187 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 188 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 189 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 190 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 191 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 192 | { "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] | 193 | { "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] | 194 | { "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] | 195 | { "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] | 196 | { "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] | 197 | { NULL, 0, 0, 0 } |
| 198 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 199 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 200 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 202 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 203 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 204 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 206 | /* List head of all known configuration keywords */ |
| 207 | static struct cfg_kw_list cfg_keywords = { |
| 208 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 209 | }; |
| 210 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 211 | /* |
| 212 | * converts <str> to a list of listeners which are dynamically allocated. |
| 213 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 214 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 215 | * - <port> is a numerical port from 1 to 65535 ; |
| 216 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 217 | * 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] | 218 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 219 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 220 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 221 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 222 | 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] | 223 | { |
| 224 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 225 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | int port, end; |
| 227 | |
| 228 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 229 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 231 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 232 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 233 | |
| 234 | str = next; |
| 235 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 236 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 237 | *next++ = 0; |
| 238 | } |
| 239 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 240 | ss2 = str2sa_range(str, NULL, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 241 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 242 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 243 | if (!ss2) |
| 244 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 245 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 246 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 247 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 248 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 249 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 250 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 251 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 252 | if (!port || !end) { |
| 253 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 254 | goto fail; |
| 255 | } |
| 256 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 257 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 258 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 259 | goto fail; |
| 260 | } |
| 261 | |
| 262 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 263 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 264 | goto fail; |
| 265 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 267 | else if (ss2->ss_family == AF_UNSPEC) { |
| 268 | socklen_t addr_len; |
| 269 | |
| 270 | /* We want to attach to an already bound fd whose number |
| 271 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 272 | * Note that by definition there is a single listener. |
| 273 | * We still have to determine the address family to |
| 274 | * register the correct protocol. |
| 275 | */ |
| 276 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 277 | addr_len = sizeof(*ss2); |
| 278 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 279 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 280 | goto fail; |
| 281 | } |
| 282 | |
| 283 | port = end = get_host_port(ss2); |
| 284 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 286 | /* OK the address looks correct */ |
Vincent Bernat | 6e61589 | 2016-05-18 16:17:44 +0200 | [diff] [blame] | 287 | memcpy(&ss, ss2, sizeof(ss)); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 288 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 289 | for (; port <= end; port++) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 290 | l = calloc(1, sizeof(*l)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 291 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 292 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 293 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 294 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 295 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 296 | l->fd = fd; |
Vincent Bernat | 6e46ff1 | 2016-05-19 11:29:43 +0200 | [diff] [blame] | 297 | memcpy(&l->addr, &ss, sizeof(ss)); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 298 | l->state = LI_INIT; |
| 299 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 300 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 301 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 302 | tcpv4_add_listener(l); |
| 303 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 304 | else if (ss.ss_family == AF_INET6) { |
| 305 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 306 | tcpv6_add_listener(l); |
| 307 | } |
| 308 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 309 | uxst_add_listener(l); |
| 310 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 311 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 312 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 313 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 314 | } /* end for(port) */ |
| 315 | } /* end while(next) */ |
| 316 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 317 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 318 | fail: |
| 319 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 320 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 321 | } |
| 322 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 323 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 324 | * Report an error in <msg> when there are too many arguments. This version is |
| 325 | * intended to be used by keyword parsers so that the message will be included |
| 326 | * into the general error message. The index is the current keyword in args. |
| 327 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 328 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 329 | * message may also be null, it will simply not be produced (useful to check only). |
| 330 | * <msg> and <err_code> are only affected on error. |
| 331 | */ |
| 332 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 333 | { |
| 334 | int i; |
| 335 | |
| 336 | if (!*args[index + maxarg + 1]) |
| 337 | return 0; |
| 338 | |
| 339 | if (msg) { |
| 340 | *msg = NULL; |
| 341 | memprintf(msg, "%s", args[0]); |
| 342 | for (i = 1; i <= index; i++) |
| 343 | memprintf(msg, "%s %s", *msg, args[i]); |
| 344 | |
| 345 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 346 | } |
| 347 | if (err_code) |
| 348 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 349 | |
| 350 | return 1; |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * same as too_many_args_idx with a 0 index |
| 355 | */ |
| 356 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 357 | { |
| 358 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 359 | } |
| 360 | |
| 361 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 362 | * Report a fatal Alert when there is too much arguments |
| 363 | * The index is the current keyword in args |
| 364 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 365 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 366 | */ |
| 367 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 368 | { |
| 369 | char *kw = NULL; |
| 370 | int i; |
| 371 | |
| 372 | if (!*args[index + maxarg + 1]) |
| 373 | return 0; |
| 374 | |
| 375 | memprintf(&kw, "%s", args[0]); |
| 376 | for (i = 1; i <= index; i++) { |
| 377 | memprintf(&kw, "%s %s", kw, args[i]); |
| 378 | } |
| 379 | |
| 380 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 381 | free(kw); |
| 382 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 383 | return 1; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * same as alertif_too_many_args_idx with a 0 index |
| 388 | */ |
| 389 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 390 | { |
| 391 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 392 | } |
| 393 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 394 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 395 | * Return 1 if the warning has been emitted, otherwise 0. |
| 396 | */ |
| 397 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 398 | { |
| 399 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 400 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 401 | file, line, arg); |
| 402 | return 1; |
| 403 | } |
| 404 | return 0; |
| 405 | } |
| 406 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 407 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 408 | * Return 1 if the warning has been emitted, otherwise 0. |
| 409 | */ |
| 410 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 411 | { |
| 412 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 413 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 414 | file, line, arg); |
| 415 | return 1; |
| 416 | } |
| 417 | return 0; |
| 418 | } |
| 419 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 420 | /* Report a warning if a rule is placed after a 'block' rule. |
| 421 | * Return 1 if the warning has been emitted, otherwise 0. |
| 422 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 423 | int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 424 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 425 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 426 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 427 | file, line, arg); |
| 428 | return 1; |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 433 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 434 | * Return 1 if the warning has been emitted, otherwise 0. |
| 435 | */ |
| 436 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 437 | { |
| 438 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 439 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 440 | file, line, arg); |
| 441 | return 1; |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 446 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 447 | * Return 1 if the warning has been emitted, otherwise 0. |
| 448 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 449 | int warnif_rule_after_reqxxx(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 450 | { |
| 451 | if (proxy->req_exp) { |
| 452 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 453 | file, line, arg); |
| 454 | return 1; |
| 455 | } |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* Report a warning if a rule is placed after a reqadd rule. |
| 460 | * Return 1 if the warning has been emitted, otherwise 0. |
| 461 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 462 | int warnif_rule_after_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 463 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 464 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 465 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 466 | file, line, arg); |
| 467 | return 1; |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | /* Report a warning if a rule is placed after a redirect rule. |
| 473 | * Return 1 if the warning has been emitted, otherwise 0. |
| 474 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 475 | 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] | 476 | { |
| 477 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 478 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 479 | file, line, arg); |
| 480 | return 1; |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 486 | * Return 1 if the warning has been emitted, otherwise 0. |
| 487 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 488 | 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] | 489 | { |
| 490 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 491 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 492 | file, line, arg); |
| 493 | return 1; |
| 494 | } |
| 495 | return 0; |
| 496 | } |
| 497 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 498 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 499 | * Return 1 if the warning has been emitted, otherwise 0. |
| 500 | */ |
| 501 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 502 | { |
| 503 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 504 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 505 | file, line, arg); |
| 506 | return 1; |
| 507 | } |
| 508 | return 0; |
| 509 | } |
| 510 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 511 | /* report a warning if a redirect rule is dangerously placed */ |
| 512 | 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] | 513 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 514 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 515 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 516 | } |
| 517 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 518 | /* report a warning if a reqadd rule is dangerously placed */ |
| 519 | 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] | 520 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 521 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 522 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 525 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 526 | 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] | 527 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 528 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 529 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* report a warning if an http-request rule is dangerously placed */ |
| 533 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 534 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 535 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 536 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 537 | } |
| 538 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 539 | /* report a warning if a block rule is dangerously placed */ |
| 540 | 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] | 541 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 542 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 543 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 544 | } |
| 545 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 546 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 547 | 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] | 548 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 549 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 550 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 551 | } |
| 552 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 553 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 554 | 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] | 555 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 556 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 557 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 558 | } |
| 559 | |
| 560 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 561 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 562 | { |
| 563 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 564 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 565 | } |
| 566 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 567 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 568 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 569 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 570 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 571 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 572 | 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] | 573 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 574 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 575 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 576 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 577 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 578 | return 0; |
| 579 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 580 | acl = acl_cond_conflicts(cond, where); |
| 581 | if (acl) { |
| 582 | if (acl->name && *acl->name) |
| 583 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 584 | file, line, acl->name, sample_ckp_names(where)); |
| 585 | else |
| 586 | 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] | 587 | 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] | 588 | return ERR_WARN; |
| 589 | } |
| 590 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 591 | return 0; |
| 592 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 593 | if (acl->name && *acl->name) |
| 594 | 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] | 595 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 596 | else |
| 597 | 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] | 598 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 599 | return ERR_WARN; |
| 600 | } |
| 601 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 602 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 603 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 604 | * any combination of : |
| 605 | * - ERR_ABORT: must abort ASAP |
| 606 | * - ERR_FATAL: we can continue parsing but not start the service |
| 607 | * - ERR_WARN: a warning has been emitted |
| 608 | * - ERR_ALERT: an alert has been emitted |
| 609 | * Only the two first ones can stop processing, the two others are just |
| 610 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 611 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 612 | 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] | 613 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 614 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 615 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 616 | |
| 617 | if (!strcmp(args[0], "global")) { /* new section */ |
| 618 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 619 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 620 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 621 | } |
| 622 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 623 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 624 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 625 | global.mode |= MODE_DAEMON; |
| 626 | } |
| 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 | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 761 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 762 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 763 | } |
| 764 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 765 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 766 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 767 | if (*(args[1]) == 0) { |
| 768 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 770 | goto out; |
| 771 | } |
| 772 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 773 | if (global.tune.maxrewrite < 0) { |
| 774 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 775 | err_code |= ERR_ALERT | ERR_FATAL; |
| 776 | goto out; |
| 777 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 778 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 779 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 780 | unsigned int idle; |
| 781 | const char *res; |
| 782 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 783 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 784 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 785 | if (*(args[1]) == 0) { |
| 786 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 788 | goto out; |
| 789 | } |
| 790 | |
| 791 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 792 | if (res) { |
| 793 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 794 | file, linenum, *res, args[0]); |
| 795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 796 | goto out; |
| 797 | } |
| 798 | |
| 799 | if (idle > 65535) { |
| 800 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 802 | goto out; |
| 803 | } |
| 804 | global.tune.idle_timer = idle; |
| 805 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 806 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 807 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 808 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 809 | if (global.tune.client_rcvbuf != 0) { |
| 810 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 811 | err_code |= ERR_ALERT; |
| 812 | goto out; |
| 813 | } |
| 814 | if (*(args[1]) == 0) { |
| 815 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 817 | goto out; |
| 818 | } |
| 819 | global.tune.client_rcvbuf = atol(args[1]); |
| 820 | } |
| 821 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 822 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 823 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 824 | if (global.tune.server_rcvbuf != 0) { |
| 825 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 826 | err_code |= ERR_ALERT; |
| 827 | goto out; |
| 828 | } |
| 829 | if (*(args[1]) == 0) { |
| 830 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 832 | goto out; |
| 833 | } |
| 834 | global.tune.server_rcvbuf = atol(args[1]); |
| 835 | } |
| 836 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 837 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 838 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 839 | if (global.tune.client_sndbuf != 0) { |
| 840 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 841 | err_code |= ERR_ALERT; |
| 842 | goto out; |
| 843 | } |
| 844 | if (*(args[1]) == 0) { |
| 845 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 847 | goto out; |
| 848 | } |
| 849 | global.tune.client_sndbuf = atol(args[1]); |
| 850 | } |
| 851 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 852 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 853 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 854 | if (global.tune.server_sndbuf != 0) { |
| 855 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 856 | err_code |= ERR_ALERT; |
| 857 | goto out; |
| 858 | } |
| 859 | if (*(args[1]) == 0) { |
| 860 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 862 | goto out; |
| 863 | } |
| 864 | global.tune.server_sndbuf = atol(args[1]); |
| 865 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 866 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 867 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 868 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 869 | if (*(args[1]) == 0) { |
| 870 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 872 | goto out; |
| 873 | } |
| 874 | global.tune.pipesize = atol(args[1]); |
| 875 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 876 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 877 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 878 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 879 | if (*(args[1]) == 0) { |
| 880 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 881 | err_code |= ERR_ALERT | ERR_FATAL; |
| 882 | goto out; |
| 883 | } |
| 884 | global.tune.cookie_len = atol(args[1]) + 1; |
| 885 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 886 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 887 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 888 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 889 | if (*(args[1]) == 0) { |
| 890 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 892 | goto out; |
| 893 | } |
| 894 | global.tune.max_http_hdr = atol(args[1]); |
| 895 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 896 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 897 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 898 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 899 | if (*args[1]) { |
| 900 | global.tune.comp_maxlevel = atoi(args[1]); |
| 901 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 902 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 903 | file, linenum, args[0]); |
| 904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 905 | goto out; |
| 906 | } |
| 907 | } else { |
| 908 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 909 | file, linenum, args[0]); |
| 910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 911 | goto out; |
| 912 | } |
| 913 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 914 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 915 | if (*args[1]) { |
| 916 | global.tune.pattern_cache = atoi(args[1]); |
| 917 | if (global.tune.pattern_cache < 0) { |
| 918 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 919 | file, linenum, args[0]); |
| 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
| 922 | } |
| 923 | } else { |
| 924 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 925 | file, linenum, args[0]); |
| 926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 927 | goto out; |
| 928 | } |
| 929 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 930 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 931 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 932 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 933 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 934 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 935 | err_code |= ERR_ALERT; |
| 936 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 937 | } |
| 938 | if (*(args[1]) == 0) { |
| 939 | 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] | 940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 941 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 942 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 943 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 944 | 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]); |
| 945 | err_code |= ERR_WARN; |
| 946 | goto out; |
| 947 | } |
| 948 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 949 | } |
| 950 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 951 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 952 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 953 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 954 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 955 | err_code |= ERR_ALERT; |
| 956 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 957 | } |
| 958 | if (*(args[1]) == 0) { |
| 959 | 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] | 960 | err_code |= ERR_ALERT | ERR_FATAL; |
| 961 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 962 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 963 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 964 | 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]); |
| 965 | err_code |= ERR_WARN; |
| 966 | goto out; |
| 967 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 968 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 969 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 970 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 971 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 972 | global.external_check = 1; |
| 973 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 974 | /* user/group name handling */ |
| 975 | else if (!strcmp(args[0], "user")) { |
| 976 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 977 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 978 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 979 | if (global.uid != 0) { |
| 980 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 981 | err_code |= ERR_ALERT; |
| 982 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 983 | } |
| 984 | errno = 0; |
| 985 | ha_user = getpwnam(args[1]); |
| 986 | if (ha_user != NULL) { |
| 987 | global.uid = (int)ha_user->pw_uid; |
| 988 | } |
| 989 | else { |
| 990 | 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] | 991 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | else if (!strcmp(args[0], "group")) { |
| 995 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 996 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 997 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 998 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 999 | 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] | 1000 | err_code |= ERR_ALERT; |
| 1001 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1002 | } |
| 1003 | errno = 0; |
| 1004 | ha_group = getgrnam(args[1]); |
| 1005 | if (ha_group != NULL) { |
| 1006 | global.gid = (int)ha_group->gr_gid; |
| 1007 | } |
| 1008 | else { |
| 1009 | 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] | 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1014 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1015 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1017 | if (*(args[1]) == 0) { |
| 1018 | 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] | 1019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1020 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1021 | } |
| 1022 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1023 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1024 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1025 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1027 | goto out; |
| 1028 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1029 | } |
| 1030 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1031 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1033 | if (global.maxconn != 0) { |
| 1034 | 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] | 1035 | err_code |= ERR_ALERT; |
| 1036 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1037 | } |
| 1038 | if (*(args[1]) == 0) { |
| 1039 | 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] | 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1042 | } |
| 1043 | global.maxconn = atol(args[1]); |
| 1044 | #ifdef SYSTEM_MAXCONN |
| 1045 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1046 | 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); |
| 1047 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1048 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1049 | } |
| 1050 | #endif /* SYSTEM_MAXCONN */ |
| 1051 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1052 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1053 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1054 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1055 | if (*(args[1]) == 0) { |
| 1056 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | if (strcmp(args[1],"none") == 0) |
| 1061 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1062 | else if (strcmp(args[1],"required") == 0) |
| 1063 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1064 | else { |
| 1065 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1067 | goto out; |
| 1068 | } |
| 1069 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1070 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1071 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1072 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1073 | if (global.cps_lim != 0) { |
| 1074 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1075 | err_code |= ERR_ALERT; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | if (*(args[1]) == 0) { |
| 1079 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1081 | goto out; |
| 1082 | } |
| 1083 | global.cps_lim = atol(args[1]); |
| 1084 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1085 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1086 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1087 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1088 | if (global.sps_lim != 0) { |
| 1089 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1090 | err_code |= ERR_ALERT; |
| 1091 | goto out; |
| 1092 | } |
| 1093 | if (*(args[1]) == 0) { |
| 1094 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
| 1097 | } |
| 1098 | global.sps_lim = atol(args[1]); |
| 1099 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1100 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1101 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1102 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1103 | if (global.ssl_lim != 0) { |
| 1104 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1105 | err_code |= ERR_ALERT; |
| 1106 | goto out; |
| 1107 | } |
| 1108 | if (*(args[1]) == 0) { |
| 1109 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1111 | goto out; |
| 1112 | } |
| 1113 | global.ssl_lim = atol(args[1]); |
| 1114 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1115 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1116 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1117 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1118 | if (*(args[1]) == 0) { |
| 1119 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1120 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1121 | goto out; |
| 1122 | } |
| 1123 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1124 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1125 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1126 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1127 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1128 | if (global.maxpipes != 0) { |
| 1129 | 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] | 1130 | err_code |= ERR_ALERT; |
| 1131 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1132 | } |
| 1133 | if (*(args[1]) == 0) { |
| 1134 | 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] | 1135 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1136 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1137 | } |
| 1138 | global.maxpipes = atol(args[1]); |
| 1139 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1140 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1141 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1142 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1143 | if (*(args[1]) == 0) { |
| 1144 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1146 | goto out; |
| 1147 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1148 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1149 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1150 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1151 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1152 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1153 | if (*(args[1]) == 0) { |
| 1154 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1156 | goto out; |
| 1157 | } |
| 1158 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1159 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1160 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1162 | goto out; |
| 1163 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1164 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1165 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1166 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1167 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1168 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1169 | if (global.rlimit_nofile != 0) { |
| 1170 | 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] | 1171 | err_code |= ERR_ALERT; |
| 1172 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1173 | } |
| 1174 | if (*(args[1]) == 0) { |
| 1175 | 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] | 1176 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1177 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1178 | } |
| 1179 | global.rlimit_nofile = atol(args[1]); |
| 1180 | } |
| 1181 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1182 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1184 | if (global.chroot != NULL) { |
| 1185 | 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] | 1186 | err_code |= ERR_ALERT; |
| 1187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1188 | } |
| 1189 | if (*(args[1]) == 0) { |
| 1190 | 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] | 1191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1192 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1193 | } |
| 1194 | global.chroot = strdup(args[1]); |
| 1195 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1196 | else if (!strcmp(args[0], "description")) { |
| 1197 | int i, len=0; |
| 1198 | char *d; |
| 1199 | |
| 1200 | if (!*args[1]) { |
| 1201 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1202 | file, linenum, args[0]); |
| 1203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1204 | goto out; |
| 1205 | } |
| 1206 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1207 | for (i = 1; *args[i]; i++) |
| 1208 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1209 | |
| 1210 | if (global.desc) |
| 1211 | free(global.desc); |
| 1212 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1213 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1214 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1215 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1216 | for (i = 2; *args[i]; i++) |
| 1217 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1218 | } |
| 1219 | else if (!strcmp(args[0], "node")) { |
| 1220 | int i; |
| 1221 | char c; |
| 1222 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1223 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1224 | goto out; |
| 1225 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1226 | for (i=0; args[1][i]; i++) { |
| 1227 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1228 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1229 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1230 | break; |
| 1231 | } |
| 1232 | |
| 1233 | if (!i || args[1][i]) { |
| 1234 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1235 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1236 | file, linenum, args[0]); |
| 1237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1238 | goto out; |
| 1239 | } |
| 1240 | |
| 1241 | if (global.node) |
| 1242 | free(global.node); |
| 1243 | |
| 1244 | global.node = strdup(args[1]); |
| 1245 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1246 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1247 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1248 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1249 | if (global.pidfile != NULL) { |
| 1250 | 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] | 1251 | err_code |= ERR_ALERT; |
| 1252 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1253 | } |
| 1254 | if (*(args[1]) == 0) { |
| 1255 | 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] | 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1257 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1258 | } |
| 1259 | global.pidfile = strdup(args[1]); |
| 1260 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1261 | else if (!strcmp(args[0], "unix-bind")) { |
| 1262 | int cur_arg = 1; |
| 1263 | while (*(args[cur_arg])) { |
| 1264 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1265 | if (global.unix_bind.prefix != NULL) { |
| 1266 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1267 | err_code |= ERR_ALERT; |
| 1268 | cur_arg += 2; |
| 1269 | continue; |
| 1270 | } |
| 1271 | |
| 1272 | if (*(args[cur_arg+1]) == 0) { |
| 1273 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1275 | goto out; |
| 1276 | } |
| 1277 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1278 | cur_arg += 2; |
| 1279 | continue; |
| 1280 | } |
| 1281 | |
| 1282 | if (!strcmp(args[cur_arg], "mode")) { |
| 1283 | |
| 1284 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1285 | cur_arg += 2; |
| 1286 | continue; |
| 1287 | } |
| 1288 | |
| 1289 | if (!strcmp(args[cur_arg], "uid")) { |
| 1290 | |
| 1291 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1292 | cur_arg += 2; |
| 1293 | continue; |
| 1294 | } |
| 1295 | |
| 1296 | if (!strcmp(args[cur_arg], "gid")) { |
| 1297 | |
| 1298 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1299 | cur_arg += 2; |
| 1300 | continue; |
| 1301 | } |
| 1302 | |
| 1303 | if (!strcmp(args[cur_arg], "user")) { |
| 1304 | struct passwd *user; |
| 1305 | |
| 1306 | user = getpwnam(args[cur_arg + 1]); |
| 1307 | if (!user) { |
| 1308 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1309 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1311 | goto out; |
| 1312 | } |
| 1313 | |
| 1314 | global.unix_bind.ux.uid = user->pw_uid; |
| 1315 | cur_arg += 2; |
| 1316 | continue; |
| 1317 | } |
| 1318 | |
| 1319 | if (!strcmp(args[cur_arg], "group")) { |
| 1320 | struct group *group; |
| 1321 | |
| 1322 | group = getgrnam(args[cur_arg + 1]); |
| 1323 | if (!group) { |
| 1324 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1325 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1327 | goto out; |
| 1328 | } |
| 1329 | |
| 1330 | global.unix_bind.ux.gid = group->gr_gid; |
| 1331 | cur_arg += 2; |
| 1332 | continue; |
| 1333 | } |
| 1334 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1335 | 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] | 1336 | file, linenum, args[0]); |
| 1337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1338 | goto out; |
| 1339 | } |
| 1340 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1341 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1342 | /* delete previous herited or defined syslog servers */ |
| 1343 | struct logsrv *back; |
| 1344 | struct logsrv *tmp; |
| 1345 | |
| 1346 | if (*(args[1]) != 0) { |
| 1347 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1349 | goto out; |
| 1350 | } |
| 1351 | |
| 1352 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1353 | LIST_DEL(&tmp->list); |
| 1354 | free(tmp); |
| 1355 | } |
| 1356 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1357 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1358 | struct sockaddr_storage *sk; |
| 1359 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1360 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1361 | int arg = 0; |
| 1362 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1363 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1364 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1365 | goto out; |
| 1366 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1367 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1368 | 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] | 1369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1370 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1371 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1372 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1373 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1374 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1375 | /* just after the address, a length may be specified */ |
| 1376 | if (strcmp(args[arg+2], "len") == 0) { |
| 1377 | len = atoi(args[arg+3]); |
| 1378 | if (len < 80 || len > 65535) { |
| 1379 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1380 | file, linenum, args[arg+3]); |
| 1381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1382 | goto out; |
| 1383 | } |
| 1384 | logsrv->maxlen = len; |
| 1385 | |
| 1386 | /* skip these two args */ |
| 1387 | arg += 2; |
| 1388 | } |
| 1389 | else |
| 1390 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1391 | |
| 1392 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1393 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 1394 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 1395 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 1396 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 1397 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1400 | /* after the length, a format may be specified */ |
| 1401 | if (strcmp(args[arg+2], "format") == 0) { |
| 1402 | logsrv->format = get_log_format(args[arg+3]); |
| 1403 | if (logsrv->format < 0) { |
| 1404 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1405 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1406 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1407 | goto out; |
| 1408 | } |
| 1409 | |
| 1410 | /* skip these two args */ |
| 1411 | arg += 2; |
| 1412 | } |
| 1413 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1414 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1415 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1416 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1417 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1418 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1419 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1420 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1421 | 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] | 1422 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1423 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1424 | } |
| 1425 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1426 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1427 | if (*(args[arg+3])) { |
| 1428 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1429 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1430 | 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] | 1431 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1432 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1436 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1437 | if (*(args[arg+4])) { |
| 1438 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1439 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1440 | 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] | 1441 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1442 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1443 | } |
| 1444 | } |
| 1445 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1446 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1447 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1448 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1449 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1450 | free(logsrv); |
| 1451 | goto out; |
| 1452 | } |
| 1453 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1454 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1455 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1456 | if (port1 != port2) { |
| 1457 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1458 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1459 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1460 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1461 | goto out; |
| 1462 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1463 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1464 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1465 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1466 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1467 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1468 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1469 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1470 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1471 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1472 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1473 | |
| 1474 | if (global.log_send_hostname != NULL) { |
| 1475 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1476 | err_code |= ERR_ALERT; |
| 1477 | goto out; |
| 1478 | } |
| 1479 | |
| 1480 | if (*(args[1])) |
| 1481 | name = args[1]; |
| 1482 | else |
| 1483 | name = hostname; |
| 1484 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1485 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1486 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1487 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1488 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1489 | if (global.server_state_base != NULL) { |
| 1490 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1491 | err_code |= ERR_ALERT; |
| 1492 | goto out; |
| 1493 | } |
| 1494 | |
| 1495 | if (!*(args[1])) { |
| 1496 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1497 | err_code |= ERR_FATAL; |
| 1498 | goto out; |
| 1499 | } |
| 1500 | |
| 1501 | global.server_state_base = strdup(args[1]); |
| 1502 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1503 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1504 | if (global.server_state_file != NULL) { |
| 1505 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1506 | err_code |= ERR_ALERT; |
| 1507 | goto out; |
| 1508 | } |
| 1509 | |
| 1510 | if (!*(args[1])) { |
| 1511 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1512 | err_code |= ERR_FATAL; |
| 1513 | goto out; |
| 1514 | } |
| 1515 | |
| 1516 | global.server_state_file = strdup(args[1]); |
| 1517 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1518 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1519 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1520 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1521 | if (*(args[1]) == 0) { |
| 1522 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1524 | goto out; |
| 1525 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1526 | chunk_destroy(&global.log_tag); |
| 1527 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1528 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1529 | 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] | 1530 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1531 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1532 | if (global.spread_checks != 0) { |
| 1533 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1534 | err_code |= ERR_ALERT; |
| 1535 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1536 | } |
| 1537 | if (*(args[1]) == 0) { |
| 1538 | 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] | 1539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1540 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1541 | } |
| 1542 | global.spread_checks = atol(args[1]); |
| 1543 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1544 | 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] | 1545 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1546 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1547 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1548 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1549 | const char *err; |
| 1550 | unsigned int val; |
| 1551 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1552 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1553 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1554 | if (*(args[1]) == 0) { |
| 1555 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1556 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1557 | goto out; |
| 1558 | } |
| 1559 | |
| 1560 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1561 | if (err) { |
| 1562 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1563 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1564 | } |
| 1565 | global.max_spread_checks = val; |
| 1566 | if (global.max_spread_checks < 0) { |
| 1567 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1569 | } |
| 1570 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1571 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1572 | #ifdef USE_CPU_AFFINITY |
| 1573 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1574 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1575 | unsigned long cpus = 0; |
| 1576 | |
| 1577 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1578 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1579 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1580 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1581 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1582 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1583 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1584 | proc = atol(args[1]); |
| 1585 | if (proc >= 1 && proc <= LONGBITS) |
| 1586 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1590 | 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", |
| 1591 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1593 | goto out; |
| 1594 | } |
| 1595 | |
| 1596 | cur_arg = 2; |
| 1597 | while (*args[cur_arg]) { |
| 1598 | unsigned int low, high; |
| 1599 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1600 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1601 | char *dash = strchr(args[cur_arg], '-'); |
| 1602 | |
| 1603 | low = high = str2uic(args[cur_arg]); |
| 1604 | if (dash) |
| 1605 | high = str2uic(dash + 1); |
| 1606 | |
| 1607 | if (high < low) { |
| 1608 | unsigned int swap = low; |
| 1609 | low = high; |
| 1610 | high = swap; |
| 1611 | } |
| 1612 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1613 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1614 | 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] | 1615 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1617 | goto out; |
| 1618 | } |
| 1619 | |
| 1620 | while (low <= high) |
| 1621 | cpus |= 1UL << low++; |
| 1622 | } |
| 1623 | else { |
| 1624 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1625 | file, linenum, args[0], args[cur_arg]); |
| 1626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1627 | goto out; |
| 1628 | } |
| 1629 | cur_arg++; |
| 1630 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1631 | for (i = 0; i < LONGBITS; i++) |
| 1632 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1633 | global.cpu_map[i] = cpus; |
| 1634 | #else |
| 1635 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1637 | goto out; |
| 1638 | #endif |
| 1639 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1640 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1641 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1642 | goto out; |
| 1643 | |
| 1644 | if (*(args[2]) == 0) { |
| 1645 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1647 | goto out; |
| 1648 | } |
| 1649 | |
| 1650 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1651 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1652 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1654 | goto out; |
| 1655 | } |
| 1656 | } |
| 1657 | else if (!strcmp(args[0], "unsetenv")) { |
| 1658 | int arg; |
| 1659 | |
| 1660 | if (*(args[1]) == 0) { |
| 1661 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1663 | goto out; |
| 1664 | } |
| 1665 | |
| 1666 | for (arg = 1; *args[arg]; arg++) { |
| 1667 | if (unsetenv(args[arg]) != 0) { |
| 1668 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1670 | goto out; |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | else if (!strcmp(args[0], "resetenv")) { |
| 1675 | extern char **environ; |
| 1676 | char **env = environ; |
| 1677 | |
| 1678 | /* args contain variable names to keep, one per argument */ |
| 1679 | while (*env) { |
| 1680 | int arg; |
| 1681 | |
| 1682 | /* look for current variable in among all those we want to keep */ |
| 1683 | for (arg = 1; *args[arg]; arg++) { |
| 1684 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1685 | (*env)[strlen(args[arg])] == '=') |
| 1686 | break; |
| 1687 | } |
| 1688 | |
| 1689 | /* delete this variable */ |
| 1690 | if (!*args[arg]) { |
| 1691 | char *delim = strchr(*env, '='); |
| 1692 | |
| 1693 | if (!delim || delim - *env >= trash.size) { |
| 1694 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
| 1699 | memcpy(trash.str, *env, delim - *env); |
| 1700 | trash.str[delim - *env] = 0; |
| 1701 | |
| 1702 | if (unsetenv(trash.str) != 0) { |
| 1703 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1705 | goto out; |
| 1706 | } |
| 1707 | } |
| 1708 | else |
| 1709 | env++; |
| 1710 | } |
| 1711 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1712 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1713 | struct cfg_kw_list *kwl; |
| 1714 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1715 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1716 | |
| 1717 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1718 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1719 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1720 | continue; |
| 1721 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1722 | 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] | 1723 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1724 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1725 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1726 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1727 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1728 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1729 | err_code |= ERR_WARN; |
| 1730 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1731 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1732 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1737 | 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] | 1738 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1739 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1740 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1741 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1742 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1743 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1744 | } |
| 1745 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1746 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1747 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1748 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1749 | defproxy.mode = PR_MODE_TCP; |
| 1750 | defproxy.state = PR_STNEW; |
| 1751 | defproxy.maxconn = cfg_maxpconn; |
| 1752 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1753 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1754 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1755 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1756 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1757 | defproxy.defsrv.check.fastinter = 0; |
| 1758 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1759 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1760 | defproxy.defsrv.agent.fastinter = 0; |
| 1761 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1762 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1763 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1764 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1765 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1766 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1767 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1768 | defproxy.defsrv.maxqueue = 0; |
| 1769 | defproxy.defsrv.minconn = 0; |
| 1770 | defproxy.defsrv.maxconn = 0; |
| 1771 | defproxy.defsrv.slowstart = 0; |
| 1772 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1773 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1774 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1775 | |
| 1776 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1777 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1780 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1781 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1782 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1783 | * ERR_FATAL in case of error. |
| 1784 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1785 | static int create_cond_regex_rule(const char *file, int line, |
| 1786 | struct proxy *px, int dir, int action, int flags, |
| 1787 | const char *cmd, const char *reg, const char *repl, |
| 1788 | const char **cond_start) |
| 1789 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1790 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1791 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1792 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1793 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1794 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1795 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1796 | int cs; |
| 1797 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1798 | |
| 1799 | if (px == &defproxy) { |
| 1800 | 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] | 1801 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1802 | goto err; |
| 1803 | } |
| 1804 | |
| 1805 | if (*reg == 0) { |
| 1806 | 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] | 1807 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1808 | goto err; |
| 1809 | } |
| 1810 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1811 | 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] | 1812 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1813 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1814 | if (cond_start && |
| 1815 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1816 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 1817 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1818 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1819 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1820 | goto err; |
| 1821 | } |
| 1822 | } |
| 1823 | else if (cond_start && **cond_start) { |
| 1824 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1825 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1826 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1827 | goto err; |
| 1828 | } |
| 1829 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1830 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1831 | (dir == SMP_OPT_DIR_REQ) ? |
| 1832 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1833 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1834 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1835 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1836 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1837 | if (!preg) { |
| 1838 | 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] | 1839 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1840 | goto err; |
| 1841 | } |
| 1842 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1843 | cs = !(flags & REG_ICASE); |
| 1844 | cap = !(flags & REG_NOSUB); |
| 1845 | error = NULL; |
| 1846 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 1847 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 1848 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1849 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1850 | goto err; |
| 1851 | } |
| 1852 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1853 | 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] | 1854 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1855 | if (repl && err) { |
| 1856 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1857 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1858 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1859 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1860 | } |
| 1861 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1862 | 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] | 1863 | ret_code |= ERR_WARN; |
| 1864 | |
| 1865 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1866 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1867 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1868 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1869 | err: |
| 1870 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1871 | free(errmsg); |
| 1872 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1873 | } |
| 1874 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1875 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1876 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1877 | * Returns the error code, 0 if OK, or any combination of : |
| 1878 | * - ERR_ABORT: must abort ASAP |
| 1879 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1880 | * - ERR_WARN: a warning has been emitted |
| 1881 | * - ERR_ALERT: an alert has been emitted |
| 1882 | * Only the two first ones can stop processing, the two others are just |
| 1883 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1884 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1885 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1886 | { |
| 1887 | static struct peers *curpeers = NULL; |
| 1888 | struct peer *newpeer = NULL; |
| 1889 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1890 | struct bind_conf *bind_conf; |
| 1891 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1892 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1893 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1894 | |
| 1895 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1896 | if (!*args[1]) { |
| 1897 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1898 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1899 | goto out; |
| 1900 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1901 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1902 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1903 | goto out; |
| 1904 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1905 | err = invalid_char(args[1]); |
| 1906 | if (err) { |
| 1907 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1908 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1909 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1910 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 1914 | /* |
| 1915 | * If there are two proxies with the same name only following |
| 1916 | * combinations are allowed: |
| 1917 | */ |
| 1918 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1919 | 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] | 1920 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 1921 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1925 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1926 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1927 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
| 1931 | curpeers->next = peers; |
| 1932 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1933 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1934 | curpeers->conf.line = linenum; |
| 1935 | curpeers->last_change = now.tv_sec; |
| 1936 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 1937 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1938 | } |
| 1939 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1940 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1941 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1942 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1943 | |
| 1944 | if (!*args[2]) { |
| 1945 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 1946 | file, linenum, args[0]); |
| 1947 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1948 | goto out; |
| 1949 | } |
| 1950 | |
| 1951 | err = invalid_char(args[1]); |
| 1952 | if (err) { |
| 1953 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 1954 | file, linenum, *err, args[1]); |
| 1955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1956 | goto out; |
| 1957 | } |
| 1958 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1959 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1960 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1961 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1962 | goto out; |
| 1963 | } |
| 1964 | |
| 1965 | /* the peers are linked backwards first */ |
| 1966 | curpeers->count++; |
| 1967 | newpeer->next = curpeers->remote; |
| 1968 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 1969 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1970 | newpeer->conf.line = linenum; |
| 1971 | |
| 1972 | newpeer->last_change = now.tv_sec; |
| 1973 | newpeer->id = strdup(args[1]); |
| 1974 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 1975 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1976 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1977 | 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] | 1978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1979 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1980 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 1981 | |
| 1982 | proto = protocol_by_family(sk->ss_family); |
| 1983 | if (!proto || !proto->connect) { |
| 1984 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 1985 | file, linenum, args[0], args[1]); |
| 1986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1987 | goto out; |
| 1988 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1989 | |
| 1990 | if (port1 != port2) { |
| 1991 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 1992 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1994 | goto out; |
| 1995 | } |
| 1996 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 1997 | if (!port1) { |
| 1998 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 1999 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2001 | goto out; |
| 2002 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2003 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2004 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2005 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2006 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2007 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2008 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2009 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2010 | /* Current is local peer, it define a frontend */ |
| 2011 | newpeer->local = 1; |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 2012 | peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2013 | |
| 2014 | if (!curpeers->peers_fe) { |
| 2015 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2016 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2017 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2018 | goto out; |
| 2019 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2020 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2021 | init_new_proxy(curpeers->peers_fe); |
| 2022 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2023 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2024 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2025 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2026 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2027 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2028 | 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] | 2029 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2030 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2031 | if (errmsg && *errmsg) { |
| 2032 | indent_msg(&errmsg, 2); |
| 2033 | 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] | 2034 | } |
| 2035 | else |
| 2036 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2037 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2038 | err_code |= ERR_FATAL; |
| 2039 | goto out; |
| 2040 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2041 | |
| 2042 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2043 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2044 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2045 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2046 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2047 | l->handler = process_stream; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2048 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2049 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2050 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2051 | global.maxsock += l->maxconn; |
| 2052 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2053 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2054 | else { |
| 2055 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2056 | file, linenum, args[0], args[1], |
| 2057 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2058 | err_code |= ERR_FATAL; |
| 2059 | goto out; |
| 2060 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2061 | } |
| 2062 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2063 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2064 | curpeers->state = PR_STSTOPPED; |
| 2065 | } |
| 2066 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2067 | curpeers->state = PR_STNEW; |
| 2068 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2069 | else if (*args[0] != 0) { |
| 2070 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2072 | goto out; |
| 2073 | } |
| 2074 | |
| 2075 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2076 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2077 | return err_code; |
| 2078 | } |
| 2079 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2080 | /* |
| 2081 | * Parse a <resolvers> section. |
| 2082 | * Returns the error code, 0 if OK, or any combination of : |
| 2083 | * - ERR_ABORT: must abort ASAP |
| 2084 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2085 | * - ERR_WARN: a warning has been emitted |
| 2086 | * - ERR_ALERT: an alert has been emitted |
| 2087 | * Only the two first ones can stop processing, the two others are just |
| 2088 | * indicators. |
| 2089 | */ |
| 2090 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2091 | { |
| 2092 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2093 | struct dns_nameserver *newnameserver = NULL; |
| 2094 | const char *err; |
| 2095 | int err_code = 0; |
| 2096 | char *errmsg = NULL; |
| 2097 | |
| 2098 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2099 | if (!*args[1]) { |
| 2100 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2101 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2102 | goto out; |
| 2103 | } |
| 2104 | |
| 2105 | err = invalid_char(args[1]); |
| 2106 | if (err) { |
| 2107 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2108 | file, linenum, *err, args[0], args[1]); |
| 2109 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2110 | goto out; |
| 2111 | } |
| 2112 | |
| 2113 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2114 | /* Error if two resolvers owns the same name */ |
| 2115 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2116 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2117 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2118 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2119 | } |
| 2120 | } |
| 2121 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2122 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2123 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2124 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2125 | goto out; |
| 2126 | } |
| 2127 | |
| 2128 | /* default values */ |
| 2129 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2130 | curr_resolvers->conf.file = strdup(file); |
| 2131 | curr_resolvers->conf.line = linenum; |
| 2132 | curr_resolvers->id = strdup(args[1]); |
| 2133 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2134 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2135 | curr_resolvers->hold.nx = 30000; |
| 2136 | curr_resolvers->hold.other = 30000; |
| 2137 | curr_resolvers->hold.refused = 30000; |
| 2138 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2139 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2140 | curr_resolvers->hold.valid = 10000; |
| 2141 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2142 | curr_resolvers->resolve_retries = 3; |
| 2143 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2144 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2145 | } |
| 2146 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2147 | struct sockaddr_storage *sk; |
| 2148 | int port1, port2; |
| 2149 | struct protocol *proto; |
| 2150 | |
| 2151 | if (!*args[2]) { |
| 2152 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2153 | file, linenum, args[0]); |
| 2154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2155 | goto out; |
| 2156 | } |
| 2157 | |
| 2158 | err = invalid_char(args[1]); |
| 2159 | if (err) { |
| 2160 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2161 | file, linenum, *err, args[1]); |
| 2162 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2163 | goto out; |
| 2164 | } |
| 2165 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2166 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2167 | /* Error if two resolvers owns the same name */ |
| 2168 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2169 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2170 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2172 | } |
| 2173 | } |
| 2174 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2175 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2176 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2177 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
| 2181 | /* the nameservers are linked backward first */ |
| 2182 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2183 | curr_resolvers->count_nameservers++; |
| 2184 | newnameserver->resolvers = curr_resolvers; |
| 2185 | newnameserver->conf.file = strdup(file); |
| 2186 | newnameserver->conf.line = linenum; |
| 2187 | newnameserver->id = strdup(args[1]); |
| 2188 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2189 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2190 | if (!sk) { |
| 2191 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2193 | goto out; |
| 2194 | } |
| 2195 | |
| 2196 | proto = protocol_by_family(sk->ss_family); |
| 2197 | if (!proto || !proto->connect) { |
| 2198 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2199 | file, linenum, args[0], args[1]); |
| 2200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2201 | goto out; |
| 2202 | } |
| 2203 | |
| 2204 | if (port1 != port2) { |
| 2205 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2206 | file, linenum, args[0], args[1], args[2]); |
| 2207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2208 | goto out; |
| 2209 | } |
| 2210 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2211 | if (!port1 && !port2) { |
| 2212 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2213 | file, linenum, args[0], args[1]); |
| 2214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2215 | goto out; |
| 2216 | } |
| 2217 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2218 | newnameserver->addr = *sk; |
| 2219 | } |
| 2220 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2221 | const char *res; |
| 2222 | unsigned int time; |
| 2223 | |
| 2224 | if (!*args[2]) { |
| 2225 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2226 | file, linenum, args[0]); |
| 2227 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2229 | goto out; |
| 2230 | } |
| 2231 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2232 | if (res) { |
| 2233 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2234 | file, linenum, *res, args[0]); |
| 2235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2236 | goto out; |
| 2237 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2238 | if (strcmp(args[1], "nx") == 0) |
| 2239 | curr_resolvers->hold.nx = time; |
| 2240 | else if (strcmp(args[1], "other") == 0) |
| 2241 | curr_resolvers->hold.other = time; |
| 2242 | else if (strcmp(args[1], "refused") == 0) |
| 2243 | curr_resolvers->hold.refused = time; |
| 2244 | else if (strcmp(args[1], "timeout") == 0) |
| 2245 | curr_resolvers->hold.timeout = time; |
| 2246 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2247 | curr_resolvers->hold.valid = time; |
| 2248 | else { |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2249 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', or 'other'.\n", |
| 2250 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2252 | goto out; |
| 2253 | } |
| 2254 | |
| 2255 | } |
| 2256 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2257 | if (!*args[1]) { |
| 2258 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2259 | file, linenum, args[0]); |
| 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2261 | goto out; |
| 2262 | } |
| 2263 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2264 | } |
| 2265 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2266 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2267 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2268 | file, linenum, args[0]); |
| 2269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2270 | goto out; |
| 2271 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2272 | else if (strcmp(args[1], "retry") == 0) { |
| 2273 | const char *res; |
| 2274 | unsigned int timeout_retry; |
| 2275 | |
| 2276 | if (!*args[2]) { |
| 2277 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2278 | file, linenum, args[0], args[1]); |
| 2279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2280 | goto out; |
| 2281 | } |
| 2282 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2283 | if (res) { |
| 2284 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2285 | file, linenum, *res, args[0], args[1]); |
| 2286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2287 | goto out; |
| 2288 | } |
| 2289 | curr_resolvers->timeout.retry = timeout_retry; |
| 2290 | } |
| 2291 | else { |
| 2292 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2293 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2295 | goto out; |
| 2296 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2297 | } /* neither "nameserver" nor "resolvers" */ |
| 2298 | else if (*args[0] != 0) { |
| 2299 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2301 | goto out; |
| 2302 | } |
| 2303 | |
| 2304 | out: |
| 2305 | free(errmsg); |
| 2306 | return err_code; |
| 2307 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2308 | |
| 2309 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2310 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2311 | * Returns the error code, 0 if OK, or any combination of : |
| 2312 | * - ERR_ABORT: must abort ASAP |
| 2313 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2314 | * - ERR_WARN: a warning has been emitted |
| 2315 | * - ERR_ALERT: an alert has been emitted |
| 2316 | * Only the two first ones can stop processing, the two others are just |
| 2317 | * indicators. |
| 2318 | */ |
| 2319 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2320 | { |
| 2321 | static struct mailers *curmailers = NULL; |
| 2322 | struct mailer *newmailer = NULL; |
| 2323 | const char *err; |
| 2324 | int err_code = 0; |
| 2325 | char *errmsg = NULL; |
| 2326 | |
| 2327 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2328 | if (!*args[1]) { |
| 2329 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2330 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2331 | goto out; |
| 2332 | } |
| 2333 | |
| 2334 | err = invalid_char(args[1]); |
| 2335 | if (err) { |
| 2336 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2337 | file, linenum, *err, args[0], args[1]); |
| 2338 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2339 | goto out; |
| 2340 | } |
| 2341 | |
| 2342 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2343 | /* |
| 2344 | * If there are two proxies with the same name only following |
| 2345 | * combinations are allowed: |
| 2346 | */ |
| 2347 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2348 | 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] | 2349 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2350 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2354 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2355 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2356 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2357 | goto out; |
| 2358 | } |
| 2359 | |
| 2360 | curmailers->next = mailers; |
| 2361 | mailers = curmailers; |
| 2362 | curmailers->conf.file = strdup(file); |
| 2363 | curmailers->conf.line = linenum; |
| 2364 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2365 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2366 | * But need enough time so that timeouts don't occur |
| 2367 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2368 | } |
| 2369 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2370 | struct sockaddr_storage *sk; |
| 2371 | int port1, port2; |
| 2372 | struct protocol *proto; |
| 2373 | |
| 2374 | if (!*args[2]) { |
| 2375 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2376 | file, linenum, args[0]); |
| 2377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2378 | goto out; |
| 2379 | } |
| 2380 | |
| 2381 | err = invalid_char(args[1]); |
| 2382 | if (err) { |
| 2383 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2384 | file, linenum, *err, args[1]); |
| 2385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2386 | goto out; |
| 2387 | } |
| 2388 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2389 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2390 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2391 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2392 | goto out; |
| 2393 | } |
| 2394 | |
| 2395 | /* the mailers are linked backwards first */ |
| 2396 | curmailers->count++; |
| 2397 | newmailer->next = curmailers->mailer_list; |
| 2398 | curmailers->mailer_list = newmailer; |
| 2399 | newmailer->mailers = curmailers; |
| 2400 | newmailer->conf.file = strdup(file); |
| 2401 | newmailer->conf.line = linenum; |
| 2402 | |
| 2403 | newmailer->id = strdup(args[1]); |
| 2404 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2405 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2406 | if (!sk) { |
| 2407 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | |
| 2412 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2413 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2414 | 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] | 2415 | file, linenum, args[0], args[1]); |
| 2416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2417 | goto out; |
| 2418 | } |
| 2419 | |
| 2420 | if (port1 != port2) { |
| 2421 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2422 | file, linenum, args[0], args[1], args[2]); |
| 2423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2424 | goto out; |
| 2425 | } |
| 2426 | |
| 2427 | if (!port1) { |
| 2428 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2429 | file, linenum, args[0], args[1], args[2]); |
| 2430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2431 | goto out; |
| 2432 | } |
| 2433 | |
| 2434 | newmailer->addr = *sk; |
| 2435 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2436 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2437 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2438 | } |
| 2439 | else if (strcmp(args[0], "timeout") == 0) { |
| 2440 | if (!*args[1]) { |
| 2441 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2442 | file, linenum, args[0]); |
| 2443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2444 | goto out; |
| 2445 | } |
| 2446 | else if (strcmp(args[1], "mail") == 0) { |
| 2447 | const char *res; |
| 2448 | unsigned int timeout_mail; |
| 2449 | if (!*args[2]) { |
| 2450 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2451 | file, linenum, args[0], args[1]); |
| 2452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2453 | goto out; |
| 2454 | } |
| 2455 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2456 | if (res) { |
| 2457 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2458 | file, linenum, *res, args[0]); |
| 2459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2460 | goto out; |
| 2461 | } |
| 2462 | if (timeout_mail <= 0) { |
| 2463 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2465 | goto out; |
| 2466 | } |
| 2467 | curmailers->timeout.mail = timeout_mail; |
| 2468 | } else { |
| 2469 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2470 | file, linenum, args[0], args[1]); |
| 2471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2472 | goto out; |
| 2473 | } |
| 2474 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2475 | else if (*args[0] != 0) { |
| 2476 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2477 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2478 | goto out; |
| 2479 | } |
| 2480 | |
| 2481 | out: |
| 2482 | free(errmsg); |
| 2483 | return err_code; |
| 2484 | } |
| 2485 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2486 | static void free_email_alert(struct proxy *p) |
| 2487 | { |
| 2488 | free(p->email_alert.mailers.name); |
| 2489 | p->email_alert.mailers.name = NULL; |
| 2490 | free(p->email_alert.from); |
| 2491 | p->email_alert.from = NULL; |
| 2492 | free(p->email_alert.to); |
| 2493 | p->email_alert.to = NULL; |
| 2494 | free(p->email_alert.myhostname); |
| 2495 | p->email_alert.myhostname = NULL; |
| 2496 | } |
| 2497 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2498 | 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] | 2499 | { |
| 2500 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2501 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2502 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2503 | int rc; |
| 2504 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2505 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2506 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2507 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2508 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2509 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2510 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2511 | if (!strcmp(args[0], "listen")) |
| 2512 | rc = PR_CAP_LISTEN; |
| 2513 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2514 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2515 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2516 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2517 | else |
| 2518 | rc = PR_CAP_NONE; |
| 2519 | |
| 2520 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2521 | if (!*args[1]) { |
| 2522 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2523 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2524 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2525 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2526 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2527 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2528 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2529 | err = invalid_char(args[1]); |
| 2530 | if (err) { |
| 2531 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2532 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2533 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2534 | } |
| 2535 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2536 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2537 | if (curproxy) { |
| 2538 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2539 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2540 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2541 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2544 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2545 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2546 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2548 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2549 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2550 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2551 | curproxy->next = proxy; |
| 2552 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2553 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2554 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2555 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2556 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2557 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2558 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2559 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2560 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2561 | if (curproxy->cap & PR_CAP_FE) |
| 2562 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2563 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2567 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2568 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2570 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2571 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2572 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2573 | curproxy->no_options = defproxy.no_options; |
| 2574 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2575 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2576 | curproxy->except_net = defproxy.except_net; |
| 2577 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2578 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2579 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2580 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2581 | if (defproxy.fwdfor_hdr_len) { |
| 2582 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2583 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2584 | } |
| 2585 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2586 | if (defproxy.orgto_hdr_len) { |
| 2587 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2588 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2589 | } |
| 2590 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2591 | if (defproxy.server_id_hdr_len) { |
| 2592 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2593 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2594 | } |
| 2595 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2596 | if (curproxy->cap & PR_CAP_FE) { |
| 2597 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2598 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2599 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2600 | |
| 2601 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2602 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2603 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2604 | |
| 2605 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2606 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2607 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2608 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2609 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2610 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2611 | curproxy->fullconn = defproxy.fullconn; |
| 2612 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2613 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2614 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2615 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2616 | if (defproxy.check_req) { |
| 2617 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2618 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2619 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2620 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2621 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2622 | if (defproxy.expect_str) { |
| 2623 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2624 | if (defproxy.expect_regex) { |
| 2625 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2626 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2627 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2631 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2632 | if (defproxy.cookie_name) |
| 2633 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2634 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2635 | if (defproxy.cookie_domain) |
| 2636 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2637 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2638 | if (defproxy.cookie_maxidle) |
| 2639 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2640 | |
| 2641 | if (defproxy.cookie_maxlife) |
| 2642 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2643 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2644 | if (defproxy.rdp_cookie_name) |
| 2645 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2646 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2647 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2648 | if (defproxy.url_param_name) |
| 2649 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2650 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2651 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2652 | if (defproxy.hh_name) |
| 2653 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2654 | curproxy->hh_len = defproxy.hh_len; |
| 2655 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2656 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2657 | if (defproxy.conn_src.iface_name) |
| 2658 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2659 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2660 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2661 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2662 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2663 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2664 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2665 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2666 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2667 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2668 | if (defproxy.capture_name) |
| 2669 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2670 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2671 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2672 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2673 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2674 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2675 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2676 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2677 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2678 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2679 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2680 | curproxy->mon_net = defproxy.mon_net; |
| 2681 | curproxy->mon_mask = defproxy.mon_mask; |
| 2682 | if (defproxy.monitor_uri) |
| 2683 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2684 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2685 | if (defproxy.defbe.name) |
| 2686 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2687 | |
| 2688 | /* 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] | 2689 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2690 | if (curproxy->conf.logformat_string && |
| 2691 | curproxy->conf.logformat_string != default_http_log_format && |
| 2692 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2693 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2694 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2695 | |
| 2696 | if (defproxy.conf.lfs_file) { |
| 2697 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2698 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2699 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2700 | |
| 2701 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2702 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2703 | if (curproxy->conf.logformat_sd_string && |
| 2704 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2705 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2706 | |
| 2707 | if (defproxy.conf.lfsd_file) { |
| 2708 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2709 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2710 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2714 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2715 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2716 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2717 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2718 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2719 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2720 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2721 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2722 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2723 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2724 | } |
| 2725 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2726 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2727 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2728 | |
| 2729 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2730 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2731 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2732 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2733 | LIST_INIT(&node->list); |
| 2734 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2735 | } |
| 2736 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2737 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2738 | if (curproxy->conf.uniqueid_format_string) |
| 2739 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2740 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2741 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2742 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2743 | if (defproxy.conf.uif_file) { |
| 2744 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2745 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2746 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2747 | |
| 2748 | /* copy default header unique id */ |
| 2749 | if (defproxy.header_unique_id) |
| 2750 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2751 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2752 | /* default compression options */ |
| 2753 | if (defproxy.comp != NULL) { |
| 2754 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2755 | curproxy->comp->algos = defproxy.comp->algos; |
| 2756 | curproxy->comp->types = defproxy.comp->types; |
| 2757 | } |
| 2758 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2759 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2760 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2761 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2762 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2763 | if (defproxy.check_path) |
| 2764 | curproxy->check_path = strdup(defproxy.check_path); |
| 2765 | if (defproxy.check_command) |
| 2766 | curproxy->check_command = strdup(defproxy.check_command); |
| 2767 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2768 | if (defproxy.email_alert.mailers.name) |
| 2769 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 2770 | if (defproxy.email_alert.from) |
| 2771 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 2772 | if (defproxy.email_alert.to) |
| 2773 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 2774 | if (defproxy.email_alert.myhostname) |
| 2775 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2776 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 2777 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2778 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2779 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2780 | } |
| 2781 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 2782 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2783 | /* FIXME-20070101: we should do this too at the end of the |
| 2784 | * config parsing to free all default values. |
| 2785 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2786 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2787 | err_code |= ERR_ABORT; |
| 2788 | goto out; |
| 2789 | } |
| 2790 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2791 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2792 | free(defproxy.check_command); |
| 2793 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2794 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2795 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2796 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2797 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2798 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2799 | free(defproxy.capture_name); |
| 2800 | free(defproxy.monitor_uri); |
| 2801 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2802 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2803 | free(defproxy.fwdfor_hdr_name); |
| 2804 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2805 | free(defproxy.orgto_hdr_name); |
| 2806 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2807 | free(defproxy.server_id_hdr_name); |
| 2808 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2809 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2810 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2811 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 2812 | free(defproxy.expect_regex); |
| 2813 | defproxy.expect_regex = NULL; |
| 2814 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2815 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2816 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 2817 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 2818 | defproxy.conf.logformat_string != clf_http_log_format) |
| 2819 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2820 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2821 | free(defproxy.conf.uniqueid_format_string); |
| 2822 | free(defproxy.conf.lfs_file); |
| 2823 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2824 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2825 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 2826 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2827 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2828 | free(defproxy.conf.logformat_sd_string); |
| 2829 | free(defproxy.conf.lfsd_file); |
| 2830 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2831 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2832 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2833 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2834 | /* we cannot free uri_auth because it might already be used */ |
| 2835 | init_default_instance(); |
| 2836 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2837 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2838 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2839 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2841 | } |
| 2842 | else if (curproxy == NULL) { |
| 2843 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2845 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2846 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2847 | |
| 2848 | /* update the current file and line being parsed */ |
| 2849 | curproxy->conf.args.file = curproxy->conf.file; |
| 2850 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2851 | |
| 2852 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 2853 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 2854 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 2855 | if (err_code & ERR_FATAL) |
| 2856 | goto out; |
| 2857 | } |
| 2858 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2859 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2860 | int cur_arg; |
| 2861 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2862 | if (curproxy == &defproxy) { |
| 2863 | 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] | 2864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2865 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2866 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2867 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2868 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2869 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 2870 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 2871 | 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] | 2872 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2874 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2875 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2876 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2877 | 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] | 2878 | |
| 2879 | /* use default settings for unix sockets */ |
| 2880 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 2881 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 2882 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 2883 | |
| 2884 | /* NOTE: the following line might create several listeners if there |
| 2885 | * are comma-separated IPs or port ranges. So all further processing |
| 2886 | * will have to be applied to all listeners created after last_listen. |
| 2887 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2888 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 2889 | if (errmsg && *errmsg) { |
| 2890 | indent_msg(&errmsg, 2); |
| 2891 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 2892 | } |
| 2893 | else |
| 2894 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 2895 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2897 | goto out; |
| 2898 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2899 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2900 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 2901 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 2902 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 2903 | } |
| 2904 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 2905 | cur_arg = 2; |
| 2906 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2907 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2908 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2909 | char *err; |
| 2910 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2911 | kw = bind_find_kw(args[cur_arg]); |
| 2912 | if (kw) { |
| 2913 | char *err = NULL; |
| 2914 | int code; |
| 2915 | |
| 2916 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2917 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 2918 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2919 | cur_arg += 1 + kw->skip ; |
| 2920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2921 | goto out; |
| 2922 | } |
| 2923 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2924 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2925 | err_code |= code; |
| 2926 | |
| 2927 | if (code) { |
| 2928 | if (err && *err) { |
| 2929 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2930 | 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] | 2931 | } |
| 2932 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 2933 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 2934 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 2935 | if (code & ERR_FATAL) { |
| 2936 | free(err); |
| 2937 | cur_arg += 1 + kw->skip; |
| 2938 | goto out; |
| 2939 | } |
| 2940 | } |
| 2941 | free(err); |
| 2942 | cur_arg += 1 + kw->skip; |
| 2943 | continue; |
| 2944 | } |
| 2945 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 2946 | err = NULL; |
| 2947 | if (!bind_dumped) { |
| 2948 | bind_dump_kws(&err); |
| 2949 | indent_msg(&err, 4); |
| 2950 | bind_dumped = 1; |
| 2951 | } |
| 2952 | |
| 2953 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 2954 | file, linenum, args[0], args[1], args[cur_arg], |
| 2955 | err ? " Registered keywords :" : "", err ? err : ""); |
| 2956 | free(err); |
| 2957 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2959 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 2960 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2961 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2962 | } |
| 2963 | 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] | 2964 | 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] | 2965 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 2966 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2968 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2969 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2970 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2971 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2972 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2973 | /* flush useless bits */ |
| 2974 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2975 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2976 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2977 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2978 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2979 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2980 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 2981 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2982 | goto out; |
| 2983 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2984 | if (!*args[1]) { |
| 2985 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 2986 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2988 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 2991 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2992 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2993 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 2994 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2995 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 2996 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2997 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2998 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2999 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3000 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3001 | goto out; |
| 3002 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3003 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3004 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3005 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3006 | else { |
| 3007 | 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] | 3008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3009 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3010 | } |
| 3011 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3012 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3013 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3014 | |
| 3015 | if (curproxy == &defproxy) { |
| 3016 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\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; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3020 | } |
| 3021 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3022 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3023 | goto out; |
| 3024 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3025 | if (!*args[1]) { |
| 3026 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3027 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3029 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3033 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3034 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3035 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3036 | if (curproxy->uuid <= 0) { |
| 3037 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3038 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3039 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3040 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3041 | } |
| 3042 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3043 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3044 | if (node) { |
| 3045 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3046 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3047 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3048 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3050 | goto out; |
| 3051 | } |
| 3052 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3053 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3054 | else if (!strcmp(args[0], "description")) { |
| 3055 | int i, len=0; |
| 3056 | char *d; |
| 3057 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3058 | if (curproxy == &defproxy) { |
| 3059 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3060 | file, linenum, args[0]); |
| 3061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3062 | goto out; |
| 3063 | } |
| 3064 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3065 | if (!*args[1]) { |
| 3066 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3067 | file, linenum, args[0]); |
| 3068 | return -1; |
| 3069 | } |
| 3070 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3071 | for (i = 1; *args[i]; i++) |
| 3072 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3073 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3074 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3075 | curproxy->desc = d; |
| 3076 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3077 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3078 | for (i = 2; *args[i]; i++) |
| 3079 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3080 | |
| 3081 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3082 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3083 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3085 | curproxy->state = PR_STSTOPPED; |
| 3086 | } |
| 3087 | 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] | 3088 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3089 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3090 | curproxy->state = PR_STNEW; |
| 3091 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3092 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3093 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3094 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3095 | |
| 3096 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3097 | unsigned int low, high; |
| 3098 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3099 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3100 | set = 0; |
| 3101 | break; |
| 3102 | } |
| 3103 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3104 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3105 | } |
| 3106 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3107 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3108 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3109 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3110 | char *dash = strchr(args[cur_arg], '-'); |
| 3111 | |
| 3112 | low = high = str2uic(args[cur_arg]); |
| 3113 | if (dash) |
| 3114 | high = str2uic(dash + 1); |
| 3115 | |
| 3116 | if (high < low) { |
| 3117 | unsigned int swap = low; |
| 3118 | low = high; |
| 3119 | high = swap; |
| 3120 | } |
| 3121 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3122 | if (low < 1 || high > LONGBITS) { |
| 3123 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3124 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3126 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3127 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3128 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3129 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3130 | } |
| 3131 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3132 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3133 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3134 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3135 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3136 | } |
| 3137 | cur_arg++; |
| 3138 | } |
| 3139 | curproxy->bind_proc = set; |
| 3140 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3141 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3142 | if (curproxy == &defproxy) { |
| 3143 | 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] | 3144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3145 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3146 | } |
| 3147 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3148 | err = invalid_char(args[1]); |
| 3149 | if (err) { |
| 3150 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3151 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3152 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3153 | } |
| 3154 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3155 | 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] | 3156 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3157 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3159 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3160 | } |
| 3161 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3162 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3163 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3164 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3165 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3166 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3167 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3168 | if (*(args[1]) == 0) { |
| 3169 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3170 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3172 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3173 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3174 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3175 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3176 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3177 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3178 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3179 | curproxy->cookie_name = strdup(args[1]); |
| 3180 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3181 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3182 | cur_arg = 2; |
| 3183 | while (*(args[cur_arg])) { |
| 3184 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3185 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3186 | } |
| 3187 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3188 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3189 | } |
| 3190 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3191 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3192 | } |
| 3193 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3194 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3195 | } |
| 3196 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3197 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3198 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3199 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3200 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3201 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3202 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3203 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3204 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3205 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3206 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3207 | } |
| 3208 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3209 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3210 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3211 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3212 | if (!*args[cur_arg + 1]) { |
| 3213 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3214 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3216 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3217 | } |
| 3218 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3219 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3220 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3221 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3222 | " dots nor does not start with a dot." |
| 3223 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3224 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3225 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3229 | if (err) { |
| 3230 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3231 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3233 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3234 | } |
| 3235 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3236 | if (!curproxy->cookie_domain) { |
| 3237 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3238 | } else { |
| 3239 | /* one domain was already specified, add another one by |
| 3240 | * building the string which will be returned along with |
| 3241 | * the cookie. |
| 3242 | */ |
| 3243 | char *new_ptr; |
| 3244 | int new_len = strlen(curproxy->cookie_domain) + |
| 3245 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3246 | new_ptr = malloc(new_len); |
| 3247 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3248 | free(curproxy->cookie_domain); |
| 3249 | curproxy->cookie_domain = new_ptr; |
| 3250 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3251 | cur_arg++; |
| 3252 | } |
| 3253 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3254 | unsigned int maxidle; |
| 3255 | const char *res; |
| 3256 | |
| 3257 | if (!*args[cur_arg + 1]) { |
| 3258 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3259 | file, linenum, args[cur_arg]); |
| 3260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3261 | goto out; |
| 3262 | } |
| 3263 | |
| 3264 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3265 | if (res) { |
| 3266 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3267 | file, linenum, *res, args[cur_arg]); |
| 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3269 | goto out; |
| 3270 | } |
| 3271 | curproxy->cookie_maxidle = maxidle; |
| 3272 | cur_arg++; |
| 3273 | } |
| 3274 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3275 | unsigned int maxlife; |
| 3276 | const char *res; |
| 3277 | |
| 3278 | if (!*args[cur_arg + 1]) { |
| 3279 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3280 | file, linenum, args[cur_arg]); |
| 3281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3282 | goto out; |
| 3283 | } |
| 3284 | |
| 3285 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3286 | if (res) { |
| 3287 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3288 | file, linenum, *res, args[cur_arg]); |
| 3289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3290 | goto out; |
| 3291 | } |
| 3292 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3293 | cur_arg++; |
| 3294 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3295 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3296 | Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3298 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3299 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3300 | } |
| 3301 | cur_arg++; |
| 3302 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3303 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3304 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3305 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3306 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3307 | } |
| 3308 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3309 | 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] | 3310 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3311 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3312 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3313 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3314 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3315 | 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] | 3316 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3317 | file, linenum); |
| 3318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3319 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3320 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3321 | else if (!strcmp(args[0], "email-alert")) { |
| 3322 | if (*(args[1]) == 0) { |
| 3323 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3324 | file, linenum, args[0]); |
| 3325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3326 | goto out; |
| 3327 | } |
| 3328 | |
| 3329 | if (!strcmp(args[1], "from")) { |
| 3330 | if (*(args[1]) == 0) { |
| 3331 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3332 | file, linenum, args[1]); |
| 3333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3334 | goto out; |
| 3335 | } |
| 3336 | free(curproxy->email_alert.from); |
| 3337 | curproxy->email_alert.from = strdup(args[2]); |
| 3338 | } |
| 3339 | else if (!strcmp(args[1], "mailers")) { |
| 3340 | if (*(args[1]) == 0) { |
| 3341 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3342 | file, linenum, args[1]); |
| 3343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3344 | goto out; |
| 3345 | } |
| 3346 | free(curproxy->email_alert.mailers.name); |
| 3347 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3348 | } |
| 3349 | else if (!strcmp(args[1], "myhostname")) { |
| 3350 | if (*(args[1]) == 0) { |
| 3351 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3352 | file, linenum, args[1]); |
| 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
| 3355 | } |
| 3356 | free(curproxy->email_alert.myhostname); |
| 3357 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3358 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3359 | else if (!strcmp(args[1], "level")) { |
| 3360 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3361 | if (curproxy->email_alert.level < 0) { |
| 3362 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3363 | file, linenum, args[1], args[2]); |
| 3364 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3365 | goto out; |
| 3366 | } |
| 3367 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3368 | else if (!strcmp(args[1], "to")) { |
| 3369 | if (*(args[1]) == 0) { |
| 3370 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3371 | file, linenum, args[1]); |
| 3372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3373 | goto out; |
| 3374 | } |
| 3375 | free(curproxy->email_alert.to); |
| 3376 | curproxy->email_alert.to = strdup(args[2]); |
| 3377 | } |
| 3378 | else { |
| 3379 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3380 | file, linenum, args[1]); |
| 3381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3382 | goto out; |
| 3383 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3384 | /* Indicate that the email_alert is at least partially configured */ |
| 3385 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3386 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3387 | else if (!strcmp(args[0], "external-check")) { |
| 3388 | if (*(args[1]) == 0) { |
| 3389 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3390 | file, linenum, args[0]); |
| 3391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3392 | goto out; |
| 3393 | } |
| 3394 | |
| 3395 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3396 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3397 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3398 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3399 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3400 | file, linenum, args[1]); |
| 3401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3402 | goto out; |
| 3403 | } |
| 3404 | free(curproxy->check_command); |
| 3405 | curproxy->check_command = strdup(args[2]); |
| 3406 | } |
| 3407 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3408 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3409 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3410 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3411 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3412 | file, linenum, args[1]); |
| 3413 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3414 | goto out; |
| 3415 | } |
| 3416 | free(curproxy->check_path); |
| 3417 | curproxy->check_path = strdup(args[2]); |
| 3418 | } |
| 3419 | else { |
| 3420 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3421 | file, linenum, args[1]); |
| 3422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3423 | goto out; |
| 3424 | } |
| 3425 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3426 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3427 | if (*(args[1]) == 0) { |
| 3428 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3429 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3431 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3435 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3436 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3437 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3438 | const char *beg, *end; |
| 3439 | |
| 3440 | beg = args[1] + 11; |
| 3441 | end = strchr(beg, ')'); |
| 3442 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3443 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3444 | goto out; |
| 3445 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3446 | if (!end || end == beg) { |
| 3447 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3448 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3450 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | free(curproxy->rdp_cookie_name); |
| 3454 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3455 | curproxy->rdp_cookie_len = end-beg; |
| 3456 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3457 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3458 | free(curproxy->rdp_cookie_name); |
| 3459 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3460 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3461 | } |
| 3462 | else { /* syntax */ |
| 3463 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3464 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3466 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3467 | } |
| 3468 | } |
| 3469 | else { |
| 3470 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3471 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3473 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3474 | } |
| 3475 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3476 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3477 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3479 | goto out; |
| 3480 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3481 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3482 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3483 | err_code |= ERR_WARN; |
| 3484 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3485 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3486 | } |
| 3487 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3488 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3489 | } |
| 3490 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3491 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3492 | } |
| 3493 | else { |
| 3494 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3495 | file, linenum, args[0], args[1]); |
| 3496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3497 | goto out; |
| 3498 | } |
| 3499 | } |
| 3500 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3501 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3502 | err_code |= ERR_WARN; |
| 3503 | if (*(args[1]) == 0) { |
| 3504 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3505 | file, linenum, args[0]); |
| 3506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3507 | goto out; |
| 3508 | } |
| 3509 | else if (!strcmp(args[1], "use-backend-name")) |
| 3510 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3511 | else |
| 3512 | curproxy->server_state_file_name = strdup(args[1]); |
| 3513 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3514 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3515 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3516 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3517 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3518 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3519 | if (curproxy == &defproxy) { |
| 3520 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3522 | goto out; |
| 3523 | } |
| 3524 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3525 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3526 | goto out; |
| 3527 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3528 | if (*(args[4]) == 0) { |
| 3529 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3530 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3532 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3533 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3534 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3535 | curproxy->capture_name = strdup(args[2]); |
| 3536 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3537 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3538 | curproxy->to_log |= LW_COOKIE; |
| 3539 | } |
| 3540 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3541 | struct cap_hdr *hdr; |
| 3542 | |
| 3543 | if (curproxy == &defproxy) { |
| 3544 | 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] | 3545 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3546 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3547 | } |
| 3548 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3549 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3550 | goto out; |
| 3551 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3552 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3553 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3554 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3556 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3557 | } |
| 3558 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3559 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3560 | hdr->next = curproxy->req_cap; |
| 3561 | hdr->name = strdup(args[3]); |
| 3562 | hdr->namelen = strlen(args[3]); |
| 3563 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3564 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3565 | hdr->index = curproxy->nb_req_cap++; |
| 3566 | curproxy->req_cap = hdr; |
| 3567 | curproxy->to_log |= LW_REQHDR; |
| 3568 | } |
| 3569 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3570 | struct cap_hdr *hdr; |
| 3571 | |
| 3572 | if (curproxy == &defproxy) { |
| 3573 | 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] | 3574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3575 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3576 | } |
| 3577 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3578 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3579 | goto out; |
| 3580 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3581 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3582 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3583 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3585 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3586 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3587 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3588 | hdr->next = curproxy->rsp_cap; |
| 3589 | hdr->name = strdup(args[3]); |
| 3590 | hdr->namelen = strlen(args[3]); |
| 3591 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3592 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3593 | hdr->index = curproxy->nb_rsp_cap++; |
| 3594 | curproxy->rsp_cap = hdr; |
| 3595 | curproxy->to_log |= LW_RSPHDR; |
| 3596 | } |
| 3597 | else { |
| 3598 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3599 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3601 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3602 | } |
| 3603 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3604 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3605 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3606 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3607 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3608 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3609 | goto out; |
| 3610 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3611 | if (*(args[1]) == 0) { |
| 3612 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3613 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3616 | } |
| 3617 | curproxy->conn_retries = atol(args[1]); |
| 3618 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3619 | 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] | 3620 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3621 | |
| 3622 | if (curproxy == &defproxy) { |
| 3623 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3625 | goto out; |
| 3626 | } |
| 3627 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3628 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3629 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3630 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3631 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3632 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3633 | 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] | 3634 | 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] | 3635 | file, linenum, args[0]); |
| 3636 | err_code |= ERR_WARN; |
| 3637 | } |
| 3638 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3639 | 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] | 3640 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3641 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3642 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3643 | goto out; |
| 3644 | } |
| 3645 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3646 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3647 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3648 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3649 | file, linenum); |
| 3650 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3651 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3652 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3653 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3654 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3655 | |
| 3656 | if (curproxy == &defproxy) { |
| 3657 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3658 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3659 | goto out; |
| 3660 | } |
| 3661 | |
| 3662 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3663 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3664 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3665 | 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] | 3666 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3667 | file, linenum, args[0]); |
| 3668 | err_code |= ERR_WARN; |
| 3669 | } |
| 3670 | |
| 3671 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3672 | |
| 3673 | if (!rule) { |
| 3674 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3675 | goto out; |
| 3676 | } |
| 3677 | |
| 3678 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3679 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3680 | file, linenum); |
| 3681 | |
| 3682 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3683 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3684 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3685 | /* set the header name and length into the proxy structure */ |
| 3686 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3687 | err_code |= ERR_WARN; |
| 3688 | |
| 3689 | if (!*args[1]) { |
| 3690 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3691 | file, linenum, args[0]); |
| 3692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3693 | goto out; |
| 3694 | } |
| 3695 | |
| 3696 | /* set the desired header name */ |
| 3697 | free(curproxy->server_id_hdr_name); |
| 3698 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3699 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3700 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3701 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3702 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3703 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3704 | if (curproxy == &defproxy) { |
| 3705 | 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] | 3706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3707 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3708 | } |
| 3709 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3710 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3711 | * be processed before all http-request rules, we put them into their own list |
| 3712 | * and will insert them at the end. |
| 3713 | */ |
| 3714 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3715 | if (!rule) { |
| 3716 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3717 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3718 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3719 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 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 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3724 | |
| 3725 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3726 | 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]); |
| 3727 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3728 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3729 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3730 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3731 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3732 | if (curproxy == &defproxy) { |
| 3733 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3735 | goto out; |
| 3736 | } |
| 3737 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3738 | 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] | 3739 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3740 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3742 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3743 | } |
| 3744 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3745 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3746 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3747 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3748 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3749 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3750 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3751 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3752 | struct switching_rule *rule; |
| 3753 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3754 | if (curproxy == &defproxy) { |
| 3755 | 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] | 3756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3757 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3758 | } |
| 3759 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3760 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3761 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3762 | |
| 3763 | if (*(args[1]) == 0) { |
| 3764 | 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] | 3765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3766 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3767 | } |
| 3768 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3769 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 3770 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3771 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3772 | file, linenum, errmsg); |
| 3773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3774 | goto out; |
| 3775 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3776 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 3777 | 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] | 3778 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 3779 | else if (*args[2]) { |
| 3780 | Alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 3781 | file, linenum, args[2]); |
| 3782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3783 | goto out; |
| 3784 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3785 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3786 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 3787 | if (!rule) { |
| 3788 | Alert("Out of memory error.\n"); |
| 3789 | goto out; |
| 3790 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3791 | rule->cond = cond; |
| 3792 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 3793 | rule->line = linenum; |
| 3794 | rule->file = strdup(file); |
| 3795 | if (!rule->file) { |
| 3796 | Alert("Out of memory error.\n"); |
| 3797 | goto out; |
| 3798 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3799 | LIST_INIT(&rule->list); |
| 3800 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 3801 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3802 | else if (strcmp(args[0], "use-server") == 0) { |
| 3803 | struct server_rule *rule; |
| 3804 | |
| 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 | |
| 3811 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3812 | err_code |= ERR_WARN; |
| 3813 | |
| 3814 | if (*(args[1]) == 0) { |
| 3815 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 3816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3817 | goto out; |
| 3818 | } |
| 3819 | |
| 3820 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 3821 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3822 | file, linenum, args[0]); |
| 3823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3824 | goto out; |
| 3825 | } |
| 3826 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3827 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 3828 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 3829 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3831 | goto out; |
| 3832 | } |
| 3833 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3834 | 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] | 3835 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3836 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 3837 | rule->cond = cond; |
| 3838 | rule->srv.name = strdup(args[1]); |
| 3839 | LIST_INIT(&rule->list); |
| 3840 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 3841 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 3842 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3843 | else if ((!strcmp(args[0], "force-persist")) || |
| 3844 | (!strcmp(args[0], "ignore-persist"))) { |
| 3845 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3846 | |
| 3847 | if (curproxy == &defproxy) { |
| 3848 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3850 | goto out; |
| 3851 | } |
| 3852 | |
| 3853 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3854 | err_code |= ERR_WARN; |
| 3855 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 3856 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3857 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 3858 | file, linenum, args[0]); |
| 3859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3860 | goto out; |
| 3861 | } |
| 3862 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 3863 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 3864 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 3865 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3867 | goto out; |
| 3868 | } |
| 3869 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3870 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 3871 | * where force-persist is applied. |
| 3872 | */ |
| 3873 | 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] | 3874 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3875 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3876 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3877 | if (!strcmp(args[0], "force-persist")) { |
| 3878 | rule->type = PERSIST_TYPE_FORCE; |
| 3879 | } else { |
| 3880 | rule->type = PERSIST_TYPE_IGNORE; |
| 3881 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3882 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 3883 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 3884 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3885 | else if (!strcmp(args[0], "stick-table")) { |
| 3886 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3887 | struct proxy *other; |
| 3888 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 3889 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 3890 | if (other) { |
| 3891 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 3892 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 3893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3894 | goto out; |
| 3895 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3896 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3897 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3898 | curproxy->table.type = (unsigned int)-1; |
| 3899 | while (*args[myidx]) { |
| 3900 | const char *err; |
| 3901 | |
| 3902 | if (strcmp(args[myidx], "size") == 0) { |
| 3903 | myidx++; |
| 3904 | if (!*(args[myidx])) { |
| 3905 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3906 | file, linenum, args[myidx-1]); |
| 3907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3908 | goto out; |
| 3909 | } |
| 3910 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 3911 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3912 | file, linenum, *err, args[myidx-1]); |
| 3913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3914 | goto out; |
| 3915 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3916 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3917 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3918 | else if (strcmp(args[myidx], "peers") == 0) { |
| 3919 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3920 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 3921 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3922 | file, linenum, args[myidx-1]); |
| 3923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3924 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 3925 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 3926 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 3927 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3928 | else if (strcmp(args[myidx], "expire") == 0) { |
| 3929 | myidx++; |
| 3930 | if (!*(args[myidx])) { |
| 3931 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 3932 | file, linenum, args[myidx-1]); |
| 3933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3934 | goto out; |
| 3935 | } |
| 3936 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 3937 | if (err) { |
| 3938 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 3939 | file, linenum, *err, args[myidx-1]); |
| 3940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3941 | goto out; |
| 3942 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 3943 | if (val > INT_MAX) { |
| 3944 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 3945 | file, linenum, val); |
| 3946 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3947 | goto out; |
| 3948 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3949 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3950 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3951 | } |
| 3952 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 3953 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3954 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3955 | } |
| 3956 | else if (strcmp(args[myidx], "type") == 0) { |
| 3957 | myidx++; |
| 3958 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 3959 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 3960 | file, linenum, args[myidx]); |
| 3961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3962 | goto out; |
| 3963 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 3964 | /* myidx already points to next arg */ |
| 3965 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3966 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 3967 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3968 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 3969 | |
| 3970 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3971 | nw = args[myidx]; |
| 3972 | while (*nw) { |
| 3973 | /* the "store" keyword supports a comma-separated list */ |
| 3974 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3975 | sa = NULL; /* store arg */ |
| 3976 | while (*nw && *nw != ',') { |
| 3977 | if (*nw == '(') { |
| 3978 | *nw = 0; |
| 3979 | sa = ++nw; |
| 3980 | while (*nw != ')') { |
| 3981 | if (!*nw) { |
| 3982 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 3983 | file, linenum, args[0], cw); |
| 3984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3985 | goto out; |
| 3986 | } |
| 3987 | nw++; |
| 3988 | } |
| 3989 | *nw = '\0'; |
| 3990 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3991 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 3992 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 3993 | if (*nw) |
| 3994 | *nw++ = '\0'; |
| 3995 | type = stktable_get_data_type(cw); |
| 3996 | if (type < 0) { |
| 3997 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 3998 | file, linenum, args[0], cw); |
| 3999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4000 | goto out; |
| 4001 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4002 | |
| 4003 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4004 | switch (err) { |
| 4005 | case PE_NONE: break; |
| 4006 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4007 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4008 | file, linenum, args[0], cw); |
| 4009 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4010 | break; |
| 4011 | |
| 4012 | case PE_ARG_MISSING: |
| 4013 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4014 | file, linenum, args[0], cw); |
| 4015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4016 | goto out; |
| 4017 | |
| 4018 | case PE_ARG_NOT_USED: |
| 4019 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4020 | file, linenum, args[0], cw); |
| 4021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4022 | goto out; |
| 4023 | |
| 4024 | default: |
| 4025 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4026 | file, linenum, args[0], cw); |
| 4027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4028 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4029 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4030 | } |
| 4031 | myidx++; |
| 4032 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4033 | else { |
| 4034 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4035 | file, linenum, args[myidx]); |
| 4036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4037 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4038 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | if (!curproxy->table.size) { |
| 4042 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4043 | file, linenum); |
| 4044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
| 4048 | if (curproxy->table.type == (unsigned int)-1) { |
| 4049 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4050 | file, linenum); |
| 4051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4052 | goto out; |
| 4053 | } |
| 4054 | } |
| 4055 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4056 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4057 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4058 | int myidx = 0; |
| 4059 | const char *name = NULL; |
| 4060 | int flags; |
| 4061 | |
| 4062 | if (curproxy == &defproxy) { |
| 4063 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4064 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4065 | goto out; |
| 4066 | } |
| 4067 | |
| 4068 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4069 | err_code |= ERR_WARN; |
| 4070 | goto out; |
| 4071 | } |
| 4072 | |
| 4073 | myidx++; |
| 4074 | if ((strcmp(args[myidx], "store") == 0) || |
| 4075 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4076 | myidx++; |
| 4077 | flags = STK_IS_STORE; |
| 4078 | } |
| 4079 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4080 | myidx++; |
| 4081 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4082 | } |
| 4083 | else if (strcmp(args[myidx], "match") == 0) { |
| 4084 | myidx++; |
| 4085 | flags = STK_IS_MATCH; |
| 4086 | } |
| 4087 | else if (strcmp(args[myidx], "on") == 0) { |
| 4088 | myidx++; |
| 4089 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4090 | } |
| 4091 | else { |
| 4092 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4094 | goto out; |
| 4095 | } |
| 4096 | |
| 4097 | if (*(args[myidx]) == 0) { |
| 4098 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4100 | goto out; |
| 4101 | } |
| 4102 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4103 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4104 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4105 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4106 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4108 | goto out; |
| 4109 | } |
| 4110 | |
| 4111 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4112 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4113 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4114 | 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] | 4115 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4116 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4117 | goto out; |
| 4118 | } |
| 4119 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4120 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4121 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4122 | 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] | 4123 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4124 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4125 | goto out; |
| 4126 | } |
| 4127 | } |
| 4128 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4129 | /* 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] | 4130 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4131 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4132 | if (strcmp(args[myidx], "table") == 0) { |
| 4133 | myidx++; |
| 4134 | name = args[myidx++]; |
| 4135 | } |
| 4136 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4137 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4138 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4139 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4140 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4141 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4142 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4143 | goto out; |
| 4144 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4145 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4146 | else if (*(args[myidx])) { |
| 4147 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4148 | file, linenum, args[0], args[myidx]); |
| 4149 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4150 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4151 | goto out; |
| 4152 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4153 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4154 | 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] | 4155 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4156 | 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] | 4157 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4158 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4159 | rule->cond = cond; |
| 4160 | rule->expr = expr; |
| 4161 | rule->flags = flags; |
| 4162 | rule->table.name = name ? strdup(name) : NULL; |
| 4163 | LIST_INIT(&rule->list); |
| 4164 | if (flags & STK_ON_RSP) |
| 4165 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4166 | else |
| 4167 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4168 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4169 | else if (!strcmp(args[0], "stats")) { |
| 4170 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4171 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4172 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4173 | if (!*args[1]) { |
| 4174 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4175 | } else if (!strcmp(args[1], "admin")) { |
| 4176 | struct stats_admin_rule *rule; |
| 4177 | |
| 4178 | if (curproxy == &defproxy) { |
| 4179 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4181 | goto out; |
| 4182 | } |
| 4183 | |
| 4184 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4185 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4186 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4187 | goto out; |
| 4188 | } |
| 4189 | |
| 4190 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4191 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4192 | file, linenum, args[0], args[1]); |
| 4193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4194 | goto out; |
| 4195 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4196 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4197 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4198 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4200 | goto out; |
| 4201 | } |
| 4202 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4203 | err_code |= warnif_cond_conflicts(cond, |
| 4204 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4205 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4206 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4207 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4208 | rule->cond = cond; |
| 4209 | LIST_INIT(&rule->list); |
| 4210 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4211 | } else if (!strcmp(args[1], "uri")) { |
| 4212 | if (*(args[2]) == 0) { |
| 4213 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4215 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4216 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4217 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4218 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4220 | } |
| 4221 | } else if (!strcmp(args[1], "realm")) { |
| 4222 | if (*(args[2]) == 0) { |
| 4223 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4224 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4225 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4226 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4227 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4228 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4229 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4230 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4231 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4232 | unsigned interval; |
| 4233 | |
| 4234 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4235 | if (err) { |
| 4236 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4237 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4239 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4240 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4241 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4242 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4243 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4244 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4245 | } 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] | 4246 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4247 | |
| 4248 | if (curproxy == &defproxy) { |
| 4249 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4250 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4251 | goto out; |
| 4252 | } |
| 4253 | |
| 4254 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4255 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4256 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4257 | goto out; |
| 4258 | } |
| 4259 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4260 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4261 | !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] | 4262 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4263 | file, linenum, args[0]); |
| 4264 | err_code |= ERR_WARN; |
| 4265 | } |
| 4266 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4267 | 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] | 4268 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4269 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4270 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4271 | goto out; |
| 4272 | } |
| 4273 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4274 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4275 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4276 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4277 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4278 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4279 | } else if (!strcmp(args[1], "auth")) { |
| 4280 | if (*(args[2]) == 0) { |
| 4281 | 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] | 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4284 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4285 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4286 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4287 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4288 | } |
| 4289 | } else if (!strcmp(args[1], "scope")) { |
| 4290 | if (*(args[2]) == 0) { |
| 4291 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4293 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4294 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4295 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4296 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4297 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4298 | } |
| 4299 | } else if (!strcmp(args[1], "enable")) { |
| 4300 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4301 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4302 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4304 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4305 | } else if (!strcmp(args[1], "hide-version")) { |
| 4306 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4307 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4308 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4309 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4310 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4311 | } else if (!strcmp(args[1], "show-legends")) { |
| 4312 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4313 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4314 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4315 | goto out; |
| 4316 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4317 | } else if (!strcmp(args[1], "show-node")) { |
| 4318 | |
| 4319 | if (*args[2]) { |
| 4320 | int i; |
| 4321 | char c; |
| 4322 | |
| 4323 | for (i=0; args[2][i]; i++) { |
| 4324 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4325 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4326 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4327 | break; |
| 4328 | } |
| 4329 | |
| 4330 | if (!i || args[2][i]) { |
| 4331 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4332 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4333 | file, linenum, args[0], args[1]); |
| 4334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4335 | goto out; |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4340 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4341 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4342 | goto out; |
| 4343 | } |
| 4344 | } else if (!strcmp(args[1], "show-desc")) { |
| 4345 | char *desc = NULL; |
| 4346 | |
| 4347 | if (*args[2]) { |
| 4348 | int i, len=0; |
| 4349 | char *d; |
| 4350 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4351 | for (i = 2; *args[i]; i++) |
| 4352 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4353 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4354 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4355 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4356 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4357 | for (i = 3; *args[i]; i++) |
| 4358 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | if (!*args[2] && !global.desc) |
| 4362 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4363 | file, linenum, args[1]); |
| 4364 | else { |
| 4365 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4366 | free(desc); |
| 4367 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4368 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4369 | goto out; |
| 4370 | } |
| 4371 | free(desc); |
| 4372 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4373 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4374 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4375 | 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] | 4376 | 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] | 4377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4378 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4379 | } |
| 4380 | } |
| 4381 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4382 | int optnum; |
| 4383 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4384 | if (*(args[1]) == '\0') { |
| 4385 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4386 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4389 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4390 | |
| 4391 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4392 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4393 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4394 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4395 | file, linenum, cfg_opts[optnum].name); |
| 4396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4397 | goto out; |
| 4398 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4399 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4400 | goto out; |
| 4401 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4402 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4403 | err_code |= ERR_WARN; |
| 4404 | goto out; |
| 4405 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4406 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4407 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4408 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4409 | |
| 4410 | switch (kwm) { |
| 4411 | case KWM_STD: |
| 4412 | curproxy->options |= cfg_opts[optnum].val; |
| 4413 | break; |
| 4414 | case KWM_NO: |
| 4415 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4416 | break; |
| 4417 | case KWM_DEF: /* already cleared */ |
| 4418 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4419 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4420 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4421 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4422 | } |
| 4423 | } |
| 4424 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4425 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4426 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4427 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4428 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4429 | file, linenum, cfg_opts2[optnum].name); |
| 4430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4431 | goto out; |
| 4432 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4433 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4434 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4435 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4436 | err_code |= ERR_WARN; |
| 4437 | goto out; |
| 4438 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4439 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4440 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4441 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4442 | |
| 4443 | switch (kwm) { |
| 4444 | case KWM_STD: |
| 4445 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4446 | break; |
| 4447 | case KWM_NO: |
| 4448 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4449 | break; |
| 4450 | case KWM_DEF: /* already cleared */ |
| 4451 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4452 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4453 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4457 | /* HTTP options override each other. They can be cancelled using |
| 4458 | * "no option xxx" which only switches to default mode if the mode |
| 4459 | * was this one (useful for cancelling options set in defaults |
| 4460 | * sections). |
| 4461 | */ |
| 4462 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4463 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4464 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4465 | if (kwm == KWM_STD) { |
| 4466 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4467 | curproxy->options |= PR_O_HTTP_PCL; |
| 4468 | goto out; |
| 4469 | } |
| 4470 | else if (kwm == KWM_NO) { |
| 4471 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4472 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4473 | goto out; |
| 4474 | } |
| 4475 | } |
| 4476 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4477 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4478 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4479 | if (kwm == KWM_STD) { |
| 4480 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4481 | curproxy->options |= PR_O_HTTP_FCL; |
| 4482 | goto out; |
| 4483 | } |
| 4484 | else if (kwm == KWM_NO) { |
| 4485 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4486 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4487 | goto out; |
| 4488 | } |
| 4489 | } |
| 4490 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4491 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4492 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4493 | if (kwm == KWM_STD) { |
| 4494 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4495 | curproxy->options |= PR_O_HTTP_SCL; |
| 4496 | goto out; |
| 4497 | } |
| 4498 | else if (kwm == KWM_NO) { |
| 4499 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4500 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4501 | goto out; |
| 4502 | } |
| 4503 | } |
| 4504 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4505 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4506 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4507 | if (kwm == KWM_STD) { |
| 4508 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4509 | curproxy->options |= PR_O_HTTP_KAL; |
| 4510 | goto out; |
| 4511 | } |
| 4512 | else if (kwm == KWM_NO) { |
| 4513 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4514 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4515 | goto out; |
| 4516 | } |
| 4517 | } |
| 4518 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4519 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4520 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4521 | if (kwm == KWM_STD) { |
| 4522 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4523 | curproxy->options |= PR_O_HTTP_TUN; |
| 4524 | goto out; |
| 4525 | } |
| 4526 | else if (kwm == KWM_NO) { |
| 4527 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4528 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4529 | goto out; |
| 4530 | } |
| 4531 | } |
| 4532 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4533 | /* Redispatch can take an integer argument that control when the |
| 4534 | * resispatch occurs. All values are relative to the retries option. |
| 4535 | * This can be cancelled using "no option xxx". |
| 4536 | */ |
| 4537 | if (strcmp(args[1], "redispatch") == 0) { |
| 4538 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4539 | err_code |= ERR_WARN; |
| 4540 | goto out; |
| 4541 | } |
| 4542 | |
| 4543 | curproxy->no_options &= ~PR_O_REDISP; |
| 4544 | curproxy->options &= ~PR_O_REDISP; |
| 4545 | |
| 4546 | switch (kwm) { |
| 4547 | case KWM_STD: |
| 4548 | curproxy->options |= PR_O_REDISP; |
| 4549 | curproxy->redispatch_after = -1; |
| 4550 | if(*args[2]) { |
| 4551 | curproxy->redispatch_after = atol(args[2]); |
| 4552 | } |
| 4553 | break; |
| 4554 | case KWM_NO: |
| 4555 | curproxy->no_options |= PR_O_REDISP; |
| 4556 | curproxy->redispatch_after = 0; |
| 4557 | break; |
| 4558 | case KWM_DEF: /* already cleared */ |
| 4559 | break; |
| 4560 | } |
| 4561 | goto out; |
| 4562 | } |
| 4563 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4564 | if (kwm != KWM_STD) { |
| 4565 | 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] | 4566 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4568 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4569 | } |
| 4570 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4571 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4572 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4573 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4574 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4575 | if (*(args[2]) != '\0') { |
| 4576 | if (!strcmp(args[2], "clf")) { |
| 4577 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4578 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4579 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4580 | 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] | 4581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4582 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4583 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4584 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4585 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4586 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4587 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4588 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4589 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4590 | free(curproxy->conf.logformat_string); |
| 4591 | curproxy->conf.logformat_string = logformat; |
| 4592 | |
| 4593 | free(curproxy->conf.lfs_file); |
| 4594 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4595 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4596 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4597 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4598 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4599 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4600 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4601 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4602 | free(curproxy->conf.logformat_string); |
| 4603 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4604 | |
| 4605 | free(curproxy->conf.lfs_file); |
| 4606 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4607 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4608 | |
| 4609 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4610 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4611 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4612 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4613 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4614 | 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] | 4615 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4616 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4617 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4618 | goto out; |
| 4619 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4620 | if (curproxy->cap & PR_CAP_FE) |
| 4621 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4622 | if (curproxy->cap & PR_CAP_BE) |
| 4623 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4624 | } |
| 4625 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4626 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4627 | err_code |= ERR_WARN; |
| 4628 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4629 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4630 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4631 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4632 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4633 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4634 | if (!*args[2]) { /* no argument */ |
| 4635 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4636 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4637 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4638 | 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] | 4639 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4640 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4641 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4642 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4643 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4644 | if (*args[4]) |
| 4645 | reqlen += strlen(args[4]); |
| 4646 | else |
| 4647 | reqlen += strlen("HTTP/1.0"); |
| 4648 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4649 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4650 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4651 | "%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] | 4652 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4653 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4654 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4655 | } |
| 4656 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4657 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4658 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4659 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4660 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4661 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4662 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4663 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4664 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4665 | |
| 4666 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4667 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4668 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4669 | else if (!strcmp(args[1], "smtpchk")) { |
| 4670 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4671 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4672 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4673 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4674 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4675 | |
| 4676 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4677 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4678 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4679 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4680 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4681 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4682 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4683 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4684 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4685 | } else { |
| 4686 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4687 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4688 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4689 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4690 | } |
| 4691 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4692 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4693 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4694 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4695 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4696 | /* use PostgreSQL request to check servers' health */ |
| 4697 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4698 | err_code |= ERR_WARN; |
| 4699 | |
| 4700 | free(curproxy->check_req); |
| 4701 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4702 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4703 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4704 | |
| 4705 | if (*(args[2])) { |
| 4706 | int cur_arg = 2; |
| 4707 | |
| 4708 | while (*(args[cur_arg])) { |
| 4709 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4710 | char * packet; |
| 4711 | uint32_t packet_len; |
| 4712 | uint32_t pv; |
| 4713 | |
| 4714 | /* suboption header - needs additional argument for it */ |
| 4715 | if (*(args[cur_arg+1]) == 0) { |
| 4716 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4717 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4719 | goto out; |
| 4720 | } |
| 4721 | |
| 4722 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4723 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4724 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4725 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4726 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4727 | |
| 4728 | memcpy(packet + 4, &pv, 4); |
| 4729 | |
| 4730 | /* copy "user" */ |
| 4731 | memcpy(packet + 8, "user", 4); |
| 4732 | |
| 4733 | /* copy username */ |
| 4734 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4735 | |
| 4736 | free(curproxy->check_req); |
| 4737 | curproxy->check_req = packet; |
| 4738 | curproxy->check_len = packet_len; |
| 4739 | |
| 4740 | packet_len = htonl(packet_len); |
| 4741 | memcpy(packet, &packet_len, 4); |
| 4742 | cur_arg += 2; |
| 4743 | } else { |
| 4744 | /* unknown suboption - catchall */ |
| 4745 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4746 | file, linenum, args[0], args[1]); |
| 4747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4748 | goto out; |
| 4749 | } |
| 4750 | } /* end while loop */ |
| 4751 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4752 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4753 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4756 | else if (!strcmp(args[1], "redis-check")) { |
| 4757 | /* use REDIS PING request to check servers' health */ |
| 4758 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4759 | err_code |= ERR_WARN; |
| 4760 | |
| 4761 | free(curproxy->check_req); |
| 4762 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4763 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4764 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4765 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4766 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4767 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4768 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4769 | |
| 4770 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4771 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4772 | } |
| 4773 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4774 | else if (!strcmp(args[1], "mysql-check")) { |
| 4775 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4776 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4777 | err_code |= ERR_WARN; |
| 4778 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4779 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4780 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4781 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4782 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4783 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4784 | /* 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] | 4785 | * const char mysql40_client_auth_pkt[] = { |
| 4786 | * "\x0e\x00\x00" // packet length |
| 4787 | * "\x01" // packet number |
| 4788 | * "\x00\x00" // client capabilities |
| 4789 | * "\x00\x00\x01" // max packet |
| 4790 | * "haproxy\x00" // username (null terminated string) |
| 4791 | * "\x00" // filler (always 0x00) |
| 4792 | * "\x01\x00\x00" // packet length |
| 4793 | * "\x00" // packet number |
| 4794 | * "\x01" // COM_QUIT command |
| 4795 | * }; |
| 4796 | */ |
| 4797 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4798 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 4799 | * const char mysql41_client_auth_pkt[] = { |
| 4800 | * "\x0e\x00\x00\" // packet length |
| 4801 | * "\x01" // packet number |
| 4802 | * "\x00\x00\x00\x00" // client capabilities |
| 4803 | * "\x00\x00\x00\x01" // max packet |
| 4804 | * "\x21" // character set (UTF-8) |
| 4805 | * char[23] // All zeroes |
| 4806 | * "haproxy\x00" // username (null terminated string) |
| 4807 | * "\x00" // filler (always 0x00) |
| 4808 | * "\x01\x00\x00" // packet length |
| 4809 | * "\x00" // packet number |
| 4810 | * "\x01" // COM_QUIT command |
| 4811 | * }; |
| 4812 | */ |
| 4813 | |
| 4814 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4815 | if (*(args[2])) { |
| 4816 | int cur_arg = 2; |
| 4817 | |
| 4818 | while (*(args[cur_arg])) { |
| 4819 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4820 | char *mysqluser; |
| 4821 | int packetlen, reqlen, userlen; |
| 4822 | |
| 4823 | /* suboption header - needs additional argument for it */ |
| 4824 | if (*(args[cur_arg+1]) == 0) { |
| 4825 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4826 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4828 | goto out; |
| 4829 | } |
| 4830 | mysqluser = args[cur_arg + 1]; |
| 4831 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4832 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4833 | if (*(args[cur_arg+2])) { |
| 4834 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 4835 | packetlen = userlen + 7 + 27; |
| 4836 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4837 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4838 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4839 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4840 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4841 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4842 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4843 | ((unsigned char) packetlen & 0xff), |
| 4844 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4845 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4846 | |
| 4847 | curproxy->check_req[3] = 1; |
| 4848 | curproxy->check_req[5] = 130; |
| 4849 | curproxy->check_req[11] = 1; |
| 4850 | curproxy->check_req[12] = 33; |
| 4851 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 4852 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 4853 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 4854 | cur_arg += 3; |
| 4855 | } else { |
| 4856 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 4857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4858 | goto out; |
| 4859 | } |
| 4860 | } else { |
| 4861 | packetlen = userlen + 7; |
| 4862 | reqlen = packetlen + 9; |
| 4863 | |
| 4864 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4865 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 4866 | curproxy->check_len = reqlen; |
| 4867 | |
| 4868 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 4869 | ((unsigned char) packetlen & 0xff), |
| 4870 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 4871 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 4872 | |
| 4873 | curproxy->check_req[3] = 1; |
| 4874 | curproxy->check_req[5] = 128; |
| 4875 | curproxy->check_req[8] = 1; |
| 4876 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 4877 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 4878 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 4879 | cur_arg += 2; |
| 4880 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4881 | } else { |
| 4882 | /* unknown suboption - catchall */ |
| 4883 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4884 | file, linenum, args[0], args[1]); |
| 4885 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4886 | goto out; |
| 4887 | } |
| 4888 | } /* end while loop */ |
| 4889 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4890 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4891 | else if (!strcmp(args[1], "ldap-check")) { |
| 4892 | /* use LDAP request to check servers' health */ |
| 4893 | free(curproxy->check_req); |
| 4894 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4895 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4896 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 4897 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4898 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4899 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 4900 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4901 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4902 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 4903 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 4904 | else if (!strcmp(args[1], "spop-check")) { |
| 4905 | if (curproxy == &defproxy) { |
| 4906 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 4907 | file, linenum, args[0], args[1]); |
| 4908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4909 | goto out; |
| 4910 | } |
| 4911 | if (curproxy->cap & PR_CAP_FE) { |
| 4912 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 4913 | file, linenum, args[0], args[1]); |
| 4914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4915 | goto out; |
| 4916 | } |
| 4917 | |
| 4918 | /* use SPOE request to check servers' health */ |
| 4919 | free(curproxy->check_req); |
| 4920 | curproxy->check_req = NULL; |
| 4921 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4922 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 4923 | |
| 4924 | if (prepare_spoe_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
| 4925 | Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
| 4926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4927 | goto out; |
| 4928 | } |
| 4929 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4930 | goto out; |
| 4931 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4932 | else if (!strcmp(args[1], "tcp-check")) { |
| 4933 | /* use raw TCPCHK send/expect to check servers' health */ |
| 4934 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4935 | err_code |= ERR_WARN; |
| 4936 | |
| 4937 | free(curproxy->check_req); |
| 4938 | curproxy->check_req = NULL; |
| 4939 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4940 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4941 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4942 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 4943 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4944 | else if (!strcmp(args[1], "external-check")) { |
| 4945 | /* excute an external command to check servers' health */ |
| 4946 | free(curproxy->check_req); |
| 4947 | curproxy->check_req = NULL; |
| 4948 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4949 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4950 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4951 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 4952 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4953 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4954 | int cur_arg; |
| 4955 | |
| 4956 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 4957 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4958 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4959 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4960 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4961 | |
| 4962 | free(curproxy->fwdfor_hdr_name); |
| 4963 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 4964 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 4965 | |
| 4966 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 4967 | cur_arg = 2; |
| 4968 | while (*(args[cur_arg])) { |
| 4969 | if (!strcmp(args[cur_arg], "except")) { |
| 4970 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 4971 | 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] | 4972 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 4973 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4975 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4976 | } |
| 4977 | /* flush useless bits */ |
| 4978 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4979 | cur_arg += 2; |
| 4980 | } else if (!strcmp(args[cur_arg], "header")) { |
| 4981 | /* suboption header - needs additional argument for it */ |
| 4982 | if (*(args[cur_arg+1]) == 0) { |
| 4983 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 4984 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4986 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4987 | } |
| 4988 | free(curproxy->fwdfor_hdr_name); |
| 4989 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 4990 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 4991 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4992 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 4993 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 4994 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 4995 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 4996 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 4997 | 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] | 4998 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5000 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5001 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5002 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5003 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5004 | else if (!strcmp(args[1], "originalto")) { |
| 5005 | int cur_arg; |
| 5006 | |
| 5007 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5008 | * set default options (ie: bitfield, header name, etc) |
| 5009 | */ |
| 5010 | |
| 5011 | curproxy->options |= PR_O_ORGTO; |
| 5012 | |
| 5013 | free(curproxy->orgto_hdr_name); |
| 5014 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5015 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5016 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5017 | /* 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] | 5018 | cur_arg = 2; |
| 5019 | while (*(args[cur_arg])) { |
| 5020 | if (!strcmp(args[cur_arg], "except")) { |
| 5021 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5022 | 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] | 5023 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5024 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5026 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5027 | } |
| 5028 | /* flush useless bits */ |
| 5029 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5030 | cur_arg += 2; |
| 5031 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5032 | /* suboption header - needs additional argument for it */ |
| 5033 | if (*(args[cur_arg+1]) == 0) { |
| 5034 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5035 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5037 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5038 | } |
| 5039 | free(curproxy->orgto_hdr_name); |
| 5040 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5041 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5042 | cur_arg += 2; |
| 5043 | } else { |
| 5044 | /* unknown suboption - catchall */ |
| 5045 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5046 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5048 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5049 | } |
| 5050 | } /* end while loop */ |
| 5051 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5052 | else { |
| 5053 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5055 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5056 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5057 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5058 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5059 | else if (!strcmp(args[0], "default_backend")) { |
| 5060 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5061 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5062 | |
| 5063 | if (*(args[1]) == 0) { |
| 5064 | 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] | 5065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5066 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5067 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5068 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5069 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5070 | |
| 5071 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5072 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5073 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5074 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5075 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5076 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5077 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5078 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5079 | 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] | 5080 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5081 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5082 | /* enable reconnections to dispatch */ |
| 5083 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5084 | |
| 5085 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5086 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5087 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5088 | else if (!strcmp(args[0], "http-reuse")) { |
| 5089 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5090 | err_code |= ERR_WARN; |
| 5091 | |
| 5092 | if (strcmp(args[1], "never") == 0) { |
| 5093 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5094 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5095 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5096 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5097 | goto out; |
| 5098 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5099 | else if (strcmp(args[1], "safe") == 0) { |
| 5100 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5101 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5102 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5103 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5104 | goto out; |
| 5105 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5106 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5107 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5108 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5109 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5110 | goto out; |
| 5111 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5112 | else if (strcmp(args[1], "always") == 0) { |
| 5113 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5114 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5115 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5116 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5117 | goto out; |
| 5118 | } |
| 5119 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5120 | 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] | 5121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5122 | goto out; |
| 5123 | } |
| 5124 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5125 | else if (!strcmp(args[0], "http-check")) { |
| 5126 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5127 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5128 | |
| 5129 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5130 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5131 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5132 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5133 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5134 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5135 | else if (strcmp(args[1], "send-state") == 0) { |
| 5136 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5137 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5138 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5139 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5140 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5141 | else if (strcmp(args[1], "expect") == 0) { |
| 5142 | const char *ptr_arg; |
| 5143 | int cur_arg; |
| 5144 | |
| 5145 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5146 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5147 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5148 | goto out; |
| 5149 | } |
| 5150 | |
| 5151 | cur_arg = 2; |
| 5152 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5153 | while (*(ptr_arg = args[cur_arg])) { |
| 5154 | while (*ptr_arg == '!') { |
| 5155 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5156 | ptr_arg++; |
| 5157 | } |
| 5158 | if (*ptr_arg) |
| 5159 | break; |
| 5160 | cur_arg++; |
| 5161 | } |
| 5162 | /* now ptr_arg points to the beginning of a word past any possible |
| 5163 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5164 | */ |
| 5165 | if (strcmp(ptr_arg, "status") == 0) { |
| 5166 | if (!*(args[cur_arg + 1])) { |
| 5167 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5168 | file, linenum, args[0], args[1], ptr_arg); |
| 5169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5170 | goto out; |
| 5171 | } |
| 5172 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5173 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5174 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5175 | } |
| 5176 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5177 | if (!*(args[cur_arg + 1])) { |
| 5178 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5179 | file, linenum, args[0], args[1], ptr_arg); |
| 5180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5181 | goto out; |
| 5182 | } |
| 5183 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5184 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5185 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5186 | } |
| 5187 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5188 | if (!*(args[cur_arg + 1])) { |
| 5189 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5190 | file, linenum, args[0], args[1], ptr_arg); |
| 5191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5192 | goto out; |
| 5193 | } |
| 5194 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5195 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5196 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5197 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5198 | free(curproxy->expect_regex); |
| 5199 | curproxy->expect_regex = NULL; |
| 5200 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5201 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5202 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5203 | error = NULL; |
| 5204 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5205 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5206 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5207 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5209 | goto out; |
| 5210 | } |
| 5211 | } |
| 5212 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5213 | if (!*(args[cur_arg + 1])) { |
| 5214 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5215 | file, linenum, args[0], args[1], ptr_arg); |
| 5216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5217 | goto out; |
| 5218 | } |
| 5219 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5220 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5221 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5222 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5223 | free(curproxy->expect_regex); |
| 5224 | curproxy->expect_regex = NULL; |
| 5225 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5226 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5227 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5228 | error = NULL; |
| 5229 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5230 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5231 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5232 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5234 | goto out; |
| 5235 | } |
| 5236 | } |
| 5237 | else { |
| 5238 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5239 | file, linenum, args[0], args[1], ptr_arg); |
| 5240 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5241 | goto out; |
| 5242 | } |
| 5243 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5244 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5245 | 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] | 5246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5247 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5248 | } |
| 5249 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5250 | else if (!strcmp(args[0], "tcp-check")) { |
| 5251 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5252 | err_code |= ERR_WARN; |
| 5253 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5254 | if (strcmp(args[1], "comment") == 0) { |
| 5255 | int cur_arg; |
| 5256 | struct tcpcheck_rule *tcpcheck; |
| 5257 | |
| 5258 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5259 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5260 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5261 | |
| 5262 | if (!*args[cur_arg + 1]) { |
| 5263 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5264 | file, linenum, args[cur_arg]); |
| 5265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5266 | goto out; |
| 5267 | } |
| 5268 | |
| 5269 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5270 | |
| 5271 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5272 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5273 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5274 | } |
| 5275 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5276 | const char *ptr_arg; |
| 5277 | int cur_arg; |
| 5278 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5279 | |
| 5280 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5281 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5282 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5283 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5284 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5285 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5286 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5287 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5288 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5289 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5290 | file, linenum); |
| 5291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5292 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5296 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5297 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5298 | |
| 5299 | /* parsing each parameters to fill up the rule */ |
| 5300 | while (*(ptr_arg = args[cur_arg])) { |
| 5301 | /* tcp port */ |
| 5302 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5303 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5304 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5305 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5306 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5308 | goto out; |
| 5309 | } |
| 5310 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5311 | cur_arg += 2; |
| 5312 | } |
| 5313 | /* send proxy protocol */ |
| 5314 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5315 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5316 | cur_arg++; |
| 5317 | } |
| 5318 | #ifdef USE_OPENSSL |
| 5319 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5320 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5321 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5322 | cur_arg++; |
| 5323 | } |
| 5324 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5325 | /* comment for this tcpcheck line */ |
| 5326 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5327 | if (!*args[cur_arg + 1]) { |
| 5328 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5329 | file, linenum, args[cur_arg]); |
| 5330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5331 | goto out; |
| 5332 | } |
| 5333 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5334 | cur_arg += 2; |
| 5335 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5336 | else { |
| 5337 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5338 | 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] | 5339 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5340 | 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] | 5341 | #endif /* USE_OPENSSL */ |
| 5342 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5344 | goto out; |
| 5345 | } |
| 5346 | |
| 5347 | } |
| 5348 | |
| 5349 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5350 | } |
| 5351 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5352 | if (! *(args[2]) ) { |
| 5353 | /* SEND string expected */ |
| 5354 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5355 | file, linenum, args[0], args[1], args[2]); |
| 5356 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5357 | goto out; |
| 5358 | } else { |
| 5359 | struct tcpcheck_rule *tcpcheck; |
| 5360 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5361 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5362 | |
| 5363 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5364 | tcpcheck->string_len = strlen(args[2]); |
| 5365 | tcpcheck->string = strdup(args[2]); |
| 5366 | tcpcheck->expect_regex = NULL; |
| 5367 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5368 | /* comment for this tcpcheck line */ |
| 5369 | if (strcmp(args[3], "comment") == 0) { |
| 5370 | if (!*args[4]) { |
| 5371 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5372 | file, linenum, args[3]); |
| 5373 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5374 | goto out; |
| 5375 | } |
| 5376 | tcpcheck->comment = strdup(args[4]); |
| 5377 | } |
| 5378 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5379 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5380 | } |
| 5381 | } |
| 5382 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5383 | if (! *(args[2]) ) { |
| 5384 | /* SEND binary string expected */ |
| 5385 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5386 | file, linenum, args[0], args[1], args[2]); |
| 5387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5388 | goto out; |
| 5389 | } else { |
| 5390 | struct tcpcheck_rule *tcpcheck; |
| 5391 | char *err = NULL; |
| 5392 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5393 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5394 | |
| 5395 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5396 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5397 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5398 | file, linenum, args[0], args[1], args[2], err); |
| 5399 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5400 | goto out; |
| 5401 | } |
| 5402 | tcpcheck->expect_regex = NULL; |
| 5403 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5404 | /* comment for this tcpcheck line */ |
| 5405 | if (strcmp(args[3], "comment") == 0) { |
| 5406 | if (!*args[4]) { |
| 5407 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5408 | file, linenum, args[3]); |
| 5409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5410 | goto out; |
| 5411 | } |
| 5412 | tcpcheck->comment = strdup(args[4]); |
| 5413 | } |
| 5414 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5415 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5416 | } |
| 5417 | } |
| 5418 | else if (strcmp(args[1], "expect") == 0) { |
| 5419 | const char *ptr_arg; |
| 5420 | int cur_arg; |
| 5421 | int inverse = 0; |
| 5422 | |
| 5423 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5424 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5426 | goto out; |
| 5427 | } |
| 5428 | |
| 5429 | cur_arg = 2; |
| 5430 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5431 | while (*(ptr_arg = args[cur_arg])) { |
| 5432 | while (*ptr_arg == '!') { |
| 5433 | inverse = !inverse; |
| 5434 | ptr_arg++; |
| 5435 | } |
| 5436 | if (*ptr_arg) |
| 5437 | break; |
| 5438 | cur_arg++; |
| 5439 | } |
| 5440 | /* now ptr_arg points to the beginning of a word past any possible |
| 5441 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5442 | */ |
| 5443 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5444 | struct tcpcheck_rule *tcpcheck; |
| 5445 | char *err = NULL; |
| 5446 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5447 | if (!*(args[cur_arg + 1])) { |
| 5448 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5449 | file, linenum, args[0], args[1], ptr_arg); |
| 5450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5451 | goto out; |
| 5452 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5453 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5454 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5455 | |
| 5456 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5457 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5458 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5459 | file, linenum, args[0], args[1], args[2], err); |
| 5460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5461 | goto out; |
| 5462 | } |
| 5463 | tcpcheck->expect_regex = NULL; |
| 5464 | tcpcheck->inverse = inverse; |
| 5465 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5466 | /* tcpcheck comment */ |
| 5467 | cur_arg += 2; |
| 5468 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5469 | if (!*args[cur_arg + 1]) { |
| 5470 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5471 | file, linenum, args[cur_arg + 1]); |
| 5472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5473 | goto out; |
| 5474 | } |
| 5475 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5476 | } |
| 5477 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5478 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5479 | } |
| 5480 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5481 | struct tcpcheck_rule *tcpcheck; |
| 5482 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5483 | if (!*(args[cur_arg + 1])) { |
| 5484 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5485 | file, linenum, args[0], args[1], ptr_arg); |
| 5486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5487 | goto out; |
| 5488 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5489 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5490 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5491 | |
| 5492 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5493 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5494 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5495 | tcpcheck->expect_regex = NULL; |
| 5496 | tcpcheck->inverse = inverse; |
| 5497 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5498 | /* tcpcheck comment */ |
| 5499 | cur_arg += 2; |
| 5500 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5501 | if (!*args[cur_arg + 1]) { |
| 5502 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5503 | file, linenum, args[cur_arg + 1]); |
| 5504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5505 | goto out; |
| 5506 | } |
| 5507 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5508 | } |
| 5509 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5510 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5511 | } |
| 5512 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5513 | struct tcpcheck_rule *tcpcheck; |
| 5514 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5515 | if (!*(args[cur_arg + 1])) { |
| 5516 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5517 | file, linenum, args[0], args[1], ptr_arg); |
| 5518 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5519 | goto out; |
| 5520 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5521 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5522 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5523 | |
| 5524 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5525 | tcpcheck->string_len = 0; |
| 5526 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5527 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5528 | error = NULL; |
| 5529 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5530 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5531 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5532 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5534 | goto out; |
| 5535 | } |
| 5536 | tcpcheck->inverse = inverse; |
| 5537 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5538 | /* tcpcheck comment */ |
| 5539 | cur_arg += 2; |
| 5540 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5541 | if (!*args[cur_arg + 1]) { |
| 5542 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5543 | file, linenum, args[cur_arg + 1]); |
| 5544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5545 | goto out; |
| 5546 | } |
| 5547 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5548 | } |
| 5549 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5550 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5551 | } |
| 5552 | else { |
| 5553 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5554 | file, linenum, args[0], args[1], ptr_arg); |
| 5555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5556 | goto out; |
| 5557 | } |
| 5558 | } |
| 5559 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5560 | 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] | 5561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5562 | goto out; |
| 5563 | } |
| 5564 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5565 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5566 | if (curproxy == &defproxy) { |
| 5567 | 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] | 5568 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5569 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5570 | } |
| 5571 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5572 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5573 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5574 | |
| 5575 | if (strcmp(args[1], "fail") == 0) { |
| 5576 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5577 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5578 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5579 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5581 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5582 | } |
| 5583 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5584 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5585 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5586 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5588 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5589 | } |
| 5590 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5591 | } |
| 5592 | else { |
| 5593 | 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] | 5594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5595 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5596 | } |
| 5597 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5598 | #ifdef TPROXY |
| 5599 | else if (!strcmp(args[0], "transparent")) { |
| 5600 | /* enable transparent proxy connections */ |
| 5601 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5602 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5603 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5604 | } |
| 5605 | #endif |
| 5606 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5607 | 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] | 5608 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5609 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5610 | if (*(args[1]) == 0) { |
| 5611 | 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] | 5612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5613 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5614 | } |
| 5615 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5616 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5617 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5618 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5619 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5620 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5621 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5622 | |
| 5623 | if (*(args[1]) == 0) { |
| 5624 | 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] | 5625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5626 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5627 | } |
| 5628 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5629 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5630 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5631 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5632 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5633 | 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] | 5634 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5635 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5636 | if (*(args[1]) == 0) { |
| 5637 | 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] | 5638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5639 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5640 | } |
| 5641 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5642 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5643 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5644 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5645 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5646 | if (*(args[1]) == 0) { |
| 5647 | 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] | 5648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5649 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5650 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5651 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5652 | if (err) { |
| 5653 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5654 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5656 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5657 | } |
| 5658 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5659 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5660 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5661 | } |
| 5662 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5663 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5664 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5665 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5666 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5667 | if (curproxy == &defproxy) { |
| 5668 | 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] | 5669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5670 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5671 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5672 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5673 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5674 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5675 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5676 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5677 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5678 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5679 | goto out; |
| 5680 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5681 | |
| 5682 | proto = protocol_by_family(sk->ss_family); |
| 5683 | if (!proto || !proto->connect) { |
| 5684 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5685 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5687 | goto out; |
| 5688 | } |
| 5689 | |
| 5690 | if (port1 != port2) { |
| 5691 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5692 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5694 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5695 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5696 | |
| 5697 | if (!port1) { |
| 5698 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5699 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5701 | goto out; |
| 5702 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5703 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5704 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5705 | goto out; |
| 5706 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5707 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5708 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5709 | } |
| 5710 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5711 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5712 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5713 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5714 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5715 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5717 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5718 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5719 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5720 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5721 | /** |
| 5722 | * The syntax for hash-type config element is |
| 5723 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5724 | * |
| 5725 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5726 | */ |
| 5727 | 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] | 5728 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5729 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5730 | err_code |= ERR_WARN; |
| 5731 | |
| 5732 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5733 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5734 | } |
| 5735 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5736 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5737 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5738 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5739 | 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]); |
| 5740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5741 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5742 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5743 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5744 | 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] | 5745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5746 | goto out; |
| 5747 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5748 | |
| 5749 | /* set the hash function to use */ |
| 5750 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5751 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5752 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5753 | |
| 5754 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5755 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5756 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5757 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5758 | /* set the hash function */ |
| 5759 | if (!strcmp(args[2], "sdbm")) { |
| 5760 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5761 | } |
| 5762 | else if (!strcmp(args[2], "djb2")) { |
| 5763 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5764 | } |
| 5765 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5766 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5767 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5768 | else if (!strcmp(args[2], "crc32")) { |
| 5769 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5770 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5771 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5772 | 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] | 5773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5774 | goto out; |
| 5775 | } |
| 5776 | |
| 5777 | /* set the hash modifier */ |
| 5778 | if (!strcmp(args[3], "avalanche")) { |
| 5779 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5780 | } |
| 5781 | else if (*args[3]) { |
| 5782 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 5783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5784 | goto out; |
| 5785 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 5786 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5787 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 5788 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 5789 | if (*(args[1]) == 0) { |
| 5790 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 5791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5792 | goto out; |
| 5793 | } |
| 5794 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 5795 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 5796 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 5797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5798 | goto out; |
| 5799 | } |
| 5800 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5801 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 5802 | if (!*(args[1])) { |
| 5803 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5805 | goto out; |
| 5806 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5807 | if (*(args[2])) { |
| 5808 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5810 | goto out; |
| 5811 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5812 | free(curproxy->conf.uniqueid_format_string); |
| 5813 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5814 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5815 | free(curproxy->conf.uif_file); |
| 5816 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 5817 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5818 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 5819 | |
| 5820 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 5821 | if (!*(args[1])) { |
| 5822 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5824 | goto out; |
| 5825 | } |
| 5826 | free(curproxy->header_unique_id); |
| 5827 | curproxy->header_unique_id = strdup(args[1]); |
| 5828 | } |
| 5829 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5830 | else if (strcmp(args[0], "log-format") == 0) { |
| 5831 | if (!*(args[1])) { |
| 5832 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5834 | goto out; |
| 5835 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 5836 | if (*(args[2])) { |
| 5837 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5839 | goto out; |
| 5840 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 5841 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 5842 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 5843 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 5844 | curproxy->conf.logformat_string != clf_http_log_format) |
| 5845 | free(curproxy->conf.logformat_string); |
| 5846 | curproxy->conf.logformat_string = strdup(args[1]); |
| 5847 | |
| 5848 | free(curproxy->conf.lfs_file); |
| 5849 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 5850 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 5851 | |
| 5852 | /* get a chance to improve log-format error reporting by |
| 5853 | * reporting the correct line-number when possible. |
| 5854 | */ |
| 5855 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5856 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 5857 | file, linenum, curproxy->id); |
| 5858 | err_code |= ERR_WARN; |
| 5859 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5860 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 5861 | else if (!strcmp(args[0], "log-format-sd")) { |
| 5862 | if (!*(args[1])) { |
| 5863 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 5864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5865 | goto out; |
| 5866 | } |
| 5867 | if (*(args[2])) { |
| 5868 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 5869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5870 | goto out; |
| 5871 | } |
| 5872 | |
| 5873 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 5874 | free(curproxy->conf.logformat_sd_string); |
| 5875 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 5876 | |
| 5877 | free(curproxy->conf.lfsd_file); |
| 5878 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 5879 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 5880 | |
| 5881 | /* get a chance to improve log-format-sd error reporting by |
| 5882 | * reporting the correct line-number when possible. |
| 5883 | */ |
| 5884 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 5885 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 5886 | file, linenum, curproxy->id); |
| 5887 | err_code |= ERR_WARN; |
| 5888 | } |
| 5889 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 5890 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 5891 | if (*(args[1]) == 0) { |
| 5892 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 5893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5894 | goto out; |
| 5895 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 5896 | chunk_destroy(&curproxy->log_tag); |
| 5897 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 5898 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5899 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 5900 | /* delete previous herited or defined syslog servers */ |
| 5901 | struct logsrv *back; |
| 5902 | |
| 5903 | if (*(args[1]) != 0) { |
| 5904 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 5905 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5906 | goto out; |
| 5907 | } |
| 5908 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5909 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 5910 | LIST_DEL(&tmplogsrv->list); |
| 5911 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5912 | } |
| 5913 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5914 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5915 | struct logsrv *logsrv; |
| 5916 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5917 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5918 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5919 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 5920 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 5921 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5922 | LIST_INIT(&node->list); |
| 5923 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 5924 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5925 | } |
| 5926 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 5927 | struct sockaddr_storage *sk; |
| 5928 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5929 | int arg = 0; |
| 5930 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5931 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 5932 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5933 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5934 | /* just after the address, a length may be specified */ |
| 5935 | if (strcmp(args[arg+2], "len") == 0) { |
| 5936 | len = atoi(args[arg+3]); |
| 5937 | if (len < 80 || len > 65535) { |
| 5938 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 5939 | file, linenum, args[arg+3]); |
| 5940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5941 | goto out; |
| 5942 | } |
| 5943 | logsrv->maxlen = len; |
| 5944 | |
| 5945 | /* skip these two args */ |
| 5946 | arg += 2; |
| 5947 | } |
| 5948 | else |
| 5949 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 5950 | |
| 5951 | if (logsrv->maxlen > global.max_syslog_len) { |
| 5952 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 5953 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 5954 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 5955 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 5956 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5957 | } |
| 5958 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 5959 | /* after the length, a format may be specified */ |
| 5960 | if (strcmp(args[arg+2], "format") == 0) { |
| 5961 | logsrv->format = get_log_format(args[arg+3]); |
| 5962 | if (logsrv->format < 0) { |
| 5963 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 5964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5965 | goto out; |
| 5966 | } |
| 5967 | |
| 5968 | /* skip these two args */ |
| 5969 | arg += 2; |
| 5970 | } |
| 5971 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5972 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 5973 | goto out; |
| 5974 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5975 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5976 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5977 | 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] | 5978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5979 | goto out; |
| 5980 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5981 | } |
| 5982 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5983 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5984 | if (*(args[arg+3])) { |
| 5985 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5986 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5987 | 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] | 5988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5989 | goto out; |
| 5990 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5991 | } |
| 5992 | } |
| 5993 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 5994 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5995 | if (*(args[arg+4])) { |
| 5996 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 5997 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 5998 | 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] | 5999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6000 | goto out; |
| 6001 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6002 | } |
| 6003 | } |
| 6004 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6005 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6006 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6007 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6008 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6009 | goto out; |
| 6010 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6011 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6012 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6013 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6014 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6015 | if (port1 != port2) { |
| 6016 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6017 | file, linenum, args[0], args[1]); |
| 6018 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6019 | goto out; |
| 6020 | } |
| 6021 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6022 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6023 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6024 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6025 | |
| 6026 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6027 | } |
| 6028 | else { |
| 6029 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6030 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6032 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6033 | } |
| 6034 | } |
| 6035 | 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] | 6036 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6037 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6038 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6039 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6040 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6041 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6042 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6043 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6044 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6045 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6046 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6048 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6049 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6050 | |
| 6051 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6052 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6053 | free(curproxy->conn_src.iface_name); |
| 6054 | curproxy->conn_src.iface_name = NULL; |
| 6055 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6056 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6057 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6058 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6059 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6060 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6061 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6062 | goto out; |
| 6063 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6064 | |
| 6065 | proto = protocol_by_family(sk->ss_family); |
| 6066 | if (!proto || !proto->connect) { |
| 6067 | 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] | 6068 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6070 | goto out; |
| 6071 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6072 | |
| 6073 | if (port1 != port2) { |
| 6074 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6075 | file, linenum, args[0], args[1]); |
| 6076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6077 | goto out; |
| 6078 | } |
| 6079 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6080 | curproxy->conn_src.source_addr = *sk; |
| 6081 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6082 | |
| 6083 | cur_arg = 2; |
| 6084 | while (*(args[cur_arg])) { |
| 6085 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6086 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6087 | if (!*args[cur_arg + 1]) { |
| 6088 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6089 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6091 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6095 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6096 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6097 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6098 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6099 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6100 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6101 | char *name, *end; |
| 6102 | |
| 6103 | name = args[cur_arg+1] + 7; |
| 6104 | while (isspace(*name)) |
| 6105 | name++; |
| 6106 | |
| 6107 | end = name; |
| 6108 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6109 | end++; |
| 6110 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6111 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6112 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6113 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6114 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6115 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6116 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6117 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6118 | |
| 6119 | /* now look for an occurrence number */ |
| 6120 | while (isspace(*end)) |
| 6121 | end++; |
| 6122 | if (*end == ',') { |
| 6123 | end++; |
| 6124 | name = end; |
| 6125 | if (*end == '-') |
| 6126 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6127 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6128 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6129 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6130 | } |
| 6131 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6132 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6133 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6134 | " occurrences values smaller than %d.\n", |
| 6135 | file, linenum, MAX_HDR_HISTORY); |
| 6136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6137 | goto out; |
| 6138 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6139 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6140 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6141 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6142 | 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] | 6143 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6144 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6145 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6146 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6147 | goto out; |
| 6148 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6149 | |
| 6150 | proto = protocol_by_family(sk->ss_family); |
| 6151 | if (!proto || !proto->connect) { |
| 6152 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6153 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6155 | goto out; |
| 6156 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6157 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6158 | if (port1 != port2) { |
| 6159 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6160 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6162 | goto out; |
| 6163 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6164 | curproxy->conn_src.tproxy_addr = *sk; |
| 6165 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6166 | } |
| 6167 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6168 | #else /* no TPROXY support */ |
| 6169 | 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] | 6170 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6172 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6173 | #endif |
| 6174 | cur_arg += 2; |
| 6175 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6176 | } |
| 6177 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6178 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6179 | #ifdef SO_BINDTODEVICE |
| 6180 | if (!*args[cur_arg + 1]) { |
| 6181 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6182 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6184 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6185 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6186 | free(curproxy->conn_src.iface_name); |
| 6187 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6188 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6189 | global.last_checks |= LSTCHK_NETADM; |
| 6190 | #else |
| 6191 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6192 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6194 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6195 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6196 | cur_arg += 2; |
| 6197 | continue; |
| 6198 | } |
| 6199 | 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] | 6200 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6202 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6203 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6204 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6205 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6206 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6207 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6209 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6210 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6211 | 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] | 6212 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6213 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6214 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6217 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6218 | |
| 6219 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6220 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6221 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6222 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6224 | } |
| 6225 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6226 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6227 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6228 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6229 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6230 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6231 | } |
| 6232 | 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] | 6233 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6234 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6235 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6236 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6237 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6238 | } |
| 6239 | 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] | 6240 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6241 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6242 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6243 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6244 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6245 | } |
| 6246 | 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] | 6247 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6248 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6249 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6250 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6251 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6252 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6253 | 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] | 6254 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6255 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6256 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6257 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6258 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6259 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6260 | 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] | 6261 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6262 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6263 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6265 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6266 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6267 | |
| 6268 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6269 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6270 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6271 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6272 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6273 | } |
| 6274 | 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] | 6275 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6276 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6277 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6278 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6279 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6280 | } |
| 6281 | 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] | 6282 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6283 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6284 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6285 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6286 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6287 | } |
| 6288 | 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] | 6289 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6290 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6291 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6292 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6293 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6294 | } |
| 6295 | 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] | 6296 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6297 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6298 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6299 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6300 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6301 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6302 | 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] | 6303 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6304 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6305 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6306 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6307 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6308 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6309 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6310 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6311 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6312 | if (curproxy == &defproxy) { |
| 6313 | 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] | 6314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6315 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6316 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6317 | 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] | 6318 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6320 | if (*(args[1]) == 0) { |
| 6321 | 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] | 6322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6324 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6325 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6326 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6327 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6328 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6329 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6331 | goto out; |
| 6332 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6333 | err_code |= warnif_cond_conflicts(cond, |
| 6334 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6335 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6336 | } |
| 6337 | else if (*args[2]) { |
| 6338 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6339 | file, linenum, args[0], args[2]); |
| 6340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6341 | goto out; |
| 6342 | } |
| 6343 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6344 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6345 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6346 | wl->s = strdup(args[1]); |
| 6347 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6348 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6349 | } |
| 6350 | 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] | 6351 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6352 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6353 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6355 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6356 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6357 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6358 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6359 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6360 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6361 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6362 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6363 | } |
| 6364 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6365 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6366 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6367 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6368 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6370 | } |
| 6371 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6372 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6373 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6374 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6375 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6376 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6377 | } |
| 6378 | 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] | 6379 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6380 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6381 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6383 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6384 | } |
| 6385 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6386 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6387 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6388 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6389 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6390 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6391 | } |
| 6392 | 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] | 6393 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6394 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6395 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6396 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6397 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6398 | } |
| 6399 | 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] | 6400 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6401 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6402 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6403 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6405 | } |
| 6406 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6407 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6408 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6409 | if (curproxy == &defproxy) { |
| 6410 | 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] | 6411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6412 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6413 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6414 | 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] | 6415 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6416 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6417 | if (*(args[1]) == 0) { |
| 6418 | 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] | 6419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6420 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6421 | } |
| 6422 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6423 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6424 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6425 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6426 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6427 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6428 | goto out; |
| 6429 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6430 | err_code |= warnif_cond_conflicts(cond, |
| 6431 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6432 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6433 | } |
| 6434 | else if (*args[2]) { |
| 6435 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6436 | file, linenum, args[0], args[2]); |
| 6437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6438 | goto out; |
| 6439 | } |
| 6440 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6441 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6442 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6443 | wl->s = strdup(args[1]); |
| 6444 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6445 | } |
| 6446 | else if (!strcmp(args[0], "errorloc") || |
| 6447 | !strcmp(args[0], "errorloc302") || |
| 6448 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6449 | int errnum, errlen; |
| 6450 | char *err; |
| 6451 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6452 | 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] | 6453 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6454 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6455 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6456 | 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] | 6457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6458 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | errnum = atol(args[1]); |
| 6462 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6463 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6464 | err = malloc(errlen); |
| 6465 | 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] | 6466 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6467 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6468 | err = malloc(errlen); |
| 6469 | 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] | 6470 | } |
| 6471 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6472 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6473 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6474 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6475 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6476 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6477 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6478 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6479 | |
| 6480 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6481 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6482 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6483 | free(err); |
| 6484 | } |
| 6485 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6486 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6487 | int errnum, errlen, fd; |
| 6488 | char *err; |
| 6489 | struct stat stat; |
| 6490 | |
| 6491 | 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] | 6492 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6493 | |
| 6494 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6495 | 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] | 6496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6497 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | fd = open(args[2], O_RDONLY); |
| 6501 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6502 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6503 | file, linenum, args[2], args[1]); |
| 6504 | if (fd >= 0) |
| 6505 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6507 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6508 | } |
| 6509 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6510 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6511 | errlen = stat.st_size; |
| 6512 | } else { |
| 6513 | 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] | 6514 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6515 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6516 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6520 | errnum = read(fd, err, errlen); |
| 6521 | if (errnum != errlen) { |
| 6522 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6523 | file, linenum, args[2], args[1]); |
| 6524 | close(fd); |
| 6525 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6527 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6528 | } |
| 6529 | close(fd); |
| 6530 | |
| 6531 | errnum = atol(args[1]); |
| 6532 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6533 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6534 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6535 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6536 | break; |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6541 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6542 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6543 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6544 | free(err); |
| 6545 | } |
| 6546 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6547 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6548 | struct cfg_kw_list *kwl; |
| 6549 | int index; |
| 6550 | |
| 6551 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6552 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6553 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6554 | continue; |
| 6555 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6556 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6557 | 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] | 6558 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6559 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6561 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6562 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6563 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6564 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6565 | err_code |= ERR_WARN; |
| 6566 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6567 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6568 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6569 | } |
| 6570 | } |
| 6571 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6572 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6573 | 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] | 6574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6575 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6576 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6577 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6578 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6579 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6580 | } |
| 6581 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6582 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6583 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6584 | { |
| 6585 | #ifdef CONFIG_HAP_NS |
| 6586 | const char *err; |
| 6587 | const char *item = args[0]; |
| 6588 | |
| 6589 | if (!strcmp(item, "namespace_list")) { |
| 6590 | return 0; |
| 6591 | } |
| 6592 | else if (!strcmp(item, "namespace")) { |
| 6593 | size_t idx = 1; |
| 6594 | const char *current; |
| 6595 | while (*(current = args[idx++])) { |
| 6596 | err = invalid_char(current); |
| 6597 | if (err) { |
| 6598 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6599 | file, linenum, *err, item, current); |
| 6600 | return ERR_ALERT | ERR_FATAL; |
| 6601 | } |
| 6602 | |
| 6603 | if (netns_store_lookup(current, strlen(current))) { |
| 6604 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6605 | file, linenum, current); |
| 6606 | return ERR_ALERT | ERR_FATAL; |
| 6607 | } |
| 6608 | if (!netns_store_insert(current)) { |
| 6609 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6610 | file, linenum, current); |
| 6611 | return ERR_ALERT | ERR_FATAL; |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | return 0; |
| 6617 | #else |
| 6618 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6619 | file, linenum); |
| 6620 | return ERR_ALERT | ERR_FATAL; |
| 6621 | #endif |
| 6622 | } |
| 6623 | |
| 6624 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6625 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6626 | { |
| 6627 | |
| 6628 | int err_code = 0; |
| 6629 | const char *err; |
| 6630 | |
| 6631 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6632 | struct userlist *newul; |
| 6633 | |
| 6634 | if (!*args[1]) { |
| 6635 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6636 | file, linenum, args[0]); |
| 6637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6638 | goto out; |
| 6639 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6640 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6641 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6642 | |
| 6643 | err = invalid_char(args[1]); |
| 6644 | if (err) { |
| 6645 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6646 | file, linenum, *err, args[0], args[1]); |
| 6647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6648 | goto out; |
| 6649 | } |
| 6650 | |
| 6651 | for (newul = userlist; newul; newul = newul->next) |
| 6652 | if (!strcmp(newul->name, args[1])) { |
| 6653 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6654 | file, linenum, args[1]); |
| 6655 | err_code |= ERR_WARN; |
| 6656 | goto out; |
| 6657 | } |
| 6658 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6659 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6660 | if (!newul) { |
| 6661 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6662 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6663 | goto out; |
| 6664 | } |
| 6665 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6666 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6667 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6668 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6669 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6670 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6671 | goto out; |
| 6672 | } |
| 6673 | |
| 6674 | newul->next = userlist; |
| 6675 | userlist = newul; |
| 6676 | |
| 6677 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6678 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6679 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6680 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6681 | |
| 6682 | if (!*args[1]) { |
| 6683 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6684 | file, linenum, args[0]); |
| 6685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6686 | goto out; |
| 6687 | } |
| 6688 | |
| 6689 | err = invalid_char(args[1]); |
| 6690 | if (err) { |
| 6691 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6692 | file, linenum, *err, args[0], args[1]); |
| 6693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6694 | goto out; |
| 6695 | } |
| 6696 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6697 | if (!userlist) |
| 6698 | goto out; |
| 6699 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6700 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6701 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6702 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6703 | file, linenum, args[1], userlist->name); |
| 6704 | err_code |= ERR_ALERT; |
| 6705 | goto out; |
| 6706 | } |
| 6707 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6708 | ag = calloc(1, sizeof(*ag)); |
| 6709 | if (!ag) { |
| 6710 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6711 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6712 | goto out; |
| 6713 | } |
| 6714 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6715 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6716 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6717 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6718 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6719 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6720 | goto out; |
| 6721 | } |
| 6722 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6723 | cur_arg = 2; |
| 6724 | |
| 6725 | while (*args[cur_arg]) { |
| 6726 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6727 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6728 | cur_arg += 2; |
| 6729 | continue; |
| 6730 | } else { |
| 6731 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6732 | file, linenum, args[0]); |
| 6733 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6734 | free(ag->groupusers); |
| 6735 | free(ag->name); |
| 6736 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6737 | goto out; |
| 6738 | } |
| 6739 | } |
| 6740 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6741 | ag->next = userlist->groups; |
| 6742 | userlist->groups = ag; |
| 6743 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6744 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6745 | struct auth_users *newuser; |
| 6746 | int cur_arg; |
| 6747 | |
| 6748 | if (!*args[1]) { |
| 6749 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6750 | file, linenum, args[0]); |
| 6751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6752 | goto out; |
| 6753 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6754 | if (!userlist) |
| 6755 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6756 | |
| 6757 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6758 | if (!strcmp(newuser->user, args[1])) { |
| 6759 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6760 | file, linenum, args[1], userlist->name); |
| 6761 | err_code |= ERR_ALERT; |
| 6762 | goto out; |
| 6763 | } |
| 6764 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6765 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6766 | if (!newuser) { |
| 6767 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6768 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6769 | goto out; |
| 6770 | } |
| 6771 | |
| 6772 | newuser->user = strdup(args[1]); |
| 6773 | |
| 6774 | newuser->next = userlist->users; |
| 6775 | userlist->users = newuser; |
| 6776 | |
| 6777 | cur_arg = 2; |
| 6778 | |
| 6779 | while (*args[cur_arg]) { |
| 6780 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6781 | #ifdef CONFIG_HAP_CRYPT |
| 6782 | if (!crypt("", args[cur_arg + 1])) { |
| 6783 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6784 | file, linenum, newuser->user); |
| 6785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6786 | goto out; |
| 6787 | } |
| 6788 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6789 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6790 | file, linenum); |
| 6791 | err_code |= ERR_ALERT; |
| 6792 | #endif |
| 6793 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6794 | cur_arg += 2; |
| 6795 | continue; |
| 6796 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6797 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6798 | newuser->flags |= AU_O_INSECURE; |
| 6799 | cur_arg += 2; |
| 6800 | continue; |
| 6801 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6802 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6803 | cur_arg += 2; |
| 6804 | continue; |
| 6805 | } else { |
| 6806 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6807 | file, linenum, args[0]); |
| 6808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6809 | goto out; |
| 6810 | } |
| 6811 | } |
| 6812 | } else { |
| 6813 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 6814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6815 | } |
| 6816 | |
| 6817 | out: |
| 6818 | return err_code; |
| 6819 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6820 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6821 | int |
| 6822 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6823 | { |
| 6824 | char *beg, *end, *scope = NULL; |
| 6825 | int err_code = 0; |
| 6826 | const char *err; |
| 6827 | |
| 6828 | beg = line + 1; |
| 6829 | end = strchr(beg, ']'); |
| 6830 | |
| 6831 | /* Detect end of scope declaration */ |
| 6832 | if (!end || end == beg) { |
| 6833 | Alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 6834 | file, linenum); |
| 6835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6836 | goto out; |
| 6837 | } |
| 6838 | |
| 6839 | /* Get scope name and check its validity */ |
| 6840 | scope = my_strndup(beg, end-beg); |
| 6841 | err = invalid_char(scope); |
| 6842 | if (err) { |
| 6843 | Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 6844 | file, linenum, *err); |
| 6845 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6846 | goto out; |
| 6847 | } |
| 6848 | |
| 6849 | /* Be sure to have a scope declaration alone on its line */ |
| 6850 | line = end+1; |
| 6851 | while (isspace((unsigned char)*line)) |
| 6852 | line++; |
| 6853 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
| 6854 | Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 6855 | file, linenum, *line); |
| 6856 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6857 | goto out; |
| 6858 | } |
| 6859 | |
| 6860 | /* We have a valid scope declaration, save it */ |
| 6861 | free(cfg_scope); |
| 6862 | cfg_scope = scope; |
| 6863 | scope = NULL; |
| 6864 | |
| 6865 | out: |
| 6866 | free(scope); |
| 6867 | return err_code; |
| 6868 | } |
| 6869 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6870 | /* |
| 6871 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6872 | * Returns the error code, 0 if OK, or any combination of : |
| 6873 | * - ERR_ABORT: must abort ASAP |
| 6874 | * - ERR_FATAL: we can continue parsing but not start the service |
| 6875 | * - ERR_WARN: a warning has been emitted |
| 6876 | * - ERR_ALERT: an alert has been emitted |
| 6877 | * Only the two first ones can stop processing, the two others are just |
| 6878 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6879 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 6880 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6881 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6882 | char *thisline; |
| 6883 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6884 | FILE *f; |
| 6885 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 6886 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6887 | struct cfg_section *cs = NULL; |
| 6888 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6889 | int readbytes = 0; |
| 6890 | |
| 6891 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6892 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6893 | return -1; |
| 6894 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 6895 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6896 | if ((f=fopen(file,"r")) == NULL) { |
| 6897 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6898 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6899 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6900 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 6901 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6902 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 6903 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6904 | char *end; |
| 6905 | char *args[MAX_LINE_ARGS + 1]; |
| 6906 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6907 | int dquote = 0; /* double quote */ |
| 6908 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6909 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6910 | linenum++; |
| 6911 | |
| 6912 | end = line + strlen(line); |
| 6913 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6914 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6915 | /* Check if we reached the limit and the last char is not \n. |
| 6916 | * Watch out for the last line without the terminating '\n'! |
| 6917 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6918 | char *newline; |
| 6919 | int newlinesize = linesize * 2; |
| 6920 | |
| 6921 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 6922 | if (newline == NULL) { |
| 6923 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 6924 | file, linenum); |
| 6925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6926 | continue; |
| 6927 | } |
| 6928 | |
| 6929 | readbytes = linesize - 1; |
| 6930 | linesize = newlinesize; |
| 6931 | thisline = newline; |
| 6932 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 6933 | } |
| 6934 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 6935 | readbytes = 0; |
| 6936 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6937 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 6938 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6939 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6940 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6941 | |
| 6942 | if (*line == '[') {/* This is the begining if a scope */ |
| 6943 | err_code |= cfg_parse_scope(file, linenum, line); |
| 6944 | goto next_line; |
| 6945 | } |
| 6946 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6947 | arg = 0; |
| 6948 | args[arg] = line; |
| 6949 | |
| 6950 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6951 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 6952 | if (dquote) |
| 6953 | dquote = 0; |
| 6954 | else |
| 6955 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 6956 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6957 | end--; |
| 6958 | } |
| 6959 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 6960 | if (squote) |
| 6961 | squote = 0; |
| 6962 | else |
| 6963 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 6964 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6965 | end--; |
| 6966 | } |
| 6967 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6968 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 6969 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 6970 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6971 | int skip = 0; |
| 6972 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 6973 | *line = line[1]; |
| 6974 | skip = 1; |
| 6975 | } |
| 6976 | else if (line[1] == 'r') { |
| 6977 | *line = '\r'; |
| 6978 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 6979 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6980 | else if (line[1] == 'n') { |
| 6981 | *line = '\n'; |
| 6982 | skip = 1; |
| 6983 | } |
| 6984 | else if (line[1] == 't') { |
| 6985 | *line = '\t'; |
| 6986 | skip = 1; |
| 6987 | } |
| 6988 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 6989 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6990 | unsigned char hex1, hex2; |
| 6991 | hex1 = toupper(line[2]) - '0'; |
| 6992 | hex2 = toupper(line[3]) - '0'; |
| 6993 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 6994 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 6995 | *line = (hex1<<4) + hex2; |
| 6996 | skip = 3; |
| 6997 | } |
| 6998 | else { |
| 6999 | 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] | 7000 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7001 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7002 | } else if (line[1] == '"') { |
| 7003 | *line = '"'; |
| 7004 | skip = 1; |
| 7005 | } else if (line[1] == '\'') { |
| 7006 | *line = '\''; |
| 7007 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7008 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7009 | *line = '$'; |
| 7010 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7011 | } |
| 7012 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7013 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7014 | end -= skip; |
| 7015 | } |
| 7016 | line++; |
| 7017 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7018 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7019 | /* end of string, end of loop */ |
| 7020 | *line = 0; |
| 7021 | break; |
| 7022 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7023 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7024 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7025 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7026 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7027 | line++; |
| 7028 | args[++arg] = line; |
| 7029 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7030 | else if (dquote && *line == '$') { |
| 7031 | /* environment variables are evaluated inside double quotes */ |
| 7032 | char *var_beg; |
| 7033 | char *var_end; |
| 7034 | char save_char; |
| 7035 | char *value; |
| 7036 | int val_len; |
| 7037 | int newlinesize; |
| 7038 | int braces = 0; |
| 7039 | |
| 7040 | var_beg = line + 1; |
| 7041 | var_end = var_beg; |
| 7042 | |
| 7043 | if (*var_beg == '{') { |
| 7044 | var_beg++; |
| 7045 | var_end++; |
| 7046 | braces = 1; |
| 7047 | } |
| 7048 | |
| 7049 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7050 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7052 | goto next_line; /* skip current line */ |
| 7053 | } |
| 7054 | |
| 7055 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7056 | var_end++; |
| 7057 | |
| 7058 | save_char = *var_end; |
| 7059 | *var_end = '\0'; |
| 7060 | value = getenv(var_beg); |
| 7061 | *var_end = save_char; |
| 7062 | val_len = value ? strlen(value) : 0; |
| 7063 | |
| 7064 | if (braces) { |
| 7065 | if (*var_end == '}') { |
| 7066 | var_end++; |
| 7067 | braces = 0; |
| 7068 | } else { |
| 7069 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7070 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7071 | goto next_line; /* skip current line */ |
| 7072 | } |
| 7073 | } |
| 7074 | |
| 7075 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7076 | |
| 7077 | /* if not enough space in thisline */ |
| 7078 | if (newlinesize > linesize) { |
| 7079 | char *newline; |
| 7080 | |
| 7081 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7082 | if (newline == NULL) { |
| 7083 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7085 | goto next_line; /* slip current line */ |
| 7086 | } |
| 7087 | /* recompute pointers if realloc returns a new pointer */ |
| 7088 | if (newline != thisline) { |
| 7089 | int i; |
| 7090 | int diff; |
| 7091 | |
| 7092 | for (i = 0; i <= arg; i++) { |
| 7093 | diff = args[i] - thisline; |
| 7094 | args[i] = newline + diff; |
| 7095 | } |
| 7096 | |
| 7097 | diff = var_end - thisline; |
| 7098 | var_end = newline + diff; |
| 7099 | diff = end - thisline; |
| 7100 | end = newline + diff; |
| 7101 | diff = line - thisline; |
| 7102 | line = newline + diff; |
| 7103 | thisline = newline; |
| 7104 | } |
| 7105 | linesize = newlinesize; |
| 7106 | } |
| 7107 | |
| 7108 | /* insert value inside the line */ |
| 7109 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7110 | memcpy(line, value, val_len); |
| 7111 | end += val_len - (var_end - line); |
| 7112 | line += val_len; |
| 7113 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7114 | else { |
| 7115 | line++; |
| 7116 | } |
| 7117 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7118 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7119 | if (dquote) { |
| 7120 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7122 | } |
| 7123 | |
| 7124 | if (squote) { |
| 7125 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7127 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7128 | |
| 7129 | /* empty line */ |
| 7130 | if (!**args) |
| 7131 | continue; |
| 7132 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7133 | if (*line) { |
| 7134 | /* we had to stop due to too many args. |
| 7135 | * Let's terminate the string, print the offending part then cut the |
| 7136 | * last arg. |
| 7137 | */ |
| 7138 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7139 | line++; |
| 7140 | *line = '\0'; |
| 7141 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7142 | 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] | 7143 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7145 | args[arg] = line; |
| 7146 | } |
| 7147 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7148 | /* zero out remaining args and ensure that at least one entry |
| 7149 | * is zeroed out. |
| 7150 | */ |
| 7151 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7152 | args[arg] = line; |
| 7153 | } |
| 7154 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7155 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7156 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7157 | char *tmp; |
| 7158 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7159 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7160 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7161 | for (arg=0; *args[arg+1]; arg++) |
| 7162 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7163 | *tmp = '\0'; // fix the next arg to \0 |
| 7164 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7165 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7166 | else if (!strcmp(args[0], "default")) { |
| 7167 | kwm = KWM_DEF; |
| 7168 | for (arg=0; *args[arg+1]; arg++) |
| 7169 | args[arg] = args[arg+1]; // shift args after inversion |
| 7170 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7171 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7172 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7173 | strcmp(args[0], "log") != 0) { |
| 7174 | 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] | 7175 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7176 | } |
| 7177 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7178 | /* detect section start */ |
| 7179 | list_for_each_entry(ics, §ions, list) { |
| 7180 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7181 | cursection = ics->section_name; |
| 7182 | cs = ics; |
| 7183 | break; |
| 7184 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7185 | } |
| 7186 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7187 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7188 | if (cs) |
| 7189 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7190 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7191 | 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] | 7192 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7193 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7194 | |
| 7195 | if (err_code & ERR_ABORT) |
| 7196 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7197 | } |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7198 | free(cfg_scope); |
| 7199 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7200 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7201 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7202 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7203 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7204 | } |
| 7205 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7206 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7207 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7208 | * bound to all of its processes. After that, if the target is a "listen" |
| 7209 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7210 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7211 | * checked first to ensure that <to> is already bound to all processes of |
| 7212 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7213 | * path to the destination. |
| 7214 | * |
| 7215 | * It is possible to set <to> to NULL for the first call so that the function |
| 7216 | * takes care of visiting the initial frontend in <from>. |
| 7217 | * |
| 7218 | * It is important to note that the function relies on the fact that all names |
| 7219 | * have already been resolved. |
| 7220 | */ |
| 7221 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7222 | { |
| 7223 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7224 | |
| 7225 | if (to) { |
| 7226 | /* check whether we need to go down */ |
| 7227 | if (from->bind_proc && |
| 7228 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7229 | return; |
| 7230 | |
| 7231 | if (!from->bind_proc && !to->bind_proc) |
| 7232 | return; |
| 7233 | |
| 7234 | to->bind_proc = from->bind_proc ? |
| 7235 | (to->bind_proc | from->bind_proc) : 0; |
| 7236 | |
| 7237 | /* now propagate down */ |
| 7238 | from = to; |
| 7239 | } |
| 7240 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7241 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7242 | return; |
| 7243 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7244 | if (from->state == PR_STSTOPPED) |
| 7245 | return; |
| 7246 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7247 | /* default_backend */ |
| 7248 | if (from->defbe.be) |
| 7249 | propagate_processes(from, from->defbe.be); |
| 7250 | |
| 7251 | /* use_backend */ |
| 7252 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7253 | if (rule->dynamic) |
| 7254 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7255 | to = rule->be.backend; |
| 7256 | propagate_processes(from, to); |
| 7257 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7258 | } |
| 7259 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7260 | /* |
| 7261 | * Returns the error code, 0 if OK, or any combination of : |
| 7262 | * - ERR_ABORT: must abort ASAP |
| 7263 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7264 | * - ERR_WARN: a warning has been emitted |
| 7265 | * - ERR_ALERT: an alert has been emitted |
| 7266 | * Only the two first ones can stop processing, the two others are just |
| 7267 | * indicators. |
| 7268 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7269 | int check_config_validity() |
| 7270 | { |
| 7271 | int cfgerr = 0; |
| 7272 | struct proxy *curproxy = NULL; |
| 7273 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7274 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7275 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7276 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7277 | char *err; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7278 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7279 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7280 | /* |
| 7281 | * Now, check for the integrity of all that we have collected. |
| 7282 | */ |
| 7283 | |
| 7284 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7285 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7286 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7287 | if (!global.tune.max_http_hdr) |
| 7288 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7289 | |
| 7290 | if (!global.tune.cookie_len) |
| 7291 | global.tune.cookie_len = CAPTURE_LEN; |
| 7292 | |
| 7293 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7294 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7295 | /* Post initialisation of the users and groups lists. */ |
| 7296 | err_code = userlist_postinit(); |
| 7297 | if (err_code != ERR_NONE) |
| 7298 | goto out; |
| 7299 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7300 | /* first, we will invert the proxy list order */ |
| 7301 | curproxy = NULL; |
| 7302 | while (proxy) { |
| 7303 | struct proxy *next; |
| 7304 | |
| 7305 | next = proxy->next; |
| 7306 | proxy->next = curproxy; |
| 7307 | curproxy = proxy; |
| 7308 | if (!next) |
| 7309 | break; |
| 7310 | proxy = next; |
| 7311 | } |
| 7312 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7313 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7314 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7315 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7316 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7317 | struct act_rule *trule; |
| 7318 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7319 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7320 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7321 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7322 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7323 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7324 | /* proxy ID not set, use automatic numbering with first |
| 7325 | * spare entry starting with next_pxid. |
| 7326 | */ |
| 7327 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7328 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7329 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7330 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7331 | next_pxid++; |
| 7332 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7333 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7334 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7335 | /* ensure we don't keep listeners uselessly bound */ |
| 7336 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7337 | free((void *)curproxy->table.peers.name); |
| 7338 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7339 | continue; |
| 7340 | } |
| 7341 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7342 | /* Check multi-process mode compatibility for the current proxy */ |
| 7343 | |
| 7344 | if (curproxy->bind_proc) { |
| 7345 | /* an explicit bind-process was specified, let's check how many |
| 7346 | * processes remain. |
| 7347 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7348 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7349 | |
| 7350 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7351 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7352 | 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); |
| 7353 | curproxy->bind_proc = 1; |
| 7354 | } |
| 7355 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7356 | 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); |
| 7357 | curproxy->bind_proc = 0; |
| 7358 | } |
| 7359 | } |
| 7360 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7361 | /* check and reduce the bind-proc of each listener */ |
| 7362 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7363 | unsigned long mask; |
| 7364 | |
| 7365 | if (!bind_conf->bind_proc) |
| 7366 | continue; |
| 7367 | |
| 7368 | mask = nbits(global.nbproc); |
| 7369 | if (curproxy->bind_proc) |
| 7370 | mask &= curproxy->bind_proc; |
| 7371 | /* mask cannot be null here thanks to the previous checks */ |
| 7372 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7373 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7374 | bind_conf->bind_proc &= mask; |
| 7375 | |
| 7376 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7377 | 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", |
| 7378 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7379 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7380 | } |
| 7381 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7382 | 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", |
| 7383 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7384 | bind_conf->bind_proc = 0; |
| 7385 | } |
| 7386 | } |
| 7387 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7388 | switch (curproxy->mode) { |
| 7389 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7390 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7391 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7392 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7393 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7394 | cfgerr++; |
| 7395 | } |
| 7396 | |
| 7397 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7398 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7399 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7400 | break; |
| 7401 | |
| 7402 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7403 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7404 | break; |
| 7405 | |
| 7406 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7407 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7408 | break; |
| 7409 | } |
| 7410 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7411 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7412 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7413 | proxy_type_str(curproxy), curproxy->id); |
| 7414 | err_code |= ERR_WARN; |
| 7415 | } |
| 7416 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7417 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7418 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7419 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7420 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7421 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7422 | cfgerr++; |
| 7423 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7424 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7425 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7426 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7427 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7428 | cfgerr++; |
| 7429 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7430 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7431 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7432 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7433 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7434 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7435 | } |
| 7436 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7437 | 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] | 7438 | /* If no LB algo is set in a backend, and we're not in |
| 7439 | * transparent mode, dispatch mode nor proxy mode, we |
| 7440 | * want to use balance roundrobin by default. |
| 7441 | */ |
| 7442 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7443 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7444 | } |
| 7445 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7446 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7447 | if (curproxy->options & PR_O_DISPATCH) |
| 7448 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7449 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7450 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7451 | else if (curproxy->options & PR_O_TRANSP) |
| 7452 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7453 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7454 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7455 | if (curproxy->options & PR_O_DISABLE404) { |
| 7456 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7457 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7458 | err_code |= ERR_WARN; |
| 7459 | curproxy->options &= ~PR_O_DISABLE404; |
| 7460 | } |
| 7461 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7462 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7463 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7464 | err_code |= ERR_WARN; |
| 7465 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7466 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7467 | } |
| 7468 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7469 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7470 | if (!global.external_check) { |
| 7471 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7472 | curproxy->id, "option external-check"); |
| 7473 | cfgerr++; |
| 7474 | } |
| 7475 | if (!curproxy->check_command) { |
| 7476 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7477 | curproxy->id, "option external-check"); |
| 7478 | cfgerr++; |
| 7479 | } |
| 7480 | } |
| 7481 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7482 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7483 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7484 | 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] | 7485 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7486 | "'email-alert myhostname', or 'email-alert to' " |
| 7487 | "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] | 7488 | "to be present).\n", |
| 7489 | proxy_type_str(curproxy), curproxy->id); |
| 7490 | err_code |= ERR_WARN; |
| 7491 | free_email_alert(curproxy); |
| 7492 | } |
| 7493 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7494 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7495 | } |
| 7496 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7497 | if (curproxy->check_command) { |
| 7498 | int clear = 0; |
| 7499 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7500 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7501 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7502 | err_code |= ERR_WARN; |
| 7503 | clear = 1; |
| 7504 | } |
| 7505 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7506 | 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] | 7507 | curproxy->id, "external-check command"); |
| 7508 | cfgerr++; |
| 7509 | } |
| 7510 | if (clear) { |
| 7511 | free(curproxy->check_command); |
| 7512 | curproxy->check_command = NULL; |
| 7513 | } |
| 7514 | } |
| 7515 | |
| 7516 | if (curproxy->check_path) { |
| 7517 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7518 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7519 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7520 | err_code |= ERR_WARN; |
| 7521 | free(curproxy->check_path); |
| 7522 | curproxy->check_path = NULL; |
| 7523 | } |
| 7524 | } |
| 7525 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7526 | /* if a default backend was specified, let's find it */ |
| 7527 | if (curproxy->defbe.name) { |
| 7528 | struct proxy *target; |
| 7529 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7530 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7531 | if (!target) { |
| 7532 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7533 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7534 | cfgerr++; |
| 7535 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7536 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7537 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7538 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7539 | } else if (target->mode != curproxy->mode && |
| 7540 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7541 | |
| 7542 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7543 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7544 | curproxy->conf.file, curproxy->conf.line, |
| 7545 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7546 | target->conf.file, target->conf.line); |
| 7547 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7548 | } else { |
| 7549 | free(curproxy->defbe.name); |
| 7550 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7551 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7552 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7553 | /* Emit a warning if this proxy also has some servers */ |
| 7554 | if (curproxy->srv) { |
| 7555 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7556 | curproxy->id); |
| 7557 | err_code |= ERR_WARN; |
| 7558 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7559 | } |
| 7560 | } |
| 7561 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7562 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7563 | /* Case of listen without default backend |
| 7564 | * The curproxy will be its own default backend |
| 7565 | * so we update tot_fe_maxconn for a further |
| 7566 | * fullconn's computation */ |
| 7567 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7568 | } |
| 7569 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7570 | /* find the target proxy for 'use_backend' rules */ |
| 7571 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7572 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7573 | struct logformat_node *node; |
| 7574 | char *pxname; |
| 7575 | |
| 7576 | /* Try to parse the string as a log format expression. If the result |
| 7577 | * of the parsing is only one entry containing a simple string, then |
| 7578 | * it's a standard string corresponding to a static rule, thus the |
| 7579 | * parsing is cancelled and be.name is restored to be resolved. |
| 7580 | */ |
| 7581 | pxname = rule->be.name; |
| 7582 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7583 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7584 | curproxy->conf.args.file = rule->file; |
| 7585 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7586 | err = NULL; |
| 7587 | if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
| 7588 | Alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7589 | rule->file, rule->line, pxname, err); |
| 7590 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7591 | cfgerr++; |
| 7592 | continue; |
| 7593 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7594 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7595 | |
| 7596 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7597 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7598 | rule->dynamic = 1; |
| 7599 | free(pxname); |
| 7600 | continue; |
| 7601 | } |
| 7602 | /* simple string: free the expression and fall back to static rule */ |
| 7603 | free(node->arg); |
| 7604 | free(node); |
| 7605 | } |
| 7606 | |
| 7607 | rule->dynamic = 0; |
| 7608 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7609 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7610 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7611 | if (!target) { |
| 7612 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7613 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7614 | cfgerr++; |
| 7615 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7616 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7617 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7618 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7619 | } else if (target->mode != curproxy->mode && |
| 7620 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7621 | |
| 7622 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7623 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7624 | curproxy->conf.file, curproxy->conf.line, |
| 7625 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7626 | target->conf.file, target->conf.line); |
| 7627 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7628 | } else { |
| 7629 | free((void *)rule->be.name); |
| 7630 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7631 | /* For each target of switching rules, we update |
| 7632 | * their tot_fe_maxconn, except if a previous rule point |
| 7633 | * on the same backend or on the default backend */ |
| 7634 | if (rule->be.backend != curproxy->defbe.be) { |
| 7635 | struct switching_rule *swrule; |
| 7636 | |
| 7637 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7638 | if (rule == swrule) { |
| 7639 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7640 | break; |
| 7641 | } |
| 7642 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7643 | /* there is multiple ref of this backend */ |
| 7644 | break; |
| 7645 | } |
| 7646 | } |
| 7647 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7648 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7649 | } |
| 7650 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7651 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7652 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7653 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7654 | |
| 7655 | if (!target) { |
| 7656 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7657 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7658 | cfgerr++; |
| 7659 | continue; |
| 7660 | } |
| 7661 | free((void *)srule->srv.name); |
| 7662 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7663 | } |
| 7664 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7665 | /* find the target table for 'stick' rules */ |
| 7666 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7667 | struct proxy *target; |
| 7668 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7669 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7670 | if (mrule->flags & STK_IS_STORE) |
| 7671 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7672 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7673 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7674 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7675 | else |
| 7676 | target = curproxy; |
| 7677 | |
| 7678 | if (!target) { |
| 7679 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7680 | curproxy->id, mrule->table.name); |
| 7681 | cfgerr++; |
| 7682 | } |
| 7683 | else if (target->table.size == 0) { |
| 7684 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7685 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7686 | cfgerr++; |
| 7687 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7688 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7689 | 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] | 7690 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7691 | cfgerr++; |
| 7692 | } |
| 7693 | else { |
| 7694 | free((void *)mrule->table.name); |
| 7695 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7696 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | /* find the target table for 'store response' rules */ |
| 7701 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7702 | struct proxy *target; |
| 7703 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7704 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7705 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7706 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7707 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7708 | else |
| 7709 | target = curproxy; |
| 7710 | |
| 7711 | if (!target) { |
| 7712 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7713 | curproxy->id, mrule->table.name); |
| 7714 | cfgerr++; |
| 7715 | } |
| 7716 | else if (target->table.size == 0) { |
| 7717 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7718 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7719 | cfgerr++; |
| 7720 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7721 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7722 | 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] | 7723 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7724 | cfgerr++; |
| 7725 | } |
| 7726 | else { |
| 7727 | free((void *)mrule->table.name); |
| 7728 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7729 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7730 | } |
| 7731 | } |
| 7732 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7733 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7734 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7735 | struct proxy *target; |
| 7736 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7737 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7738 | continue; |
| 7739 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7740 | if (trule->arg.trk_ctr.table.n) |
| 7741 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7742 | else |
| 7743 | target = curproxy; |
| 7744 | |
| 7745 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7746 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7747 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7748 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7749 | cfgerr++; |
| 7750 | } |
| 7751 | else if (target->table.size == 0) { |
| 7752 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7753 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7754 | cfgerr++; |
| 7755 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7756 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7757 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7758 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7759 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7760 | cfgerr++; |
| 7761 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7762 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7763 | free(trule->arg.trk_ctr.table.n); |
| 7764 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7765 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7766 | * to pass a list of counters to track and allocate them right here using |
| 7767 | * stktable_alloc_data_type(). |
| 7768 | */ |
| 7769 | } |
| 7770 | } |
| 7771 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7772 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7773 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7774 | struct proxy *target; |
| 7775 | |
| 7776 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7777 | continue; |
| 7778 | |
| 7779 | if (trule->arg.trk_ctr.table.n) |
| 7780 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7781 | else |
| 7782 | target = curproxy; |
| 7783 | |
| 7784 | if (!target) { |
| 7785 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7786 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7787 | tcp_trk_idx(trule->action)); |
| 7788 | cfgerr++; |
| 7789 | } |
| 7790 | else if (target->table.size == 0) { |
| 7791 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7792 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7793 | cfgerr++; |
| 7794 | } |
| 7795 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7796 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7797 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7798 | tcp_trk_idx(trule->action)); |
| 7799 | cfgerr++; |
| 7800 | } |
| 7801 | else { |
| 7802 | free(trule->arg.trk_ctr.table.n); |
| 7803 | trule->arg.trk_ctr.table.t = &target->table; |
| 7804 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7805 | * to pass a list of counters to track and allocate them right here using |
| 7806 | * stktable_alloc_data_type(). |
| 7807 | */ |
| 7808 | } |
| 7809 | } |
| 7810 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7811 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7812 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7813 | struct proxy *target; |
| 7814 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7815 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7816 | continue; |
| 7817 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7818 | if (trule->arg.trk_ctr.table.n) |
| 7819 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7820 | else |
| 7821 | target = curproxy; |
| 7822 | |
| 7823 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7824 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7825 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7826 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7827 | cfgerr++; |
| 7828 | } |
| 7829 | else if (target->table.size == 0) { |
| 7830 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7831 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7832 | cfgerr++; |
| 7833 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7834 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7835 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7836 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7837 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7838 | cfgerr++; |
| 7839 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7840 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7841 | free(trule->arg.trk_ctr.table.n); |
| 7842 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7843 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7844 | * to pass a list of counters to track and allocate them right here using |
| 7845 | * stktable_alloc_data_type(). |
| 7846 | */ |
| 7847 | } |
| 7848 | } |
| 7849 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7850 | /* parse http-request capture rules to ensure id really exists */ |
| 7851 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7852 | if (hrqrule->action != ACT_CUSTOM || |
| 7853 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 7854 | continue; |
| 7855 | |
| 7856 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 7857 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 7858 | curproxy->id, hrqrule->arg.capid.idx); |
| 7859 | cfgerr++; |
| 7860 | } |
| 7861 | } |
| 7862 | |
| 7863 | /* parse http-response capture rules to ensure id really exists */ |
| 7864 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7865 | if (hrqrule->action != ACT_CUSTOM || |
| 7866 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 7867 | continue; |
| 7868 | |
| 7869 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 7870 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 7871 | curproxy->id, hrqrule->arg.capid.idx); |
| 7872 | cfgerr++; |
| 7873 | } |
| 7874 | } |
| 7875 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7876 | /* find the target table for 'http-request' layer 7 rules */ |
| 7877 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 7878 | struct proxy *target; |
| 7879 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7880 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7881 | continue; |
| 7882 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7883 | if (hrqrule->arg.trk_ctr.table.n) |
| 7884 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7885 | else |
| 7886 | target = curproxy; |
| 7887 | |
| 7888 | if (!target) { |
| 7889 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7890 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7891 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7892 | cfgerr++; |
| 7893 | } |
| 7894 | else if (target->table.size == 0) { |
| 7895 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7896 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7897 | cfgerr++; |
| 7898 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7899 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7900 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7901 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7902 | http_trk_idx(hrqrule->action)); |
| 7903 | cfgerr++; |
| 7904 | } |
| 7905 | else { |
| 7906 | free(hrqrule->arg.trk_ctr.table.n); |
| 7907 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 7908 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7909 | * to pass a list of counters to track and allocate them right here using |
| 7910 | * stktable_alloc_data_type(). |
| 7911 | */ |
| 7912 | } |
| 7913 | } |
| 7914 | |
| 7915 | /* find the target table for 'http-response' layer 7 rules */ |
| 7916 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 7917 | struct proxy *target; |
| 7918 | |
| 7919 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 7920 | continue; |
| 7921 | |
| 7922 | if (hrqrule->arg.trk_ctr.table.n) |
| 7923 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 7924 | else |
| 7925 | target = curproxy; |
| 7926 | |
| 7927 | if (!target) { |
| 7928 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7929 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 7930 | http_trk_idx(hrqrule->action)); |
| 7931 | cfgerr++; |
| 7932 | } |
| 7933 | else if (target->table.size == 0) { |
| 7934 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7935 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 7936 | cfgerr++; |
| 7937 | } |
| 7938 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 7939 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7940 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 7941 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7942 | cfgerr++; |
| 7943 | } |
| 7944 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7945 | free(hrqrule->arg.trk_ctr.table.n); |
| 7946 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7947 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7948 | * to pass a list of counters to track and allocate them right here using |
| 7949 | * stktable_alloc_data_type(). |
| 7950 | */ |
| 7951 | } |
| 7952 | } |
| 7953 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 7954 | /* move any "block" rules at the beginning of the http-request rules */ |
| 7955 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 7956 | /* insert block_rules into http_req_rules at the beginning */ |
| 7957 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 7958 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 7959 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 7960 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 7961 | LIST_INIT(&curproxy->block_rules); |
| 7962 | } |
| 7963 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7964 | if (curproxy->table.peers.name) { |
| 7965 | struct peers *curpeers = peers; |
| 7966 | |
| 7967 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 7968 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 7969 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 7970 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7971 | break; |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | if (!curpeers) { |
| 7976 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 7977 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7978 | free((void *)curproxy->table.peers.name); |
| 7979 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7980 | cfgerr++; |
| 7981 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 7982 | else if (curpeers->state == PR_STSTOPPED) { |
| 7983 | /* silently disable this peers section */ |
| 7984 | curproxy->table.peers.p = NULL; |
| 7985 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7986 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 7987 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 7988 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 7989 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7990 | cfgerr++; |
| 7991 | } |
| 7992 | } |
| 7993 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7994 | |
| 7995 | if (curproxy->email_alert.mailers.name) { |
| 7996 | struct mailers *curmailers = mailers; |
| 7997 | |
| 7998 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 7999 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8000 | free(curproxy->email_alert.mailers.name); |
| 8001 | curproxy->email_alert.mailers.m = curmailers; |
| 8002 | curmailers->users++; |
| 8003 | break; |
| 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | if (!curmailers) { |
| 8008 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8009 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8010 | free_email_alert(curproxy); |
| 8011 | cfgerr++; |
| 8012 | } |
| 8013 | } |
| 8014 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8015 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8016 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8017 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8018 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8019 | "proxy", curproxy->id); |
| 8020 | cfgerr++; |
| 8021 | goto out_uri_auth_compat; |
| 8022 | } |
| 8023 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8024 | 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] | 8025 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8026 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8027 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8028 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8029 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8030 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8031 | |
| 8032 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8033 | uri_auth_compat_req[i++] = "realm"; |
| 8034 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8035 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8036 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8037 | uri_auth_compat_req[i++] = "unless"; |
| 8038 | uri_auth_compat_req[i++] = "{"; |
| 8039 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8040 | uri_auth_compat_req[i++] = "}"; |
| 8041 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8042 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8043 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8044 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8045 | cfgerr++; |
| 8046 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8047 | } |
| 8048 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8049 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8050 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8051 | if (curproxy->uri_auth->auth_realm) { |
| 8052 | free(curproxy->uri_auth->auth_realm); |
| 8053 | curproxy->uri_auth->auth_realm = NULL; |
| 8054 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8055 | |
| 8056 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8057 | } |
| 8058 | out_uri_auth_compat: |
| 8059 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8060 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8061 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8062 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8063 | if (!curproxy->conf.logformat_sd_string) { |
| 8064 | /* set the default logformat_sd_string */ |
| 8065 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8066 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8067 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8068 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8069 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8070 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8071 | /* compile the log format */ |
| 8072 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8073 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8074 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8075 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8076 | free(curproxy->conf.logformat_string); |
| 8077 | curproxy->conf.logformat_string = NULL; |
| 8078 | free(curproxy->conf.lfs_file); |
| 8079 | curproxy->conf.lfs_file = NULL; |
| 8080 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8081 | |
| 8082 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8083 | free(curproxy->conf.logformat_sd_string); |
| 8084 | curproxy->conf.logformat_sd_string = NULL; |
| 8085 | free(curproxy->conf.lfsd_file); |
| 8086 | curproxy->conf.lfsd_file = NULL; |
| 8087 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8088 | } |
| 8089 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8090 | if (curproxy->conf.logformat_string) { |
| 8091 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8092 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8093 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8094 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8095 | 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] | 8096 | SMP_VAL_FE_LOG_END, &err)) { |
| 8097 | Alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8098 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8099 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8100 | cfgerr++; |
| 8101 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8102 | curproxy->conf.args.file = NULL; |
| 8103 | curproxy->conf.args.line = 0; |
| 8104 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8105 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8106 | if (curproxy->conf.logformat_sd_string) { |
| 8107 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8108 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8109 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8110 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8111 | 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] | 8112 | SMP_VAL_FE_LOG_END, &err)) { |
| 8113 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8114 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8115 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8116 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8117 | } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) { |
| 8118 | Alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8119 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
| 8120 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8121 | cfgerr++; |
| 8122 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8123 | curproxy->conf.args.file = NULL; |
| 8124 | curproxy->conf.args.line = 0; |
| 8125 | } |
| 8126 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8127 | if (curproxy->conf.uniqueid_format_string) { |
| 8128 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8129 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8130 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8131 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8132 | 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] | 8133 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) { |
| 8134 | Alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8135 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
| 8136 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8137 | cfgerr++; |
| 8138 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8139 | curproxy->conf.args.file = NULL; |
| 8140 | curproxy->conf.args.line = 0; |
| 8141 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8142 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8143 | /* only now we can check if some args remain unresolved. |
| 8144 | * This must be done after the users and groups resolution. |
| 8145 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8146 | cfgerr += smp_resolve_args(curproxy); |
| 8147 | if (!cfgerr) |
| 8148 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8149 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8150 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8151 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8152 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8153 | (!curproxy->timeout.connect || |
| 8154 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8155 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8156 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8157 | " | 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] | 8158 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8159 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8160 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8161 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8162 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8163 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8164 | * We must still support older configurations, so let's find out whether those |
| 8165 | * parameters have been set or must be copied from contimeouts. |
| 8166 | */ |
| 8167 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8168 | if (!curproxy->timeout.tarpit || |
| 8169 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8170 | /* tarpit timeout not set. We search in the following order: |
| 8171 | * default.tarpit, curr.connect, default.connect. |
| 8172 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8173 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8174 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8175 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8176 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8177 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8178 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8179 | } |
| 8180 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8181 | (!curproxy->timeout.queue || |
| 8182 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8183 | /* queue timeout not set. We search in the following order: |
| 8184 | * default.queue, curr.connect, default.connect. |
| 8185 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8186 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8187 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8188 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8189 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8190 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8191 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8192 | } |
| 8193 | } |
| 8194 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8195 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8196 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8197 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8198 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8199 | } |
| 8200 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8201 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8202 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8203 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8204 | proxy_type_str(curproxy), curproxy->id); |
| 8205 | err_code |= ERR_WARN; |
| 8206 | } |
| 8207 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8208 | /* ensure that cookie capture length is not too large */ |
| 8209 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8210 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8211 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8212 | err_code |= ERR_WARN; |
| 8213 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8214 | } |
| 8215 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8216 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8217 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8218 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8219 | curproxy->nb_req_cap * sizeof(char *), |
| 8220 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8221 | } |
| 8222 | |
| 8223 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8224 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8225 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8226 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8227 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8228 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8229 | switch (curproxy->load_server_state_from_file) { |
| 8230 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8231 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8232 | break; |
| 8233 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8234 | if (!global.server_state_file) { |
| 8235 | 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", |
| 8236 | curproxy->id); |
| 8237 | err_code |= ERR_WARN; |
| 8238 | } |
| 8239 | break; |
| 8240 | } |
| 8241 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8242 | /* first, we will invert the servers list order */ |
| 8243 | newsrv = NULL; |
| 8244 | while (curproxy->srv) { |
| 8245 | struct server *next; |
| 8246 | |
| 8247 | next = curproxy->srv->next; |
| 8248 | curproxy->srv->next = newsrv; |
| 8249 | newsrv = curproxy->srv; |
| 8250 | if (!next) |
| 8251 | break; |
| 8252 | curproxy->srv = next; |
| 8253 | } |
| 8254 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8255 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8256 | * We only emit a warning for the first conflict affecting each server, |
| 8257 | * in order to avoid combinatory explosion if all servers have the same |
| 8258 | * name. We do that only for servers which do not have an explicit ID, |
| 8259 | * because these IDs were made also for distinguishing them and we don't |
| 8260 | * want to annoy people who correctly manage them. |
| 8261 | */ |
| 8262 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8263 | struct server *other_srv; |
| 8264 | |
| 8265 | if (newsrv->puid) |
| 8266 | continue; |
| 8267 | |
| 8268 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8269 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8270 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8271 | newsrv->conf.file, newsrv->conf.line, |
| 8272 | proxy_type_str(curproxy), curproxy->id, |
| 8273 | newsrv->id, other_srv->conf.line); |
| 8274 | break; |
| 8275 | } |
| 8276 | } |
| 8277 | } |
| 8278 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8279 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8280 | next_id = 1; |
| 8281 | newsrv = curproxy->srv; |
| 8282 | while (newsrv != NULL) { |
| 8283 | if (!newsrv->puid) { |
| 8284 | /* server ID not set, use automatic numbering with first |
| 8285 | * spare entry starting with next_svid. |
| 8286 | */ |
| 8287 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8288 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8289 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8290 | } |
| 8291 | next_id++; |
| 8292 | newsrv = newsrv->next; |
| 8293 | } |
| 8294 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8295 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8296 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8297 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8298 | /* |
| 8299 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8300 | * tasks to fill the emptied slots when a connection leaves. |
| 8301 | * Also, resolve deferred tracking dependency if needed. |
| 8302 | */ |
| 8303 | newsrv = curproxy->srv; |
| 8304 | while (newsrv != NULL) { |
| 8305 | if (newsrv->minconn > newsrv->maxconn) { |
| 8306 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8307 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8308 | * this will avoid further useless expensive computations. |
| 8309 | */ |
| 8310 | newsrv->maxconn = newsrv->minconn; |
| 8311 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8312 | /* minconn was not specified, so we set it to maxconn */ |
| 8313 | newsrv->minconn = newsrv->maxconn; |
| 8314 | } |
| 8315 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8316 | /* this will also properly set the transport layer for prod and checks */ |
| 8317 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8318 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8319 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8320 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8321 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8322 | /* set the check type on the server */ |
| 8323 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8324 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8325 | if (newsrv->trackit) { |
| 8326 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8327 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8328 | char *pname, *sname; |
| 8329 | |
| 8330 | pname = newsrv->trackit; |
| 8331 | sname = strrchr(pname, '/'); |
| 8332 | |
| 8333 | if (sname) |
| 8334 | *sname++ = '\0'; |
| 8335 | else { |
| 8336 | sname = pname; |
| 8337 | pname = NULL; |
| 8338 | } |
| 8339 | |
| 8340 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8341 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8342 | if (!px) { |
| 8343 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8344 | proxy_type_str(curproxy), curproxy->id, |
| 8345 | newsrv->id, pname); |
| 8346 | cfgerr++; |
| 8347 | goto next_srv; |
| 8348 | } |
| 8349 | } else |
| 8350 | px = curproxy; |
| 8351 | |
| 8352 | srv = findserver(px, sname); |
| 8353 | if (!srv) { |
| 8354 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8355 | proxy_type_str(curproxy), curproxy->id, |
| 8356 | newsrv->id, sname); |
| 8357 | cfgerr++; |
| 8358 | goto next_srv; |
| 8359 | } |
| 8360 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8361 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8362 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8363 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8364 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8365 | "tracking as it does not have any check nor agent enabled.\n", |
| 8366 | proxy_type_str(curproxy), curproxy->id, |
| 8367 | newsrv->id, px->id, srv->id); |
| 8368 | cfgerr++; |
| 8369 | goto next_srv; |
| 8370 | } |
| 8371 | |
| 8372 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8373 | |
| 8374 | if (loop) { |
| 8375 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8376 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8377 | proxy_type_str(curproxy), curproxy->id, |
| 8378 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8379 | cfgerr++; |
| 8380 | goto next_srv; |
| 8381 | } |
| 8382 | |
| 8383 | if (curproxy != px && |
| 8384 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8385 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8386 | "tracking: disable-on-404 option inconsistency.\n", |
| 8387 | proxy_type_str(curproxy), curproxy->id, |
| 8388 | newsrv->id, px->id, srv->id); |
| 8389 | cfgerr++; |
| 8390 | goto next_srv; |
| 8391 | } |
| 8392 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8393 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8394 | newsrv->tracknext = srv->trackers; |
| 8395 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8396 | |
| 8397 | free(newsrv->trackit); |
| 8398 | newsrv->trackit = NULL; |
| 8399 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8400 | |
| 8401 | /* |
| 8402 | * resolve server's resolvers name and update the resolvers pointer |
| 8403 | * accordingly |
| 8404 | */ |
| 8405 | if (newsrv->resolvers_id) { |
| 8406 | struct dns_resolvers *curr_resolvers; |
| 8407 | int found; |
| 8408 | |
| 8409 | found = 0; |
| 8410 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8411 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8412 | found = 1; |
| 8413 | break; |
| 8414 | } |
| 8415 | } |
| 8416 | |
| 8417 | if (!found) { |
| 8418 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8419 | proxy_type_str(curproxy), curproxy->id, |
| 8420 | newsrv->id, newsrv->resolvers_id); |
| 8421 | cfgerr++; |
| 8422 | } else { |
| 8423 | free(newsrv->resolvers_id); |
| 8424 | newsrv->resolvers_id = NULL; |
| 8425 | if (newsrv->resolution) |
| 8426 | newsrv->resolution->resolvers = curr_resolvers; |
| 8427 | } |
| 8428 | } |
| 8429 | else { |
| 8430 | /* if no resolvers section associated to this server |
| 8431 | * we can clean up the associated resolution structure |
| 8432 | */ |
| 8433 | if (newsrv->resolution) { |
| 8434 | free(newsrv->resolution->hostname_dn); |
| 8435 | newsrv->resolution->hostname_dn = NULL; |
| 8436 | free(newsrv->resolution); |
| 8437 | newsrv->resolution = NULL; |
| 8438 | } |
| 8439 | } |
| 8440 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8441 | next_srv: |
| 8442 | newsrv = newsrv->next; |
| 8443 | } |
| 8444 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8445 | /* We have to initialize the server lookup mechanism depending |
| 8446 | * on what LB algorithm was choosen. |
| 8447 | */ |
| 8448 | |
| 8449 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8450 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8451 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8452 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8453 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8454 | init_server_map(curproxy); |
| 8455 | } else { |
| 8456 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8457 | fwrr_init_server_groups(curproxy); |
| 8458 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8459 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8460 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8461 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8462 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8463 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8464 | fwlc_init_server_tree(curproxy); |
| 8465 | } else { |
| 8466 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8467 | fas_init_server_tree(curproxy); |
| 8468 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8469 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8470 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8471 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8472 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8473 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8474 | chash_init_server_tree(curproxy); |
| 8475 | } else { |
| 8476 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8477 | init_server_map(curproxy); |
| 8478 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8479 | break; |
| 8480 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8481 | |
| 8482 | if (curproxy->options & PR_O_LOGASAP) |
| 8483 | curproxy->to_log &= ~LW_BYTES; |
| 8484 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8485 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8486 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8487 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8488 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8489 | proxy_type_str(curproxy), curproxy->id); |
| 8490 | err_code |= ERR_WARN; |
| 8491 | } |
| 8492 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8493 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8494 | int optnum; |
| 8495 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8496 | if (curproxy->uri_auth) { |
| 8497 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8498 | proxy_type_str(curproxy), curproxy->id); |
| 8499 | err_code |= ERR_WARN; |
| 8500 | curproxy->uri_auth = NULL; |
| 8501 | } |
| 8502 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8503 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8504 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8505 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8506 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8507 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8508 | } |
| 8509 | |
| 8510 | if (curproxy->options & PR_O_ORGTO) { |
| 8511 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8512 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8513 | err_code |= ERR_WARN; |
| 8514 | curproxy->options &= ~PR_O_ORGTO; |
| 8515 | } |
| 8516 | |
| 8517 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8518 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8519 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8520 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8521 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8522 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8523 | err_code |= ERR_WARN; |
| 8524 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8525 | } |
| 8526 | } |
| 8527 | |
| 8528 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8529 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8530 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8531 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8532 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8533 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8534 | err_code |= ERR_WARN; |
| 8535 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8536 | } |
| 8537 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8538 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8539 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8540 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8541 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8542 | 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] | 8543 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8544 | err_code |= ERR_WARN; |
| 8545 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8546 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8547 | } |
| 8548 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8549 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8550 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8551 | */ |
| 8552 | newsrv = curproxy->srv; |
| 8553 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8554 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8555 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8556 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8557 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8558 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8559 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8560 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8561 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8562 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8563 | err_code |= ERR_WARN; |
| 8564 | } |
| 8565 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8566 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8567 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8568 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8569 | err_code |= ERR_WARN; |
| 8570 | } |
| 8571 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8572 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8573 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8574 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8575 | 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] | 8576 | 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] | 8577 | err_code |= ERR_WARN; |
| 8578 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8579 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8580 | |
| 8581 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8582 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8583 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8584 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8585 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
| 8586 | 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", |
| 8587 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8588 | err_code |= ERR_WARN; |
| 8589 | } |
| 8590 | |
| 8591 | |
| 8592 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
| 8593 | 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", |
| 8594 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8595 | err_code |= ERR_WARN; |
| 8596 | } |
| 8597 | } |
| 8598 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8599 | newsrv = newsrv->next; |
| 8600 | } |
| 8601 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8602 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8603 | * with no inspect-delay |
| 8604 | */ |
| 8605 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8606 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8607 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8608 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8609 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8610 | if ((trule->action >= ACT_ACTION_TRK_SC0 && trule->action <= ACT_ACTION_TRK_SCMAX) && |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8611 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8612 | break; |
| 8613 | } |
| 8614 | |
| 8615 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8616 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8617 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8618 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8619 | " setting the tcp-request inspect-delay.\n", |
| 8620 | proxy_type_str(curproxy), curproxy->id); |
| 8621 | err_code |= ERR_WARN; |
| 8622 | } |
| 8623 | } |
| 8624 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8625 | /* Check filter configuration, if any */ |
| 8626 | cfgerr += flt_check(curproxy); |
| 8627 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8628 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8629 | if (!curproxy->accept) |
| 8630 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8631 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8632 | if (curproxy->tcp_req.inspect_delay || |
| 8633 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8634 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8635 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8636 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8637 | 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] | 8638 | 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] | 8639 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8640 | |
| 8641 | /* both TCP and HTTP must check switching rules */ |
| 8642 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8643 | |
| 8644 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8645 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8646 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8647 | 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] | 8648 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8649 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8650 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8651 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8652 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8653 | } |
| 8654 | |
| 8655 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8656 | if (curproxy->tcp_req.inspect_delay || |
| 8657 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8658 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8659 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8660 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8661 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8662 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8663 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8664 | 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] | 8665 | 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] | 8666 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8667 | |
| 8668 | /* If the backend does requires RDP cookie persistence, we have to |
| 8669 | * enable the corresponding analyser. |
| 8670 | */ |
| 8671 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8672 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8673 | |
| 8674 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8675 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8676 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8677 | 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] | 8678 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8679 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8680 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8681 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8682 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8683 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8684 | } |
| 8685 | |
| 8686 | /***********************************************************/ |
| 8687 | /* At this point, target names have already been resolved. */ |
| 8688 | /***********************************************************/ |
| 8689 | |
| 8690 | /* Check multi-process mode compatibility */ |
| 8691 | |
| 8692 | if (global.nbproc > 1 && global.stats_fe) { |
| 8693 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8694 | unsigned long mask; |
| 8695 | |
| 8696 | mask = nbits(global.nbproc); |
| 8697 | if (global.stats_fe->bind_proc) |
| 8698 | mask &= global.stats_fe->bind_proc; |
| 8699 | |
| 8700 | if (bind_conf->bind_proc) |
| 8701 | mask &= bind_conf->bind_proc; |
| 8702 | |
| 8703 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8704 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8705 | break; |
| 8706 | } |
| 8707 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8708 | 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"); |
| 8709 | } |
| 8710 | } |
| 8711 | |
| 8712 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8713 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8714 | if (curproxy->bind_proc) |
| 8715 | continue; |
| 8716 | |
| 8717 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8718 | unsigned long mask; |
| 8719 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8720 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8721 | curproxy->bind_proc |= mask; |
| 8722 | } |
| 8723 | |
| 8724 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8725 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8726 | } |
| 8727 | |
| 8728 | if (global.stats_fe) { |
| 8729 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8730 | unsigned long mask; |
| 8731 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8732 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8733 | global.stats_fe->bind_proc |= mask; |
| 8734 | } |
| 8735 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8736 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8737 | } |
| 8738 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8739 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8740 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8741 | */ |
| 8742 | if (!cfgerr) { |
| 8743 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8744 | if (curproxy->cap & PR_CAP_FE) |
| 8745 | propagate_processes(curproxy, NULL); |
| 8746 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8747 | } |
| 8748 | |
| 8749 | /* Bind each unbound backend to all processes when not specified. */ |
| 8750 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8751 | if (curproxy->bind_proc) |
| 8752 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8753 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8754 | } |
| 8755 | |
| 8756 | /*******************************************************/ |
| 8757 | /* At this step, all proxies have a non-null bind_proc */ |
| 8758 | /*******************************************************/ |
| 8759 | |
| 8760 | /* perform the final checks before creating tasks */ |
| 8761 | |
| 8762 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8763 | struct listener *listener; |
| 8764 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8765 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8766 | /* Configure SSL for each bind line. |
| 8767 | * Note: if configuration fails at some point, the ->ctx member |
| 8768 | * remains NULL so that listeners can later detach. |
| 8769 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8770 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8771 | if (bind_conf->xprt->prepare_bind_conf && |
| 8772 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8773 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8774 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8775 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8776 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8777 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8778 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8779 | int nbproc; |
| 8780 | |
| 8781 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8782 | (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] | 8783 | nbits(global.nbproc)); |
| 8784 | |
| 8785 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8786 | nbproc = 1; |
| 8787 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8788 | if (!listener->luid) { |
| 8789 | /* listener ID not set, use automatic numbering with first |
| 8790 | * spare entry starting with next_luid. |
| 8791 | */ |
| 8792 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8793 | listener->conf.id.key = listener->luid = next_id; |
| 8794 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8795 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8796 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8797 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8798 | /* enable separate counters */ |
| 8799 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8800 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8801 | if (!listener->name) |
| 8802 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8803 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8804 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8805 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8806 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8807 | if (!listener->maxconn) |
| 8808 | listener->maxconn = curproxy->maxconn; |
| 8809 | if (!listener->backlog) |
| 8810 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8811 | if (!listener->maxaccept) |
| 8812 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8813 | |
| 8814 | /* we want to have an optimal behaviour on single process mode to |
| 8815 | * maximize the work at once, but in multi-process we want to keep |
| 8816 | * some fairness between processes, so we target half of the max |
| 8817 | * number of events to be balanced over all the processes the proxy |
| 8818 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8819 | * used to disable the limit. |
| 8820 | */ |
| 8821 | if (listener->maxaccept > 0) { |
| 8822 | if (nbproc > 1) |
| 8823 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8824 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8825 | } |
| 8826 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8827 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8828 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8829 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8830 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8831 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8832 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8833 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8834 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8835 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8836 | listener->options |= LI_O_TCP_L5_RULES; |
| 8837 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8838 | if (curproxy->mon_mask.s_addr) |
| 8839 | listener->options |= LI_O_CHK_MONNET; |
| 8840 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8841 | /* smart accept mode is automatic in HTTP mode */ |
| 8842 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8843 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8844 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8845 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8846 | } |
| 8847 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8848 | /* Release unused SSL configs */ |
| 8849 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 8850 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 8851 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8852 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8853 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8854 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8855 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8856 | int count, maxproc = 0; |
| 8857 | |
| 8858 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8859 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8860 | if (count > maxproc) |
| 8861 | maxproc = count; |
| 8862 | } |
| 8863 | /* backends have 0, frontends have 1 or more */ |
| 8864 | if (maxproc != 1) |
| 8865 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 8866 | " limited to process assigned to the current request.\n", |
| 8867 | curproxy->id); |
| 8868 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8869 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 8870 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8871 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8872 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8873 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8874 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 8875 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8876 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8877 | } |
| 8878 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8879 | |
| 8880 | /* create the task associated with the proxy */ |
| 8881 | curproxy->task = task_new(); |
| 8882 | if (curproxy->task) { |
| 8883 | curproxy->task->context = curproxy; |
| 8884 | curproxy->task->process = manage_proxy; |
| 8885 | /* no need to queue, it will be done automatically if some |
| 8886 | * listener gets limited. |
| 8887 | */ |
| 8888 | curproxy->task->expire = TICK_ETERNITY; |
| 8889 | } else { |
| 8890 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8891 | curproxy->id); |
| 8892 | cfgerr++; |
| 8893 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8894 | } |
| 8895 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8896 | /* automatically compute fullconn if not set. We must not do it in the |
| 8897 | * loop above because cross-references are not yet fully resolved. |
| 8898 | */ |
| 8899 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8900 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 8901 | * the possible incoming frontend's maxconns. |
| 8902 | */ |
| 8903 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8904 | /* we have the sum of the maxconns in <total>. We only |
| 8905 | * keep 10% of that sum to set the default fullconn, with |
| 8906 | * a hard minimum of 1 (to avoid a divide by zero). |
| 8907 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 8908 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8909 | if (!curproxy->fullconn) |
| 8910 | curproxy->fullconn = 1; |
| 8911 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 8912 | } |
| 8913 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8914 | /* |
| 8915 | * Recount currently required checks. |
| 8916 | */ |
| 8917 | |
| 8918 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 8919 | int optnum; |
| 8920 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8921 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 8922 | if (curproxy->options & cfg_opts[optnum].val) |
| 8923 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8924 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8925 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 8926 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 8927 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8928 | } |
| 8929 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 8930 | /* compute the required process bindings for the peers */ |
| 8931 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 8932 | if (curproxy->table.peers.p) |
| 8933 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 8934 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8935 | if (peers) { |
| 8936 | struct peers *curpeers = peers, **last; |
| 8937 | struct peer *p, *pb; |
| 8938 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8939 | /* Remove all peers sections which don't have a valid listener, |
| 8940 | * which are not used by any table, or which are bound to more |
| 8941 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8942 | */ |
| 8943 | last = &peers; |
| 8944 | while (*last) { |
| 8945 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8946 | |
| 8947 | if (curpeers->state == PR_STSTOPPED) { |
| 8948 | /* the "disabled" keyword was present */ |
| 8949 | if (curpeers->peers_fe) |
| 8950 | stop_proxy(curpeers->peers_fe); |
| 8951 | curpeers->peers_fe = NULL; |
| 8952 | } |
| 8953 | else if (!curpeers->peers_fe) { |
| 8954 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 8955 | curpeers->id, localpeer); |
| 8956 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8957 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8958 | /* either it's totally stopped or too much used */ |
| 8959 | if (curpeers->peers_fe->bind_proc) { |
| 8960 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 8961 | "running in different processes (%d different ones). " |
| 8962 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8963 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8964 | cfgerr++; |
| 8965 | } |
| 8966 | stop_proxy(curpeers->peers_fe); |
| 8967 | curpeers->peers_fe = NULL; |
| 8968 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8969 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 8970 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8971 | last = &curpeers->next; |
| 8972 | continue; |
| 8973 | } |
| 8974 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8975 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8976 | p = curpeers->remote; |
| 8977 | while (p) { |
| 8978 | pb = p->next; |
| 8979 | free(p->id); |
| 8980 | free(p); |
| 8981 | p = pb; |
| 8982 | } |
| 8983 | |
| 8984 | /* Destroy and unlink this curpeers section. |
| 8985 | * Note: curpeers is backed up into *last. |
| 8986 | */ |
| 8987 | free(curpeers->id); |
| 8988 | curpeers = curpeers->next; |
| 8989 | free(*last); |
| 8990 | *last = curpeers; |
| 8991 | } |
| 8992 | } |
| 8993 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 8994 | /* initialize stick-tables on backend capable proxies. This must not |
| 8995 | * be done earlier because the data size may be discovered while parsing |
| 8996 | * other proxies. |
| 8997 | */ |
| 8998 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8999 | if (curproxy->state == PR_STSTOPPED) |
| 9000 | continue; |
| 9001 | |
| 9002 | if (!stktable_init(&curproxy->table)) { |
| 9003 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9004 | cfgerr++; |
| 9005 | } |
| 9006 | } |
| 9007 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9008 | if (mailers) { |
| 9009 | struct mailers *curmailers = mailers, **last; |
| 9010 | struct mailer *m, *mb; |
| 9011 | |
| 9012 | /* Remove all mailers sections which don't have a valid listener. |
| 9013 | * This can happen when a mailers section is never referenced. |
| 9014 | */ |
| 9015 | last = &mailers; |
| 9016 | while (*last) { |
| 9017 | curmailers = *last; |
| 9018 | if (curmailers->users) { |
| 9019 | last = &curmailers->next; |
| 9020 | continue; |
| 9021 | } |
| 9022 | |
| 9023 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9024 | curmailers->id); |
| 9025 | |
| 9026 | m = curmailers->mailer_list; |
| 9027 | while (m) { |
| 9028 | mb = m->next; |
| 9029 | free(m->id); |
| 9030 | free(m); |
| 9031 | m = mb; |
| 9032 | } |
| 9033 | |
| 9034 | /* Destroy and unlink this curmailers section. |
| 9035 | * Note: curmailers is backed up into *last. |
| 9036 | */ |
| 9037 | free(curmailers->id); |
| 9038 | curmailers = curmailers->next; |
| 9039 | free(*last); |
| 9040 | *last = curmailers; |
| 9041 | } |
| 9042 | } |
| 9043 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9044 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9045 | * a server-state file locally defined and none has been provided */ |
| 9046 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9047 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9048 | curproxy->server_state_file_name == NULL) |
| 9049 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9050 | } |
| 9051 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9052 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9053 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9054 | MEM_F_SHARED); |
| 9055 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9056 | if (cfgerr > 0) |
| 9057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9058 | out: |
| 9059 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9060 | } |
| 9061 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9062 | /* |
| 9063 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9064 | * parsing sessions. |
| 9065 | */ |
| 9066 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9067 | { |
| 9068 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9069 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9070 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9071 | /* |
| 9072 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9073 | */ |
| 9074 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9075 | { |
| 9076 | LIST_DEL(&kwl->list); |
| 9077 | LIST_INIT(&kwl->list); |
| 9078 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9079 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9080 | /* this function register new section in the haproxy configuration file. |
| 9081 | * <section_name> is the name of this new section and <section_parser> |
| 9082 | * is the called parser. If two section declaration have the same name, |
| 9083 | * only the first declared is used. |
| 9084 | */ |
| 9085 | int cfg_register_section(char *section_name, |
| 9086 | int (*section_parser)(const char *, int, char **, int)) |
| 9087 | { |
| 9088 | struct cfg_section *cs; |
| 9089 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9090 | list_for_each_entry(cs, §ions, list) { |
| 9091 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9092 | Alert("register section '%s': already registered.\n", section_name); |
| 9093 | return 0; |
| 9094 | } |
| 9095 | } |
| 9096 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9097 | cs = calloc(1, sizeof(*cs)); |
| 9098 | if (!cs) { |
| 9099 | Alert("register section '%s': out of memory.\n", section_name); |
| 9100 | return 0; |
| 9101 | } |
| 9102 | |
| 9103 | cs->section_name = section_name; |
| 9104 | cs->section_parser = section_parser; |
| 9105 | |
| 9106 | LIST_ADDQ(§ions, &cs->list); |
| 9107 | |
| 9108 | return 1; |
| 9109 | } |
| 9110 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9111 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9112 | * free all config section entries |
| 9113 | */ |
| 9114 | void cfg_unregister_sections(void) |
| 9115 | { |
| 9116 | struct cfg_section *cs, *ics; |
| 9117 | |
| 9118 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9119 | LIST_DEL(&cs->list); |
| 9120 | free(cs); |
| 9121 | } |
| 9122 | } |
| 9123 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9124 | void cfg_backup_sections(struct list *backup_sections) |
| 9125 | { |
| 9126 | struct cfg_section *cs, *ics; |
| 9127 | |
| 9128 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9129 | LIST_DEL(&cs->list); |
| 9130 | LIST_ADDQ(backup_sections, &cs->list); |
| 9131 | } |
| 9132 | } |
| 9133 | |
| 9134 | void cfg_restore_sections(struct list *backup_sections) |
| 9135 | { |
| 9136 | struct cfg_section *cs, *ics; |
| 9137 | |
| 9138 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9139 | LIST_DEL(&cs->list); |
| 9140 | LIST_ADDQ(§ions, &cs->list); |
| 9141 | } |
| 9142 | } |
| 9143 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9144 | __attribute__((constructor)) |
| 9145 | static void cfgparse_init(void) |
| 9146 | { |
| 9147 | /* Register internal sections */ |
| 9148 | cfg_register_section("listen", cfg_parse_listen); |
| 9149 | cfg_register_section("frontend", cfg_parse_listen); |
| 9150 | cfg_register_section("backend", cfg_parse_listen); |
| 9151 | cfg_register_section("defaults", cfg_parse_listen); |
| 9152 | cfg_register_section("global", cfg_parse_global); |
| 9153 | cfg_register_section("userlist", cfg_parse_users); |
| 9154 | cfg_register_section("peers", cfg_parse_peers); |
| 9155 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9156 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9157 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9158 | } |
| 9159 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9160 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9161 | * Local variables: |
| 9162 | * c-indent-level: 8 |
| 9163 | * c-basic-offset: 8 |
| 9164 | * End: |
| 9165 | */ |