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> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 83 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 85 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 86 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 87 | #ifdef USE_OPENSSL |
| 88 | #include <types/ssl_sock.h> |
| 89 | #include <proto/ssl_sock.h> |
| 90 | #include <proto/shctx.h> |
| 91 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 93 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 94 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 95 | * |
| 96 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 97 | */ |
| 98 | const char sslv3_client_hello_pkt[] = { |
| 99 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 100 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 101 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 102 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 103 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 104 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 105 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 106 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 107 | "\x00" /* Session ID length : empty (no session ID) */ |
| 108 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 109 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 110 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 111 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 112 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 113 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 114 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 115 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 116 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 117 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 118 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 119 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 120 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 121 | }; |
| 122 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 123 | /* various keyword modifiers */ |
| 124 | enum kw_mod { |
| 125 | KWM_STD = 0, /* normal */ |
| 126 | KWM_NO, /* "no" prefixed before the keyword */ |
| 127 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 128 | }; |
| 129 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 130 | /* permit to store configuration section */ |
| 131 | struct cfg_section { |
| 132 | struct list list; |
| 133 | char *section_name; |
| 134 | int (*section_parser)(const char *, int, char **, int); |
| 135 | }; |
| 136 | |
| 137 | /* Used to chain configuration sections definitions. This list |
| 138 | * stores struct cfg_section |
| 139 | */ |
| 140 | struct list sections = LIST_HEAD_INIT(sections); |
| 141 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 142 | /* 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] | 143 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 144 | const char *name; |
| 145 | unsigned int val; |
| 146 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 147 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 148 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /* proxy->options */ |
| 152 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 153 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 154 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 155 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 156 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 157 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 158 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 159 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 160 | { "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] | 161 | { "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] | 162 | { "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] | 163 | { "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] | 164 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 165 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 166 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 167 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 168 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 169 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 170 | #else |
| 171 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 172 | #endif |
| 173 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 174 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 175 | }; |
| 176 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 177 | /* proxy->options2 */ |
| 178 | static const struct cfg_opt cfg_opts2[] = |
| 179 | { |
| 180 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 181 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 182 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 183 | { "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] | 184 | #else |
| 185 | { "splice-request", 0, 0, 0, 0 }, |
| 186 | { "splice-response", 0, 0, 0, 0 }, |
| 187 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 188 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 189 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 190 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 191 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 192 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 193 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 194 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 195 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 196 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 197 | { "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] | 198 | { "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] | 199 | { "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] | 200 | { "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] | 201 | { "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] | 202 | { NULL, 0, 0, 0 } |
| 203 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 204 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 205 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 206 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 207 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 208 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 209 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 210 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 211 | /* List head of all known configuration keywords */ |
| 212 | static struct cfg_kw_list cfg_keywords = { |
| 213 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 214 | }; |
| 215 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | /* |
| 217 | * converts <str> to a list of listeners which are dynamically allocated. |
| 218 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 219 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 220 | * - <port> is a numerical port from 1 to 65535 ; |
| 221 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 222 | * 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] | 223 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 224 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 225 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 227 | 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] | 228 | { |
| 229 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 230 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 231 | int port, end; |
| 232 | |
| 233 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 234 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 235 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 236 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 237 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | |
| 239 | str = next; |
| 240 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 241 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 242 | *next++ = 0; |
| 243 | } |
| 244 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 245 | ss2 = str2sa_range(str, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 246 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 247 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 248 | if (!ss2) |
| 249 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 250 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 251 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 252 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 253 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 254 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 255 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 256 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 257 | if (!port || !end) { |
| 258 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 259 | goto fail; |
| 260 | } |
| 261 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 262 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 263 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 264 | goto fail; |
| 265 | } |
| 266 | |
| 267 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 268 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 269 | goto fail; |
| 270 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 271 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 272 | else if (ss2->ss_family == AF_UNSPEC) { |
| 273 | socklen_t addr_len; |
| 274 | |
| 275 | /* We want to attach to an already bound fd whose number |
| 276 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 277 | * Note that by definition there is a single listener. |
| 278 | * We still have to determine the address family to |
| 279 | * register the correct protocol. |
| 280 | */ |
| 281 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 282 | addr_len = sizeof(*ss2); |
| 283 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 284 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 285 | goto fail; |
| 286 | } |
| 287 | |
| 288 | port = end = get_host_port(ss2); |
| 289 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 290 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 291 | /* OK the address looks correct */ |
Vincent Bernat | 6e61589 | 2016-05-18 16:17:44 +0200 | [diff] [blame] | 292 | memcpy(&ss, ss2, sizeof(ss)); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 293 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 294 | for (; port <= end; port++) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 295 | l = calloc(1, sizeof(*l)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 296 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 297 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 298 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 299 | l->frontend = curproxy; |
| 300 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 301 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 302 | l->fd = fd; |
Vincent Bernat | 6e46ff1 | 2016-05-19 11:29:43 +0200 | [diff] [blame] | 303 | memcpy(&l->addr, &ss, sizeof(ss)); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 304 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 305 | l->state = LI_INIT; |
| 306 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 307 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 308 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 309 | tcpv4_add_listener(l); |
| 310 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 311 | else if (ss.ss_family == AF_INET6) { |
| 312 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 313 | tcpv6_add_listener(l); |
| 314 | } |
| 315 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 316 | uxst_add_listener(l); |
| 317 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 318 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 319 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 320 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 321 | } /* end for(port) */ |
| 322 | } /* end while(next) */ |
| 323 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 324 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 325 | fail: |
| 326 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 327 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 328 | } |
| 329 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 330 | /* |
| 331 | * Report a fatal Alert when there is too much arguments |
| 332 | * The index is the current keyword in args |
| 333 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 334 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 335 | */ |
| 336 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 337 | { |
| 338 | char *kw = NULL; |
| 339 | int i; |
| 340 | |
| 341 | if (!*args[index + maxarg + 1]) |
| 342 | return 0; |
| 343 | |
| 344 | memprintf(&kw, "%s", args[0]); |
| 345 | for (i = 1; i <= index; i++) { |
| 346 | memprintf(&kw, "%s %s", kw, args[i]); |
| 347 | } |
| 348 | |
| 349 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 350 | free(kw); |
| 351 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 352 | return 1; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * same as alertif_too_many_args_idx with a 0 index |
| 357 | */ |
| 358 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 359 | { |
| 360 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 361 | } |
| 362 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 363 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 364 | * Return 1 if the warning has been emitted, otherwise 0. |
| 365 | */ |
| 366 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 367 | { |
| 368 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 369 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 370 | file, line, arg); |
| 371 | return 1; |
| 372 | } |
| 373 | return 0; |
| 374 | } |
| 375 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 376 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 377 | * Return 1 if the warning has been emitted, otherwise 0. |
| 378 | */ |
| 379 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 380 | { |
| 381 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 382 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 383 | file, line, arg); |
| 384 | return 1; |
| 385 | } |
| 386 | return 0; |
| 387 | } |
| 388 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 389 | /* Report a warning if a rule is placed after a 'block' rule. |
| 390 | * Return 1 if the warning has been emitted, otherwise 0. |
| 391 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 392 | 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] | 393 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 394 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 395 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 396 | file, line, arg); |
| 397 | return 1; |
| 398 | } |
| 399 | return 0; |
| 400 | } |
| 401 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 402 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 403 | * Return 1 if the warning has been emitted, otherwise 0. |
| 404 | */ |
| 405 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 406 | { |
| 407 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 408 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 409 | file, line, arg); |
| 410 | return 1; |
| 411 | } |
| 412 | return 0; |
| 413 | } |
| 414 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 415 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 416 | * Return 1 if the warning has been emitted, otherwise 0. |
| 417 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 418 | 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] | 419 | { |
| 420 | if (proxy->req_exp) { |
| 421 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 422 | file, line, arg); |
| 423 | return 1; |
| 424 | } |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /* Report a warning if a rule is placed after a reqadd rule. |
| 429 | * Return 1 if the warning has been emitted, otherwise 0. |
| 430 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 431 | 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] | 432 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 433 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 434 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 435 | file, line, arg); |
| 436 | return 1; |
| 437 | } |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | /* Report a warning if a rule is placed after a redirect rule. |
| 442 | * Return 1 if the warning has been emitted, otherwise 0. |
| 443 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 444 | 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] | 445 | { |
| 446 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 447 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 448 | file, line, arg); |
| 449 | return 1; |
| 450 | } |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 455 | * Return 1 if the warning has been emitted, otherwise 0. |
| 456 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 457 | 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] | 458 | { |
| 459 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 460 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 461 | file, line, arg); |
| 462 | return 1; |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 467 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 468 | * Return 1 if the warning has been emitted, otherwise 0. |
| 469 | */ |
| 470 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 471 | { |
| 472 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 473 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 474 | file, line, arg); |
| 475 | return 1; |
| 476 | } |
| 477 | return 0; |
| 478 | } |
| 479 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 480 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 481 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 482 | { |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 483 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 484 | warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 485 | warnif_rule_after_block(proxy, file, line, arg) || |
| 486 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 487 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 488 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 489 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 490 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 491 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 492 | } |
| 493 | |
| 494 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 495 | { |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 496 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 497 | warnif_rule_after_block(proxy, file, line, arg) || |
| 498 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 499 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 500 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 501 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 502 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 503 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 504 | } |
| 505 | |
| 506 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 507 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 508 | { |
| 509 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 510 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 511 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 512 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 513 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 514 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 515 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 516 | } |
| 517 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 518 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 519 | 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] | 520 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 521 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 522 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 523 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 524 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 525 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 526 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /* report a warning if an http-request rule is dangerously placed */ |
| 530 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 531 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 532 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 533 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 534 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 535 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 536 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 540 | 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] | 541 | { |
| 542 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 543 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 544 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 545 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 549 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 550 | { |
| 551 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 552 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 553 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 554 | } |
| 555 | |
| 556 | /* report a warning if a redirect rule is dangerously placed */ |
| 557 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 558 | { |
| 559 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 560 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 563 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 564 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 565 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 566 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 567 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 568 | 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] | 569 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 570 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 571 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 572 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 573 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 574 | return 0; |
| 575 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 576 | acl = acl_cond_conflicts(cond, where); |
| 577 | if (acl) { |
| 578 | if (acl->name && *acl->name) |
| 579 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 580 | file, line, acl->name, sample_ckp_names(where)); |
| 581 | else |
| 582 | 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] | 583 | 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] | 584 | return ERR_WARN; |
| 585 | } |
| 586 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 587 | return 0; |
| 588 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 589 | if (acl->name && *acl->name) |
| 590 | 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] | 591 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 592 | else |
| 593 | 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] | 594 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 595 | return ERR_WARN; |
| 596 | } |
| 597 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 598 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 599 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 600 | * any combination of : |
| 601 | * - ERR_ABORT: must abort ASAP |
| 602 | * - ERR_FATAL: we can continue parsing but not start the service |
| 603 | * - ERR_WARN: a warning has been emitted |
| 604 | * - ERR_ALERT: an alert has been emitted |
| 605 | * Only the two first ones can stop processing, the two others are just |
| 606 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 607 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 608 | 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] | 609 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 610 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 611 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 612 | |
| 613 | if (!strcmp(args[0], "global")) { /* new section */ |
| 614 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 615 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 616 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 617 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 618 | else if (!strcmp(args[0], "ca-base")) { |
| 619 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 620 | if(alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 621 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 622 | if (global.ca_base != NULL) { |
| 623 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 624 | err_code |= ERR_ALERT; |
| 625 | goto out; |
| 626 | } |
| 627 | if (*(args[1]) == 0) { |
| 628 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 630 | goto out; |
| 631 | } |
| 632 | global.ca_base = strdup(args[1]); |
| 633 | #else |
| 634 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 636 | goto out; |
| 637 | #endif |
| 638 | } |
| 639 | else if (!strcmp(args[0], "crt-base")) { |
| 640 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 641 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 642 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 643 | if (global.crt_base != NULL) { |
| 644 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 645 | err_code |= ERR_ALERT; |
| 646 | goto out; |
| 647 | } |
| 648 | if (*(args[1]) == 0) { |
| 649 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 651 | goto out; |
| 652 | } |
| 653 | global.crt_base = strdup(args[1]); |
| 654 | #else |
| 655 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 657 | goto out; |
| 658 | #endif |
| 659 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 660 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 661 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 662 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 663 | global.mode |= MODE_DAEMON; |
| 664 | } |
| 665 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 666 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 667 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 668 | global.mode |= MODE_DEBUG; |
| 669 | } |
| 670 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 671 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 672 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 673 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 674 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 675 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 676 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 677 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 678 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 679 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 680 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 681 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 682 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 683 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 684 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 685 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 686 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 687 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 688 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 689 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 690 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 691 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 692 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 693 | global.tune.options &= ~GTUNE_USE_GAI; |
| 694 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 695 | else if (!strcmp(args[0], "noreuseport")) { |
| 696 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 697 | goto out; |
| 698 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 699 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 700 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 701 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 702 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 703 | global.mode |= MODE_QUIET; |
| 704 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 705 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 706 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 707 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 708 | if (global.tune.maxpollevents != 0) { |
| 709 | 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] | 710 | err_code |= ERR_ALERT; |
| 711 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 712 | } |
| 713 | if (*(args[1]) == 0) { |
| 714 | 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] | 715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 716 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 717 | } |
| 718 | global.tune.maxpollevents = atol(args[1]); |
| 719 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 720 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 721 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 722 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 723 | if (global.tune.maxaccept != 0) { |
| 724 | 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] | 725 | err_code |= ERR_ALERT; |
| 726 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 727 | } |
| 728 | if (*(args[1]) == 0) { |
| 729 | 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] | 730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 731 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 732 | } |
| 733 | global.tune.maxaccept = atol(args[1]); |
| 734 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 735 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 736 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 737 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 738 | if (*(args[1]) == 0) { |
| 739 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | global.tune.chksize = atol(args[1]); |
| 744 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 745 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 746 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 747 | goto out; |
| 748 | if (*(args[1]) == 0) { |
| 749 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 751 | goto out; |
| 752 | } |
| 753 | global.tune.recv_enough = atol(args[1]); |
| 754 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 755 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 756 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 757 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 758 | goto out; |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 759 | global.tune.sslprivatecache = 1; |
| 760 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 761 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 762 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 763 | goto out; |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 764 | if (*(args[1]) == 0) { |
| 765 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 767 | goto out; |
| 768 | } |
| 769 | global.tune.sslcachesize = atol(args[1]); |
| 770 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 771 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 772 | unsigned int ssllifetime; |
| 773 | const char *res; |
| 774 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 775 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 776 | goto out; |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 777 | if (*(args[1]) == 0) { |
| 778 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 780 | goto out; |
| 781 | } |
| 782 | |
| 783 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 784 | if (res) { |
| 785 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 786 | file, linenum, *res, args[0]); |
| 787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 788 | goto out; |
| 789 | } |
| 790 | |
| 791 | global.tune.ssllifetime = ssllifetime; |
| 792 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 793 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 794 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 795 | goto out; |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 796 | if (*(args[1]) == 0) { |
| 797 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 799 | goto out; |
| 800 | } |
| 801 | global.tune.ssl_max_record = atol(args[1]); |
| 802 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 803 | #ifndef OPENSSL_NO_DH |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 804 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 805 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 806 | goto out; |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 807 | if (*(args[1]) == 0) { |
| 808 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 810 | goto out; |
| 811 | } |
| 812 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 813 | if (global.tune.ssl_default_dh_param < 1024) { |
| 814 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 816 | goto out; |
| 817 | } |
| 818 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 819 | #endif |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 820 | else if (!strcmp(args[0], "tune.ssl.ssl-ctx-cache-size")) { |
| 821 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 822 | goto out; |
| 823 | if (*(args[1]) == 0) { |
| 824 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 826 | goto out; |
| 827 | } |
| 828 | global.tune.ssl_ctx_cache = atoi(args[1]); |
| 829 | if (global.tune.ssl_ctx_cache < 0) { |
| 830 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 831 | file, linenum, args[0]); |
| 832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 833 | goto out; |
| 834 | } |
| 835 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 836 | #endif |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 837 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 838 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 839 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 840 | if (*(args[1]) == 0) { |
| 841 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 843 | goto out; |
| 844 | } |
| 845 | global.tune.buf_limit = atol(args[1]); |
| 846 | if (global.tune.buf_limit) { |
| 847 | if (global.tune.buf_limit < 3) |
| 848 | global.tune.buf_limit = 3; |
| 849 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 850 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 851 | } |
| 852 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 853 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 854 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 855 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 856 | if (*(args[1]) == 0) { |
| 857 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 859 | goto out; |
| 860 | } |
| 861 | global.tune.reserved_bufs = atol(args[1]); |
| 862 | if (global.tune.reserved_bufs < 2) |
| 863 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 864 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 865 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 866 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 867 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 868 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 869 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 870 | if (*(args[1]) == 0) { |
| 871 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 873 | goto out; |
| 874 | } |
| 875 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 876 | if (global.tune.bufsize <= 0) { |
| 877 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 879 | goto out; |
| 880 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 881 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 882 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 883 | } |
| 884 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 885 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 886 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 887 | if (*(args[1]) == 0) { |
| 888 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 890 | goto out; |
| 891 | } |
| 892 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 893 | if (global.tune.maxrewrite < 0) { |
| 894 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 896 | goto out; |
| 897 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 898 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 899 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 900 | unsigned int idle; |
| 901 | const char *res; |
| 902 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 903 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 904 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 905 | if (*(args[1]) == 0) { |
| 906 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 908 | goto out; |
| 909 | } |
| 910 | |
| 911 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 912 | if (res) { |
| 913 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 914 | file, linenum, *res, args[0]); |
| 915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 916 | goto out; |
| 917 | } |
| 918 | |
| 919 | if (idle > 65535) { |
| 920 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 922 | goto out; |
| 923 | } |
| 924 | global.tune.idle_timer = idle; |
| 925 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 926 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 927 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 928 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 929 | if (global.tune.client_rcvbuf != 0) { |
| 930 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 931 | err_code |= ERR_ALERT; |
| 932 | goto out; |
| 933 | } |
| 934 | if (*(args[1]) == 0) { |
| 935 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
| 939 | global.tune.client_rcvbuf = atol(args[1]); |
| 940 | } |
| 941 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 942 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 943 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 944 | if (global.tune.server_rcvbuf != 0) { |
| 945 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 946 | err_code |= ERR_ALERT; |
| 947 | goto out; |
| 948 | } |
| 949 | if (*(args[1]) == 0) { |
| 950 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 952 | goto out; |
| 953 | } |
| 954 | global.tune.server_rcvbuf = atol(args[1]); |
| 955 | } |
| 956 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 957 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 958 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 959 | if (global.tune.client_sndbuf != 0) { |
| 960 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 961 | err_code |= ERR_ALERT; |
| 962 | goto out; |
| 963 | } |
| 964 | if (*(args[1]) == 0) { |
| 965 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 967 | goto out; |
| 968 | } |
| 969 | global.tune.client_sndbuf = atol(args[1]); |
| 970 | } |
| 971 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 972 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 973 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 974 | if (global.tune.server_sndbuf != 0) { |
| 975 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 976 | err_code |= ERR_ALERT; |
| 977 | goto out; |
| 978 | } |
| 979 | if (*(args[1]) == 0) { |
| 980 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 982 | goto out; |
| 983 | } |
| 984 | global.tune.server_sndbuf = atol(args[1]); |
| 985 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 986 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 987 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 988 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 989 | if (*(args[1]) == 0) { |
| 990 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 992 | goto out; |
| 993 | } |
| 994 | global.tune.pipesize = atol(args[1]); |
| 995 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 996 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 997 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 998 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 999 | if (*(args[1]) == 0) { |
| 1000 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1005 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1006 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1007 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1008 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1009 | if (*(args[1]) == 0) { |
| 1010 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | global.tune.max_http_hdr = atol(args[1]); |
| 1015 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1016 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 1017 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1018 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1019 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1020 | if (*args[1]) { |
| 1021 | global.tune.zlibmemlevel = atoi(args[1]); |
| 1022 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 1023 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1024 | file, linenum, args[0]); |
| 1025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1026 | goto out; |
| 1027 | } |
| 1028 | } else { |
| 1029 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1030 | file, linenum, args[0]); |
| 1031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1032 | goto out; |
| 1033 | } |
| 1034 | #else |
| 1035 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1037 | goto out; |
| 1038 | #endif |
| 1039 | } |
| 1040 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 1041 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1042 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1043 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1044 | if (*args[1]) { |
| 1045 | global.tune.zlibwindowsize = atoi(args[1]); |
| 1046 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 1047 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1048 | file, linenum, args[0]); |
| 1049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1050 | goto out; |
| 1051 | } |
| 1052 | } else { |
| 1053 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1054 | file, linenum, args[0]); |
| 1055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1056 | goto out; |
| 1057 | } |
| 1058 | #else |
| 1059 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1061 | goto out; |
| 1062 | #endif |
| 1063 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1064 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1065 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1066 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1067 | if (*args[1]) { |
| 1068 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1069 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 1070 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1071 | file, linenum, args[0]); |
| 1072 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1073 | goto out; |
| 1074 | } |
| 1075 | } else { |
| 1076 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1077 | file, linenum, args[0]); |
| 1078 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1079 | goto out; |
| 1080 | } |
| 1081 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1082 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1083 | if (*args[1]) { |
| 1084 | global.tune.pattern_cache = atoi(args[1]); |
| 1085 | if (global.tune.pattern_cache < 0) { |
| 1086 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1087 | file, linenum, args[0]); |
| 1088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1089 | goto out; |
| 1090 | } |
| 1091 | } else { |
| 1092 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1093 | file, linenum, args[0]); |
| 1094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1095 | goto out; |
| 1096 | } |
| 1097 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1098 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1099 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1100 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1101 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1102 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1103 | err_code |= ERR_ALERT; |
| 1104 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1105 | } |
| 1106 | if (*(args[1]) == 0) { |
| 1107 | 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] | 1108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1109 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1110 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1111 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 1112 | 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]); |
| 1113 | err_code |= ERR_WARN; |
| 1114 | goto out; |
| 1115 | } |
| 1116 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1117 | } |
| 1118 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1119 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1120 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1121 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1122 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1123 | err_code |= ERR_ALERT; |
| 1124 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1125 | } |
| 1126 | if (*(args[1]) == 0) { |
| 1127 | 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] | 1128 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1129 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1130 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1131 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 1132 | 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]); |
| 1133 | err_code |= ERR_WARN; |
| 1134 | goto out; |
| 1135 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1136 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1137 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1138 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1139 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1140 | global.external_check = 1; |
| 1141 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1142 | /* user/group name handling */ |
| 1143 | else if (!strcmp(args[0], "user")) { |
| 1144 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1145 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1146 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1147 | if (global.uid != 0) { |
| 1148 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1149 | err_code |= ERR_ALERT; |
| 1150 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1151 | } |
| 1152 | errno = 0; |
| 1153 | ha_user = getpwnam(args[1]); |
| 1154 | if (ha_user != NULL) { |
| 1155 | global.uid = (int)ha_user->pw_uid; |
| 1156 | } |
| 1157 | else { |
| 1158 | 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] | 1159 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | else if (!strcmp(args[0], "group")) { |
| 1163 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1164 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1165 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1166 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1167 | 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] | 1168 | err_code |= ERR_ALERT; |
| 1169 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1170 | } |
| 1171 | errno = 0; |
| 1172 | ha_group = getgrnam(args[1]); |
| 1173 | if (ha_group != NULL) { |
| 1174 | global.gid = (int)ha_group->gr_gid; |
| 1175 | } |
| 1176 | else { |
| 1177 | 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] | 1178 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1182 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1183 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1184 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1185 | if (*(args[1]) == 0) { |
| 1186 | 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] | 1187 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1188 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1189 | } |
| 1190 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1191 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1192 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1193 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1194 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1195 | goto out; |
| 1196 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1197 | } |
| 1198 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1199 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1200 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1201 | if (global.maxconn != 0) { |
| 1202 | 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] | 1203 | err_code |= ERR_ALERT; |
| 1204 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1205 | } |
| 1206 | if (*(args[1]) == 0) { |
| 1207 | 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] | 1208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1209 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1210 | } |
| 1211 | global.maxconn = atol(args[1]); |
| 1212 | #ifdef SYSTEM_MAXCONN |
| 1213 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1214 | 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); |
| 1215 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1216 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1217 | } |
| 1218 | #endif /* SYSTEM_MAXCONN */ |
| 1219 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1220 | else if (!strcmp(args[0], "maxsslconn")) { |
| 1221 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1222 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1223 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1224 | if (*(args[1]) == 0) { |
| 1225 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | global.maxsslconn = atol(args[1]); |
| 1230 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1231 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1233 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1234 | #endif |
| 1235 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1236 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 1237 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1238 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1239 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1240 | if (*(args[1]) == 0) { |
| 1241 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1243 | goto out; |
| 1244 | } |
| 1245 | free(global.listen_default_ciphers); |
| 1246 | global.listen_default_ciphers = strdup(args[1]); |
| 1247 | #else |
| 1248 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1250 | goto out; |
| 1251 | #endif |
| 1252 | } |
| 1253 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1254 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1255 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1256 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1257 | if (*(args[1]) == 0) { |
| 1258 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | free(global.connect_default_ciphers); |
| 1263 | global.connect_default_ciphers = strdup(args[1]); |
| 1264 | #else |
| 1265 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1267 | goto out; |
| 1268 | #endif |
| 1269 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 1270 | #ifdef USE_OPENSSL |
| 1271 | #ifndef OPENSSL_NO_DH |
| 1272 | else if (!strcmp(args[0], "ssl-dh-param-file")) { |
| 1273 | if (*(args[1]) == 0) { |
| 1274 | Alert("parsing [%s:%d] : '%s' expects a file path as an argument.\n", file, linenum, args[0]); |
| 1275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1276 | goto out; |
| 1277 | } |
| 1278 | if (ssl_sock_load_global_dh_param_from_file(args[1])) { |
| 1279 | Alert("parsing [%s:%d] : '%s': unable to load DH parameters from file <%s>.\n", file, linenum, args[0], args[1]); |
| 1280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1281 | goto out; |
| 1282 | } |
| 1283 | } |
| 1284 | #endif |
| 1285 | #endif |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1286 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1287 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1288 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1289 | if (*(args[1]) == 0) { |
| 1290 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1292 | goto out; |
| 1293 | } |
| 1294 | if (strcmp(args[1],"none") == 0) |
| 1295 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1296 | else if (strcmp(args[1],"required") == 0) |
| 1297 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1298 | else { |
| 1299 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1301 | goto out; |
| 1302 | } |
| 1303 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1304 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1305 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1306 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1307 | if (global.cps_lim != 0) { |
| 1308 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1309 | err_code |= ERR_ALERT; |
| 1310 | goto out; |
| 1311 | } |
| 1312 | if (*(args[1]) == 0) { |
| 1313 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1315 | goto out; |
| 1316 | } |
| 1317 | global.cps_lim = atol(args[1]); |
| 1318 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1319 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1320 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1321 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1322 | if (global.sps_lim != 0) { |
| 1323 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1324 | err_code |= ERR_ALERT; |
| 1325 | goto out; |
| 1326 | } |
| 1327 | if (*(args[1]) == 0) { |
| 1328 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1330 | goto out; |
| 1331 | } |
| 1332 | global.sps_lim = atol(args[1]); |
| 1333 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1334 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1335 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1336 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1337 | if (global.ssl_lim != 0) { |
| 1338 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1339 | err_code |= ERR_ALERT; |
| 1340 | goto out; |
| 1341 | } |
| 1342 | if (*(args[1]) == 0) { |
| 1343 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1345 | goto out; |
| 1346 | } |
| 1347 | global.ssl_lim = atol(args[1]); |
| 1348 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1349 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1350 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1351 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1352 | if (*(args[1]) == 0) { |
| 1353 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1355 | goto out; |
| 1356 | } |
| 1357 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1358 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1359 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1360 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1361 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1362 | if (global.maxpipes != 0) { |
| 1363 | 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] | 1364 | err_code |= ERR_ALERT; |
| 1365 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1366 | } |
| 1367 | if (*(args[1]) == 0) { |
| 1368 | 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] | 1369 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1370 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1371 | } |
| 1372 | global.maxpipes = atol(args[1]); |
| 1373 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1374 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1375 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1376 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1377 | if (*(args[1]) == 0) { |
| 1378 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1379 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1380 | goto out; |
| 1381 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1382 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1383 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1384 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1385 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1386 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1387 | if (*(args[1]) == 0) { |
| 1388 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1390 | goto out; |
| 1391 | } |
| 1392 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1393 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1394 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1396 | goto out; |
| 1397 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1398 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1399 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1400 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1401 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1402 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1403 | if (global.rlimit_nofile != 0) { |
| 1404 | 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] | 1405 | err_code |= ERR_ALERT; |
| 1406 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1407 | } |
| 1408 | if (*(args[1]) == 0) { |
| 1409 | 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] | 1410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1411 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1412 | } |
| 1413 | global.rlimit_nofile = atol(args[1]); |
| 1414 | } |
| 1415 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1416 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1417 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1418 | if (global.chroot != NULL) { |
| 1419 | 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] | 1420 | err_code |= ERR_ALERT; |
| 1421 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1422 | } |
| 1423 | if (*(args[1]) == 0) { |
| 1424 | 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] | 1425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1426 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1427 | } |
| 1428 | global.chroot = strdup(args[1]); |
| 1429 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1430 | else if (!strcmp(args[0], "description")) { |
| 1431 | int i, len=0; |
| 1432 | char *d; |
| 1433 | |
| 1434 | if (!*args[1]) { |
| 1435 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1436 | file, linenum, args[0]); |
| 1437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1438 | goto out; |
| 1439 | } |
| 1440 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1441 | for (i = 1; *args[i]; i++) |
| 1442 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1443 | |
| 1444 | if (global.desc) |
| 1445 | free(global.desc); |
| 1446 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1447 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1448 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1449 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1450 | for (i = 2; *args[i]; i++) |
| 1451 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1452 | } |
| 1453 | else if (!strcmp(args[0], "node")) { |
| 1454 | int i; |
| 1455 | char c; |
| 1456 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1457 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1458 | goto out; |
| 1459 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1460 | for (i=0; args[1][i]; i++) { |
| 1461 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1462 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1463 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1464 | break; |
| 1465 | } |
| 1466 | |
| 1467 | if (!i || args[1][i]) { |
| 1468 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1469 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1470 | file, linenum, args[0]); |
| 1471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1472 | goto out; |
| 1473 | } |
| 1474 | |
| 1475 | if (global.node) |
| 1476 | free(global.node); |
| 1477 | |
| 1478 | global.node = strdup(args[1]); |
| 1479 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1480 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1481 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1483 | if (global.pidfile != NULL) { |
| 1484 | 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] | 1485 | err_code |= ERR_ALERT; |
| 1486 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1487 | } |
| 1488 | if (*(args[1]) == 0) { |
| 1489 | 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] | 1490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1491 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1492 | } |
| 1493 | global.pidfile = strdup(args[1]); |
| 1494 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1495 | else if (!strcmp(args[0], "unix-bind")) { |
| 1496 | int cur_arg = 1; |
| 1497 | while (*(args[cur_arg])) { |
| 1498 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1499 | if (global.unix_bind.prefix != NULL) { |
| 1500 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1501 | err_code |= ERR_ALERT; |
| 1502 | cur_arg += 2; |
| 1503 | continue; |
| 1504 | } |
| 1505 | |
| 1506 | if (*(args[cur_arg+1]) == 0) { |
| 1507 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1509 | goto out; |
| 1510 | } |
| 1511 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1512 | cur_arg += 2; |
| 1513 | continue; |
| 1514 | } |
| 1515 | |
| 1516 | if (!strcmp(args[cur_arg], "mode")) { |
| 1517 | |
| 1518 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1519 | cur_arg += 2; |
| 1520 | continue; |
| 1521 | } |
| 1522 | |
| 1523 | if (!strcmp(args[cur_arg], "uid")) { |
| 1524 | |
| 1525 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1526 | cur_arg += 2; |
| 1527 | continue; |
| 1528 | } |
| 1529 | |
| 1530 | if (!strcmp(args[cur_arg], "gid")) { |
| 1531 | |
| 1532 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1533 | cur_arg += 2; |
| 1534 | continue; |
| 1535 | } |
| 1536 | |
| 1537 | if (!strcmp(args[cur_arg], "user")) { |
| 1538 | struct passwd *user; |
| 1539 | |
| 1540 | user = getpwnam(args[cur_arg + 1]); |
| 1541 | if (!user) { |
| 1542 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1543 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1545 | goto out; |
| 1546 | } |
| 1547 | |
| 1548 | global.unix_bind.ux.uid = user->pw_uid; |
| 1549 | cur_arg += 2; |
| 1550 | continue; |
| 1551 | } |
| 1552 | |
| 1553 | if (!strcmp(args[cur_arg], "group")) { |
| 1554 | struct group *group; |
| 1555 | |
| 1556 | group = getgrnam(args[cur_arg + 1]); |
| 1557 | if (!group) { |
| 1558 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1559 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1561 | goto out; |
| 1562 | } |
| 1563 | |
| 1564 | global.unix_bind.ux.gid = group->gr_gid; |
| 1565 | cur_arg += 2; |
| 1566 | continue; |
| 1567 | } |
| 1568 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1569 | 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] | 1570 | file, linenum, args[0]); |
| 1571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1572 | goto out; |
| 1573 | } |
| 1574 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1575 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1576 | /* delete previous herited or defined syslog servers */ |
| 1577 | struct logsrv *back; |
| 1578 | struct logsrv *tmp; |
| 1579 | |
| 1580 | if (*(args[1]) != 0) { |
| 1581 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1583 | goto out; |
| 1584 | } |
| 1585 | |
| 1586 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1587 | LIST_DEL(&tmp->list); |
| 1588 | free(tmp); |
| 1589 | } |
| 1590 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1591 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1592 | struct sockaddr_storage *sk; |
| 1593 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1594 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1595 | int arg = 0; |
| 1596 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1597 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1598 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1599 | goto out; |
| 1600 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1601 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1602 | 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] | 1603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1604 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1605 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1606 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1607 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1608 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1609 | /* just after the address, a length may be specified */ |
| 1610 | if (strcmp(args[arg+2], "len") == 0) { |
| 1611 | len = atoi(args[arg+3]); |
| 1612 | if (len < 80 || len > 65535) { |
| 1613 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1614 | file, linenum, args[arg+3]); |
| 1615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1616 | goto out; |
| 1617 | } |
| 1618 | logsrv->maxlen = len; |
| 1619 | |
| 1620 | /* skip these two args */ |
| 1621 | arg += 2; |
| 1622 | } |
| 1623 | else |
| 1624 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1625 | |
| 1626 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1627 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 1628 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 1629 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 1630 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 1631 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1632 | } |
| 1633 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1634 | /* after the length, a format may be specified */ |
| 1635 | if (strcmp(args[arg+2], "format") == 0) { |
| 1636 | logsrv->format = get_log_format(args[arg+3]); |
| 1637 | if (logsrv->format < 0) { |
| 1638 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1639 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1640 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1641 | goto out; |
| 1642 | } |
| 1643 | |
| 1644 | /* skip these two args */ |
| 1645 | arg += 2; |
| 1646 | } |
| 1647 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1648 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1649 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1650 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1651 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1652 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1653 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1654 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1655 | 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] | 1656 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1657 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1658 | } |
| 1659 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1660 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1661 | if (*(args[arg+3])) { |
| 1662 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1663 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1664 | 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] | 1665 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1666 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1670 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1671 | if (*(args[arg+4])) { |
| 1672 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1673 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1674 | 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] | 1675 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1676 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 1680 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1681 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1682 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1683 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1684 | free(logsrv); |
| 1685 | goto out; |
| 1686 | } |
| 1687 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1688 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1689 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1690 | if (port1 != port2) { |
| 1691 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1692 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1693 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1694 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1695 | goto out; |
| 1696 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1697 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1698 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1699 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1700 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1701 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1702 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1703 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1704 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1705 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1706 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1707 | |
| 1708 | if (global.log_send_hostname != NULL) { |
| 1709 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1710 | err_code |= ERR_ALERT; |
| 1711 | goto out; |
| 1712 | } |
| 1713 | |
| 1714 | if (*(args[1])) |
| 1715 | name = args[1]; |
| 1716 | else |
| 1717 | name = hostname; |
| 1718 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1719 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1720 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1721 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1722 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1723 | if (global.server_state_base != NULL) { |
| 1724 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1725 | err_code |= ERR_ALERT; |
| 1726 | goto out; |
| 1727 | } |
| 1728 | |
| 1729 | if (!*(args[1])) { |
| 1730 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1731 | err_code |= ERR_FATAL; |
| 1732 | goto out; |
| 1733 | } |
| 1734 | |
| 1735 | global.server_state_base = strdup(args[1]); |
| 1736 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1737 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1738 | if (global.server_state_file != NULL) { |
| 1739 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1740 | err_code |= ERR_ALERT; |
| 1741 | goto out; |
| 1742 | } |
| 1743 | |
| 1744 | if (!*(args[1])) { |
| 1745 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1746 | err_code |= ERR_FATAL; |
| 1747 | goto out; |
| 1748 | } |
| 1749 | |
| 1750 | global.server_state_file = strdup(args[1]); |
| 1751 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1752 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1753 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1754 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1755 | if (*(args[1]) == 0) { |
| 1756 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1758 | goto out; |
| 1759 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1760 | chunk_destroy(&global.log_tag); |
| 1761 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1762 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1763 | 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] | 1764 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1765 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1766 | if (global.spread_checks != 0) { |
| 1767 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1768 | err_code |= ERR_ALERT; |
| 1769 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1770 | } |
| 1771 | if (*(args[1]) == 0) { |
| 1772 | 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] | 1773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1774 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1775 | } |
| 1776 | global.spread_checks = atol(args[1]); |
| 1777 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1778 | 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] | 1779 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1780 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1781 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1782 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1783 | const char *err; |
| 1784 | unsigned int val; |
| 1785 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1786 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1787 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1788 | if (*(args[1]) == 0) { |
| 1789 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1791 | goto out; |
| 1792 | } |
| 1793 | |
| 1794 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1795 | if (err) { |
| 1796 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1798 | } |
| 1799 | global.max_spread_checks = val; |
| 1800 | if (global.max_spread_checks < 0) { |
| 1801 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1803 | } |
| 1804 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1805 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1806 | #ifdef USE_CPU_AFFINITY |
| 1807 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1808 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1809 | unsigned long cpus = 0; |
| 1810 | |
| 1811 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1812 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1813 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1814 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1815 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1816 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1817 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1818 | proc = atol(args[1]); |
| 1819 | if (proc >= 1 && proc <= LONGBITS) |
| 1820 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1824 | 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", |
| 1825 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1826 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1827 | goto out; |
| 1828 | } |
| 1829 | |
| 1830 | cur_arg = 2; |
| 1831 | while (*args[cur_arg]) { |
| 1832 | unsigned int low, high; |
| 1833 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1834 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1835 | char *dash = strchr(args[cur_arg], '-'); |
| 1836 | |
| 1837 | low = high = str2uic(args[cur_arg]); |
| 1838 | if (dash) |
| 1839 | high = str2uic(dash + 1); |
| 1840 | |
| 1841 | if (high < low) { |
| 1842 | unsigned int swap = low; |
| 1843 | low = high; |
| 1844 | high = swap; |
| 1845 | } |
| 1846 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1847 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1848 | 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] | 1849 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1851 | goto out; |
| 1852 | } |
| 1853 | |
| 1854 | while (low <= high) |
| 1855 | cpus |= 1UL << low++; |
| 1856 | } |
| 1857 | else { |
| 1858 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1859 | file, linenum, args[0], args[cur_arg]); |
| 1860 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1861 | goto out; |
| 1862 | } |
| 1863 | cur_arg++; |
| 1864 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1865 | for (i = 0; i < LONGBITS; i++) |
| 1866 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1867 | global.cpu_map[i] = cpus; |
| 1868 | #else |
| 1869 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1871 | goto out; |
| 1872 | #endif |
| 1873 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1874 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1875 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1876 | goto out; |
| 1877 | |
| 1878 | if (*(args[2]) == 0) { |
| 1879 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1880 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1881 | goto out; |
| 1882 | } |
| 1883 | |
| 1884 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1885 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1886 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1888 | goto out; |
| 1889 | } |
| 1890 | } |
| 1891 | else if (!strcmp(args[0], "unsetenv")) { |
| 1892 | int arg; |
| 1893 | |
| 1894 | if (*(args[1]) == 0) { |
| 1895 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1897 | goto out; |
| 1898 | } |
| 1899 | |
| 1900 | for (arg = 1; *args[arg]; arg++) { |
| 1901 | if (unsetenv(args[arg]) != 0) { |
| 1902 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1904 | goto out; |
| 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | else if (!strcmp(args[0], "resetenv")) { |
| 1909 | extern char **environ; |
| 1910 | char **env = environ; |
| 1911 | |
| 1912 | /* args contain variable names to keep, one per argument */ |
| 1913 | while (*env) { |
| 1914 | int arg; |
| 1915 | |
| 1916 | /* look for current variable in among all those we want to keep */ |
| 1917 | for (arg = 1; *args[arg]; arg++) { |
| 1918 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1919 | (*env)[strlen(args[arg])] == '=') |
| 1920 | break; |
| 1921 | } |
| 1922 | |
| 1923 | /* delete this variable */ |
| 1924 | if (!*args[arg]) { |
| 1925 | char *delim = strchr(*env, '='); |
| 1926 | |
| 1927 | if (!delim || delim - *env >= trash.size) { |
| 1928 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1930 | goto out; |
| 1931 | } |
| 1932 | |
| 1933 | memcpy(trash.str, *env, delim - *env); |
| 1934 | trash.str[delim - *env] = 0; |
| 1935 | |
| 1936 | if (unsetenv(trash.str) != 0) { |
| 1937 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1939 | goto out; |
| 1940 | } |
| 1941 | } |
| 1942 | else |
| 1943 | env++; |
| 1944 | } |
| 1945 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1946 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1947 | struct cfg_kw_list *kwl; |
| 1948 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1949 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1950 | |
| 1951 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1952 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1953 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1954 | continue; |
| 1955 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1956 | 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] | 1957 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1958 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1959 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1960 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1961 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1962 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1963 | err_code |= ERR_WARN; |
| 1964 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1965 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1966 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1971 | 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] | 1972 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1973 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1974 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1975 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1976 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1977 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1980 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1981 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1982 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1983 | defproxy.mode = PR_MODE_TCP; |
| 1984 | defproxy.state = PR_STNEW; |
| 1985 | defproxy.maxconn = cfg_maxpconn; |
| 1986 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1987 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1988 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1989 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1990 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1991 | defproxy.defsrv.check.fastinter = 0; |
| 1992 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1993 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1994 | defproxy.defsrv.agent.fastinter = 0; |
| 1995 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1996 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1997 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1998 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1999 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2000 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 2001 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2002 | defproxy.defsrv.maxqueue = 0; |
| 2003 | defproxy.defsrv.minconn = 0; |
| 2004 | defproxy.defsrv.maxconn = 0; |
| 2005 | defproxy.defsrv.slowstart = 0; |
| 2006 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 2007 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 2008 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2009 | |
| 2010 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2011 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2012 | } |
| 2013 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2014 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2015 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 2016 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 2017 | * ERR_FATAL in case of error. |
| 2018 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2019 | static int create_cond_regex_rule(const char *file, int line, |
| 2020 | struct proxy *px, int dir, int action, int flags, |
| 2021 | const char *cmd, const char *reg, const char *repl, |
| 2022 | const char **cond_start) |
| 2023 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2024 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2025 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2026 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2027 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2028 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2029 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2030 | int cs; |
| 2031 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2032 | |
| 2033 | if (px == &defproxy) { |
| 2034 | 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] | 2035 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2036 | goto err; |
| 2037 | } |
| 2038 | |
| 2039 | if (*reg == 0) { |
| 2040 | 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] | 2041 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2042 | goto err; |
| 2043 | } |
| 2044 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2045 | 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] | 2046 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2047 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2048 | if (cond_start && |
| 2049 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2050 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 2051 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 2052 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2053 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2054 | goto err; |
| 2055 | } |
| 2056 | } |
| 2057 | else if (cond_start && **cond_start) { |
| 2058 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 2059 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2060 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2061 | goto err; |
| 2062 | } |
| 2063 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2064 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2065 | (dir == SMP_OPT_DIR_REQ) ? |
| 2066 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 2067 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 2068 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2069 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2070 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2071 | if (!preg) { |
| 2072 | 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] | 2073 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2074 | goto err; |
| 2075 | } |
| 2076 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2077 | cs = !(flags & REG_ICASE); |
| 2078 | cap = !(flags & REG_NOSUB); |
| 2079 | error = NULL; |
| 2080 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 2081 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 2082 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2083 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2084 | goto err; |
| 2085 | } |
| 2086 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2087 | 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] | 2088 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2089 | if (repl && err) { |
| 2090 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 2091 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2092 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 2093 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2094 | } |
| 2095 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2096 | 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] | 2097 | ret_code |= ERR_WARN; |
| 2098 | |
| 2099 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2100 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2101 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2102 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2103 | err: |
| 2104 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2105 | free(errmsg); |
| 2106 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2107 | } |
| 2108 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2109 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2110 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2111 | * Returns the error code, 0 if OK, or any combination of : |
| 2112 | * - ERR_ABORT: must abort ASAP |
| 2113 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2114 | * - ERR_WARN: a warning has been emitted |
| 2115 | * - ERR_ALERT: an alert has been emitted |
| 2116 | * Only the two first ones can stop processing, the two others are just |
| 2117 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2118 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2119 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 2120 | { |
| 2121 | static struct peers *curpeers = NULL; |
| 2122 | struct peer *newpeer = NULL; |
| 2123 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2124 | struct bind_conf *bind_conf; |
| 2125 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2126 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2127 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2128 | |
| 2129 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2130 | if (!*args[1]) { |
| 2131 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2132 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2133 | goto out; |
| 2134 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2135 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2136 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2137 | goto out; |
| 2138 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2139 | err = invalid_char(args[1]); |
| 2140 | if (err) { |
| 2141 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2142 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2143 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2144 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 2148 | /* |
| 2149 | * If there are two proxies with the same name only following |
| 2150 | * combinations are allowed: |
| 2151 | */ |
| 2152 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2153 | 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] | 2154 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2155 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2159 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2160 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2161 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2162 | goto out; |
| 2163 | } |
| 2164 | |
| 2165 | curpeers->next = peers; |
| 2166 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2167 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2168 | curpeers->conf.line = linenum; |
| 2169 | curpeers->last_change = now.tv_sec; |
| 2170 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2171 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2172 | } |
| 2173 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2174 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2175 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2176 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2177 | |
| 2178 | if (!*args[2]) { |
| 2179 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2180 | file, linenum, args[0]); |
| 2181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2182 | goto out; |
| 2183 | } |
| 2184 | |
| 2185 | err = invalid_char(args[1]); |
| 2186 | if (err) { |
| 2187 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2188 | file, linenum, *err, args[1]); |
| 2189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2190 | goto out; |
| 2191 | } |
| 2192 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2193 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2194 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2195 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2196 | goto out; |
| 2197 | } |
| 2198 | |
| 2199 | /* the peers are linked backwards first */ |
| 2200 | curpeers->count++; |
| 2201 | newpeer->next = curpeers->remote; |
| 2202 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2203 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2204 | newpeer->conf.line = linenum; |
| 2205 | |
| 2206 | newpeer->last_change = now.tv_sec; |
| 2207 | newpeer->id = strdup(args[1]); |
| 2208 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2209 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2210 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2211 | 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] | 2212 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2213 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2214 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2215 | |
| 2216 | proto = protocol_by_family(sk->ss_family); |
| 2217 | if (!proto || !proto->connect) { |
| 2218 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2219 | file, linenum, args[0], args[1]); |
| 2220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2221 | goto out; |
| 2222 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2223 | |
| 2224 | if (port1 != port2) { |
| 2225 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2226 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2228 | goto out; |
| 2229 | } |
| 2230 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2231 | if (!port1) { |
| 2232 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2233 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2235 | goto out; |
| 2236 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2237 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2238 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2239 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 2240 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2241 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2242 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2243 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2244 | /* Current is local peer, it define a frontend */ |
| 2245 | newpeer->local = 1; |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 2246 | peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2247 | |
| 2248 | if (!curpeers->peers_fe) { |
| 2249 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2250 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2251 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2252 | goto out; |
| 2253 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2254 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2255 | init_new_proxy(curpeers->peers_fe); |
| 2256 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2257 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2258 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2259 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2260 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2261 | |
| 2262 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 2263 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2264 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2265 | if (errmsg && *errmsg) { |
| 2266 | indent_msg(&errmsg, 2); |
| 2267 | 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] | 2268 | } |
| 2269 | else |
| 2270 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2271 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2272 | err_code |= ERR_FATAL; |
| 2273 | goto out; |
| 2274 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2275 | |
| 2276 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2277 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2278 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2279 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2280 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2281 | l->handler = process_stream; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2282 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2283 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2284 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2285 | global.maxsock += l->maxconn; |
| 2286 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2287 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2288 | else { |
| 2289 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2290 | file, linenum, args[0], args[1], |
| 2291 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2292 | err_code |= ERR_FATAL; |
| 2293 | goto out; |
| 2294 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2295 | } |
| 2296 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2297 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2298 | curpeers->state = PR_STSTOPPED; |
| 2299 | } |
| 2300 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2301 | curpeers->state = PR_STNEW; |
| 2302 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2303 | else if (*args[0] != 0) { |
| 2304 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | |
| 2309 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2310 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2311 | return err_code; |
| 2312 | } |
| 2313 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2314 | /* |
| 2315 | * Parse a <resolvers> section. |
| 2316 | * Returns the error code, 0 if OK, or any combination of : |
| 2317 | * - ERR_ABORT: must abort ASAP |
| 2318 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2319 | * - ERR_WARN: a warning has been emitted |
| 2320 | * - ERR_ALERT: an alert has been emitted |
| 2321 | * Only the two first ones can stop processing, the two others are just |
| 2322 | * indicators. |
| 2323 | */ |
| 2324 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2325 | { |
| 2326 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2327 | struct dns_nameserver *newnameserver = NULL; |
| 2328 | const char *err; |
| 2329 | int err_code = 0; |
| 2330 | char *errmsg = NULL; |
| 2331 | |
| 2332 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2333 | if (!*args[1]) { |
| 2334 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2335 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2336 | goto out; |
| 2337 | } |
| 2338 | |
| 2339 | err = invalid_char(args[1]); |
| 2340 | if (err) { |
| 2341 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2342 | file, linenum, *err, args[0], args[1]); |
| 2343 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2344 | goto out; |
| 2345 | } |
| 2346 | |
| 2347 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2348 | /* Error if two resolvers owns the same name */ |
| 2349 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2350 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2351 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2352 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2353 | } |
| 2354 | } |
| 2355 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2356 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2357 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2358 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2359 | goto out; |
| 2360 | } |
| 2361 | |
| 2362 | /* default values */ |
| 2363 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2364 | curr_resolvers->conf.file = strdup(file); |
| 2365 | curr_resolvers->conf.line = linenum; |
| 2366 | curr_resolvers->id = strdup(args[1]); |
| 2367 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2368 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2369 | curr_resolvers->hold.nx = 30000; |
| 2370 | curr_resolvers->hold.other = 30000; |
| 2371 | curr_resolvers->hold.refused = 30000; |
| 2372 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2373 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2374 | curr_resolvers->hold.valid = 10000; |
| 2375 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2376 | curr_resolvers->resolve_retries = 3; |
| 2377 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2378 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2379 | } |
| 2380 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2381 | struct sockaddr_storage *sk; |
| 2382 | int port1, port2; |
| 2383 | struct protocol *proto; |
| 2384 | |
| 2385 | if (!*args[2]) { |
| 2386 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2387 | file, linenum, args[0]); |
| 2388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2389 | goto out; |
| 2390 | } |
| 2391 | |
| 2392 | err = invalid_char(args[1]); |
| 2393 | if (err) { |
| 2394 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2395 | file, linenum, *err, args[1]); |
| 2396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2397 | goto out; |
| 2398 | } |
| 2399 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2400 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2401 | /* Error if two resolvers owns the same name */ |
| 2402 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2403 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2404 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2406 | } |
| 2407 | } |
| 2408 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2409 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2410 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2411 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | |
| 2415 | /* the nameservers are linked backward first */ |
| 2416 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2417 | curr_resolvers->count_nameservers++; |
| 2418 | newnameserver->resolvers = curr_resolvers; |
| 2419 | newnameserver->conf.file = strdup(file); |
| 2420 | newnameserver->conf.line = linenum; |
| 2421 | newnameserver->id = strdup(args[1]); |
| 2422 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2423 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2424 | if (!sk) { |
| 2425 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2427 | goto out; |
| 2428 | } |
| 2429 | |
| 2430 | proto = protocol_by_family(sk->ss_family); |
| 2431 | if (!proto || !proto->connect) { |
| 2432 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2433 | file, linenum, args[0], args[1]); |
| 2434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2435 | goto out; |
| 2436 | } |
| 2437 | |
| 2438 | if (port1 != port2) { |
| 2439 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2440 | file, linenum, args[0], args[1], args[2]); |
| 2441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2442 | goto out; |
| 2443 | } |
| 2444 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2445 | if (!port1 && !port2) { |
| 2446 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2447 | file, linenum, args[0], args[1]); |
| 2448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2449 | goto out; |
| 2450 | } |
| 2451 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2452 | newnameserver->addr = *sk; |
| 2453 | } |
| 2454 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2455 | const char *res; |
| 2456 | unsigned int time; |
| 2457 | |
| 2458 | if (!*args[2]) { |
| 2459 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2460 | file, linenum, args[0]); |
| 2461 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2463 | goto out; |
| 2464 | } |
| 2465 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2466 | if (res) { |
| 2467 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2468 | file, linenum, *res, args[0]); |
| 2469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2470 | goto out; |
| 2471 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2472 | if (strcmp(args[1], "nx") == 0) |
| 2473 | curr_resolvers->hold.nx = time; |
| 2474 | else if (strcmp(args[1], "other") == 0) |
| 2475 | curr_resolvers->hold.other = time; |
| 2476 | else if (strcmp(args[1], "refused") == 0) |
| 2477 | curr_resolvers->hold.refused = time; |
| 2478 | else if (strcmp(args[1], "timeout") == 0) |
| 2479 | curr_resolvers->hold.timeout = time; |
| 2480 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2481 | curr_resolvers->hold.valid = time; |
| 2482 | else { |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2483 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', or 'other'.\n", |
| 2484 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2485 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2486 | goto out; |
| 2487 | } |
| 2488 | |
| 2489 | } |
| 2490 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2491 | if (!*args[1]) { |
| 2492 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2493 | file, linenum, args[0]); |
| 2494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2495 | goto out; |
| 2496 | } |
| 2497 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2498 | } |
| 2499 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2500 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2501 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2502 | file, linenum, args[0]); |
| 2503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2504 | goto out; |
| 2505 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2506 | else if (strcmp(args[1], "retry") == 0) { |
| 2507 | const char *res; |
| 2508 | unsigned int timeout_retry; |
| 2509 | |
| 2510 | if (!*args[2]) { |
| 2511 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2512 | file, linenum, args[0], args[1]); |
| 2513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2514 | goto out; |
| 2515 | } |
| 2516 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2517 | if (res) { |
| 2518 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2519 | file, linenum, *res, args[0], args[1]); |
| 2520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2521 | goto out; |
| 2522 | } |
| 2523 | curr_resolvers->timeout.retry = timeout_retry; |
| 2524 | } |
| 2525 | else { |
| 2526 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2527 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2529 | goto out; |
| 2530 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2531 | } /* neither "nameserver" nor "resolvers" */ |
| 2532 | else if (*args[0] != 0) { |
| 2533 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2534 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2535 | goto out; |
| 2536 | } |
| 2537 | |
| 2538 | out: |
| 2539 | free(errmsg); |
| 2540 | return err_code; |
| 2541 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2542 | |
| 2543 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2544 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2545 | * Returns the error code, 0 if OK, or any combination of : |
| 2546 | * - ERR_ABORT: must abort ASAP |
| 2547 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2548 | * - ERR_WARN: a warning has been emitted |
| 2549 | * - ERR_ALERT: an alert has been emitted |
| 2550 | * Only the two first ones can stop processing, the two others are just |
| 2551 | * indicators. |
| 2552 | */ |
| 2553 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2554 | { |
| 2555 | static struct mailers *curmailers = NULL; |
| 2556 | struct mailer *newmailer = NULL; |
| 2557 | const char *err; |
| 2558 | int err_code = 0; |
| 2559 | char *errmsg = NULL; |
| 2560 | |
| 2561 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2562 | if (!*args[1]) { |
| 2563 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2564 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2565 | goto out; |
| 2566 | } |
| 2567 | |
| 2568 | err = invalid_char(args[1]); |
| 2569 | if (err) { |
| 2570 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2571 | file, linenum, *err, args[0], args[1]); |
| 2572 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2573 | goto out; |
| 2574 | } |
| 2575 | |
| 2576 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2577 | /* |
| 2578 | * If there are two proxies with the same name only following |
| 2579 | * combinations are allowed: |
| 2580 | */ |
| 2581 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2582 | 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] | 2583 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2584 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2588 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2589 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2590 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2591 | goto out; |
| 2592 | } |
| 2593 | |
| 2594 | curmailers->next = mailers; |
| 2595 | mailers = curmailers; |
| 2596 | curmailers->conf.file = strdup(file); |
| 2597 | curmailers->conf.line = linenum; |
| 2598 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2599 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2600 | * But need enough time so that timeouts don't occur |
| 2601 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2602 | } |
| 2603 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2604 | struct sockaddr_storage *sk; |
| 2605 | int port1, port2; |
| 2606 | struct protocol *proto; |
| 2607 | |
| 2608 | if (!*args[2]) { |
| 2609 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2610 | file, linenum, args[0]); |
| 2611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | |
| 2615 | err = invalid_char(args[1]); |
| 2616 | if (err) { |
| 2617 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2618 | file, linenum, *err, args[1]); |
| 2619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2620 | goto out; |
| 2621 | } |
| 2622 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2623 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2624 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2625 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2626 | goto out; |
| 2627 | } |
| 2628 | |
| 2629 | /* the mailers are linked backwards first */ |
| 2630 | curmailers->count++; |
| 2631 | newmailer->next = curmailers->mailer_list; |
| 2632 | curmailers->mailer_list = newmailer; |
| 2633 | newmailer->mailers = curmailers; |
| 2634 | newmailer->conf.file = strdup(file); |
| 2635 | newmailer->conf.line = linenum; |
| 2636 | |
| 2637 | newmailer->id = strdup(args[1]); |
| 2638 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2639 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2640 | if (!sk) { |
| 2641 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
| 2646 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2647 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2648 | 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] | 2649 | file, linenum, args[0], args[1]); |
| 2650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2651 | goto out; |
| 2652 | } |
| 2653 | |
| 2654 | if (port1 != port2) { |
| 2655 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2656 | file, linenum, args[0], args[1], args[2]); |
| 2657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2658 | goto out; |
| 2659 | } |
| 2660 | |
| 2661 | if (!port1) { |
| 2662 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2663 | file, linenum, args[0], args[1], args[2]); |
| 2664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
| 2668 | newmailer->addr = *sk; |
| 2669 | newmailer->proto = proto; |
| 2670 | newmailer->xprt = &raw_sock; |
| 2671 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2672 | } |
| 2673 | else if (strcmp(args[0], "timeout") == 0) { |
| 2674 | if (!*args[1]) { |
| 2675 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2676 | file, linenum, args[0]); |
| 2677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2678 | goto out; |
| 2679 | } |
| 2680 | else if (strcmp(args[1], "mail") == 0) { |
| 2681 | const char *res; |
| 2682 | unsigned int timeout_mail; |
| 2683 | if (!*args[2]) { |
| 2684 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2685 | file, linenum, args[0], args[1]); |
| 2686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2687 | goto out; |
| 2688 | } |
| 2689 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2690 | if (res) { |
| 2691 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2692 | file, linenum, *res, args[0]); |
| 2693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2694 | goto out; |
| 2695 | } |
| 2696 | if (timeout_mail <= 0) { |
| 2697 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2699 | goto out; |
| 2700 | } |
| 2701 | curmailers->timeout.mail = timeout_mail; |
| 2702 | } else { |
| 2703 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2704 | file, linenum, args[0], args[1]); |
| 2705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2706 | goto out; |
| 2707 | } |
| 2708 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2709 | else if (*args[0] != 0) { |
| 2710 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | out: |
| 2716 | free(errmsg); |
| 2717 | return err_code; |
| 2718 | } |
| 2719 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2720 | static void free_email_alert(struct proxy *p) |
| 2721 | { |
| 2722 | free(p->email_alert.mailers.name); |
| 2723 | p->email_alert.mailers.name = NULL; |
| 2724 | free(p->email_alert.from); |
| 2725 | p->email_alert.from = NULL; |
| 2726 | free(p->email_alert.to); |
| 2727 | p->email_alert.to = NULL; |
| 2728 | free(p->email_alert.myhostname); |
| 2729 | p->email_alert.myhostname = NULL; |
| 2730 | } |
| 2731 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2732 | 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] | 2733 | { |
| 2734 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2735 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2736 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2737 | int rc; |
| 2738 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2739 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2740 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2741 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2742 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2743 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2744 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2745 | if (!strcmp(args[0], "listen")) |
| 2746 | rc = PR_CAP_LISTEN; |
| 2747 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2748 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2749 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2750 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2751 | else |
| 2752 | rc = PR_CAP_NONE; |
| 2753 | |
| 2754 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2755 | if (!*args[1]) { |
| 2756 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2757 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2758 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2759 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2760 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2761 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2762 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2763 | err = invalid_char(args[1]); |
| 2764 | if (err) { |
| 2765 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2766 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2767 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2768 | } |
| 2769 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2770 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2771 | if (curproxy) { |
| 2772 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2773 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2774 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2775 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2776 | } |
| 2777 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2778 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2779 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2780 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2781 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2782 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2783 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2784 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2785 | curproxy->next = proxy; |
| 2786 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2787 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2788 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2789 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2790 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2791 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2792 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2793 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2794 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2795 | if (curproxy->cap & PR_CAP_FE) |
| 2796 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2797 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2801 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2802 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2803 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2804 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2805 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2806 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2807 | curproxy->no_options = defproxy.no_options; |
| 2808 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2809 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2810 | curproxy->except_net = defproxy.except_net; |
| 2811 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2812 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2813 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2814 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2815 | if (defproxy.fwdfor_hdr_len) { |
| 2816 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2817 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2818 | } |
| 2819 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2820 | if (defproxy.orgto_hdr_len) { |
| 2821 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2822 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2823 | } |
| 2824 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2825 | if (defproxy.server_id_hdr_len) { |
| 2826 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2827 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2828 | } |
| 2829 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2830 | if (curproxy->cap & PR_CAP_FE) { |
| 2831 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2832 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2833 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2834 | |
| 2835 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2836 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2837 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2838 | |
| 2839 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2840 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2841 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2842 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2843 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2844 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2845 | curproxy->fullconn = defproxy.fullconn; |
| 2846 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2847 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2848 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2849 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2850 | if (defproxy.check_req) { |
| 2851 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2852 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2853 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2854 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2855 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2856 | if (defproxy.expect_str) { |
| 2857 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2858 | if (defproxy.expect_regex) { |
| 2859 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2860 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2861 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2865 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2866 | if (defproxy.cookie_name) |
| 2867 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2868 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2869 | if (defproxy.cookie_domain) |
| 2870 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2871 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2872 | if (defproxy.cookie_maxidle) |
| 2873 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2874 | |
| 2875 | if (defproxy.cookie_maxlife) |
| 2876 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2877 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2878 | if (defproxy.rdp_cookie_name) |
| 2879 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2880 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2881 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2882 | if (defproxy.url_param_name) |
| 2883 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2884 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2885 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2886 | if (defproxy.hh_name) |
| 2887 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2888 | curproxy->hh_len = defproxy.hh_len; |
| 2889 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2890 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2891 | if (defproxy.conn_src.iface_name) |
| 2892 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2893 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2894 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2895 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2896 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2897 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2898 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2899 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2900 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2901 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2902 | if (defproxy.capture_name) |
| 2903 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2904 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2905 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2906 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2907 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2908 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2909 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2910 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2911 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2912 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2913 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2914 | curproxy->mon_net = defproxy.mon_net; |
| 2915 | curproxy->mon_mask = defproxy.mon_mask; |
| 2916 | if (defproxy.monitor_uri) |
| 2917 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2918 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2919 | if (defproxy.defbe.name) |
| 2920 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2921 | |
| 2922 | /* 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] | 2923 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2924 | if (curproxy->conf.logformat_string && |
| 2925 | curproxy->conf.logformat_string != default_http_log_format && |
| 2926 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2927 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2928 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2929 | |
| 2930 | if (defproxy.conf.lfs_file) { |
| 2931 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2932 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2933 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2934 | |
| 2935 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2936 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2937 | if (curproxy->conf.logformat_sd_string && |
| 2938 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2939 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2940 | |
| 2941 | if (defproxy.conf.lfsd_file) { |
| 2942 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2943 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2944 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2948 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2949 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2950 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2951 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2952 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2953 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2954 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2955 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2956 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2957 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2958 | } |
| 2959 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2960 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2961 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2962 | |
| 2963 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2964 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2965 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2966 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2967 | LIST_INIT(&node->list); |
| 2968 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2969 | } |
| 2970 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2971 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2972 | if (curproxy->conf.uniqueid_format_string) |
| 2973 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2974 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2975 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2976 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2977 | if (defproxy.conf.uif_file) { |
| 2978 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2979 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2980 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2981 | |
| 2982 | /* copy default header unique id */ |
| 2983 | if (defproxy.header_unique_id) |
| 2984 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2985 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2986 | /* default compression options */ |
| 2987 | if (defproxy.comp != NULL) { |
| 2988 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2989 | curproxy->comp->algos = defproxy.comp->algos; |
| 2990 | curproxy->comp->types = defproxy.comp->types; |
| 2991 | } |
| 2992 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2993 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2994 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2995 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2996 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2997 | if (defproxy.check_path) |
| 2998 | curproxy->check_path = strdup(defproxy.check_path); |
| 2999 | if (defproxy.check_command) |
| 3000 | curproxy->check_command = strdup(defproxy.check_command); |
| 3001 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3002 | if (defproxy.email_alert.mailers.name) |
| 3003 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3004 | if (defproxy.email_alert.from) |
| 3005 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3006 | if (defproxy.email_alert.to) |
| 3007 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3008 | if (defproxy.email_alert.myhostname) |
| 3009 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3010 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3011 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3012 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3013 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3014 | } |
| 3015 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3016 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3017 | /* FIXME-20070101: we should do this too at the end of the |
| 3018 | * config parsing to free all default values. |
| 3019 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3020 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3021 | err_code |= ERR_ABORT; |
| 3022 | goto out; |
| 3023 | } |
| 3024 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3025 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3026 | free(defproxy.check_command); |
| 3027 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3028 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3029 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3030 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3031 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3032 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3033 | free(defproxy.capture_name); |
| 3034 | free(defproxy.monitor_uri); |
| 3035 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3036 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3037 | free(defproxy.fwdfor_hdr_name); |
| 3038 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3039 | free(defproxy.orgto_hdr_name); |
| 3040 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3041 | free(defproxy.server_id_hdr_name); |
| 3042 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3043 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3044 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3045 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3046 | free(defproxy.expect_regex); |
| 3047 | defproxy.expect_regex = NULL; |
| 3048 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3049 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3050 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3051 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3052 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3053 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3054 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3055 | free(defproxy.conf.uniqueid_format_string); |
| 3056 | free(defproxy.conf.lfs_file); |
| 3057 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3058 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3059 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3060 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3061 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3062 | free(defproxy.conf.logformat_sd_string); |
| 3063 | free(defproxy.conf.lfsd_file); |
| 3064 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3065 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3066 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3067 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3068 | /* we cannot free uri_auth because it might already be used */ |
| 3069 | init_default_instance(); |
| 3070 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3071 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3072 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3073 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3074 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3075 | } |
| 3076 | else if (curproxy == NULL) { |
| 3077 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3078 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3079 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3080 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3081 | |
| 3082 | /* update the current file and line being parsed */ |
| 3083 | curproxy->conf.args.file = curproxy->conf.file; |
| 3084 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3085 | |
| 3086 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3087 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 3088 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3089 | if (err_code & ERR_FATAL) |
| 3090 | goto out; |
| 3091 | } |
| 3092 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3093 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3094 | int cur_arg; |
| 3095 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3096 | if (curproxy == &defproxy) { |
| 3097 | 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] | 3098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3099 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3100 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3101 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3102 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3103 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3104 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 3105 | 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] | 3106 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3108 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3109 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3110 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 3111 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 3112 | |
| 3113 | /* use default settings for unix sockets */ |
| 3114 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3115 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3116 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3117 | |
| 3118 | /* NOTE: the following line might create several listeners if there |
| 3119 | * are comma-separated IPs or port ranges. So all further processing |
| 3120 | * will have to be applied to all listeners created after last_listen. |
| 3121 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3122 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3123 | if (errmsg && *errmsg) { |
| 3124 | indent_msg(&errmsg, 2); |
| 3125 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 3126 | } |
| 3127 | else |
| 3128 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3129 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3131 | goto out; |
| 3132 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3133 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3134 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3135 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3136 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3137 | } |
| 3138 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3139 | cur_arg = 2; |
| 3140 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3141 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3142 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3143 | char *err; |
| 3144 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3145 | kw = bind_find_kw(args[cur_arg]); |
| 3146 | if (kw) { |
| 3147 | char *err = NULL; |
| 3148 | int code; |
| 3149 | |
| 3150 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3151 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3152 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3153 | cur_arg += 1 + kw->skip ; |
| 3154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3155 | goto out; |
| 3156 | } |
| 3157 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3158 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3159 | err_code |= code; |
| 3160 | |
| 3161 | if (code) { |
| 3162 | if (err && *err) { |
| 3163 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3164 | 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] | 3165 | } |
| 3166 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3167 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3168 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3169 | if (code & ERR_FATAL) { |
| 3170 | free(err); |
| 3171 | cur_arg += 1 + kw->skip; |
| 3172 | goto out; |
| 3173 | } |
| 3174 | } |
| 3175 | free(err); |
| 3176 | cur_arg += 1 + kw->skip; |
| 3177 | continue; |
| 3178 | } |
| 3179 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3180 | err = NULL; |
| 3181 | if (!bind_dumped) { |
| 3182 | bind_dump_kws(&err); |
| 3183 | indent_msg(&err, 4); |
| 3184 | bind_dumped = 1; |
| 3185 | } |
| 3186 | |
| 3187 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3188 | file, linenum, args[0], args[1], args[cur_arg], |
| 3189 | err ? " Registered keywords :" : "", err ? err : ""); |
| 3190 | free(err); |
| 3191 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3193 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3194 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3195 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3196 | } |
| 3197 | 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] | 3198 | 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] | 3199 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3200 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3202 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3203 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3204 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3205 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3206 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3207 | /* flush useless bits */ |
| 3208 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3209 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3210 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3211 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3212 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3213 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3214 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3215 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3216 | goto out; |
| 3217 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3218 | if (!*args[1]) { |
| 3219 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3220 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3222 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3223 | } |
| 3224 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3225 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3226 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3227 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3228 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3229 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3230 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3231 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3232 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3233 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3234 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3235 | goto out; |
| 3236 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3237 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3238 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3239 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3240 | else { |
| 3241 | 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] | 3242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3243 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3244 | } |
| 3245 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3246 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3247 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3248 | |
| 3249 | if (curproxy == &defproxy) { |
| 3250 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3251 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3253 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3256 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3257 | goto out; |
| 3258 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3259 | if (!*args[1]) { |
| 3260 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3261 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3263 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3267 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3268 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3269 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3270 | if (curproxy->uuid <= 0) { |
| 3271 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3272 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3274 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3275 | } |
| 3276 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3277 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3278 | if (node) { |
| 3279 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3280 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3281 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3282 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3284 | goto out; |
| 3285 | } |
| 3286 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3287 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3288 | else if (!strcmp(args[0], "description")) { |
| 3289 | int i, len=0; |
| 3290 | char *d; |
| 3291 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3292 | if (curproxy == &defproxy) { |
| 3293 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3294 | file, linenum, args[0]); |
| 3295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3296 | goto out; |
| 3297 | } |
| 3298 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3299 | if (!*args[1]) { |
| 3300 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3301 | file, linenum, args[0]); |
| 3302 | return -1; |
| 3303 | } |
| 3304 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3305 | for (i = 1; *args[i]; i++) |
| 3306 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3307 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3308 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3309 | curproxy->desc = d; |
| 3310 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3311 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3312 | for (i = 2; *args[i]; i++) |
| 3313 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3314 | |
| 3315 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3316 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3317 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3318 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3319 | curproxy->state = PR_STSTOPPED; |
| 3320 | } |
| 3321 | 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] | 3322 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3323 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3324 | curproxy->state = PR_STNEW; |
| 3325 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3326 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3327 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3328 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3329 | |
| 3330 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3331 | unsigned int low, high; |
| 3332 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3333 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3334 | set = 0; |
| 3335 | break; |
| 3336 | } |
| 3337 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3338 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3339 | } |
| 3340 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3341 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3342 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3343 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3344 | char *dash = strchr(args[cur_arg], '-'); |
| 3345 | |
| 3346 | low = high = str2uic(args[cur_arg]); |
| 3347 | if (dash) |
| 3348 | high = str2uic(dash + 1); |
| 3349 | |
| 3350 | if (high < low) { |
| 3351 | unsigned int swap = low; |
| 3352 | low = high; |
| 3353 | high = swap; |
| 3354 | } |
| 3355 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3356 | if (low < 1 || high > LONGBITS) { |
| 3357 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3358 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3360 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3361 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3362 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3363 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3364 | } |
| 3365 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3366 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3367 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3369 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3370 | } |
| 3371 | cur_arg++; |
| 3372 | } |
| 3373 | curproxy->bind_proc = set; |
| 3374 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3375 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3376 | if (curproxy == &defproxy) { |
| 3377 | 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] | 3378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3379 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3380 | } |
| 3381 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3382 | err = invalid_char(args[1]); |
| 3383 | if (err) { |
| 3384 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3385 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3386 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3387 | } |
| 3388 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3389 | 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] | 3390 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3391 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3393 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3394 | } |
| 3395 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3396 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3397 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3398 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3399 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3400 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3401 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3402 | if (*(args[1]) == 0) { |
| 3403 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3404 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3406 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3407 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3408 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3409 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3410 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3411 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3412 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3413 | curproxy->cookie_name = strdup(args[1]); |
| 3414 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3415 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3416 | cur_arg = 2; |
| 3417 | while (*(args[cur_arg])) { |
| 3418 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3419 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3420 | } |
| 3421 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3422 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3423 | } |
| 3424 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3425 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3426 | } |
| 3427 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3428 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3429 | } |
| 3430 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3431 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3432 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3433 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3434 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3435 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3436 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3437 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3438 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3439 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3440 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3441 | } |
| 3442 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3443 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3444 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3445 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3446 | if (!*args[cur_arg + 1]) { |
| 3447 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3448 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3449 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3450 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3451 | } |
| 3452 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3453 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3454 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3455 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3456 | " dots nor does not start with a dot." |
| 3457 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3458 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3459 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3463 | if (err) { |
| 3464 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3465 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3467 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3468 | } |
| 3469 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3470 | if (!curproxy->cookie_domain) { |
| 3471 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3472 | } else { |
| 3473 | /* one domain was already specified, add another one by |
| 3474 | * building the string which will be returned along with |
| 3475 | * the cookie. |
| 3476 | */ |
| 3477 | char *new_ptr; |
| 3478 | int new_len = strlen(curproxy->cookie_domain) + |
| 3479 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3480 | new_ptr = malloc(new_len); |
| 3481 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3482 | free(curproxy->cookie_domain); |
| 3483 | curproxy->cookie_domain = new_ptr; |
| 3484 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3485 | cur_arg++; |
| 3486 | } |
| 3487 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3488 | unsigned int maxidle; |
| 3489 | const char *res; |
| 3490 | |
| 3491 | if (!*args[cur_arg + 1]) { |
| 3492 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3493 | file, linenum, args[cur_arg]); |
| 3494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3495 | goto out; |
| 3496 | } |
| 3497 | |
| 3498 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3499 | if (res) { |
| 3500 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3501 | file, linenum, *res, args[cur_arg]); |
| 3502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3503 | goto out; |
| 3504 | } |
| 3505 | curproxy->cookie_maxidle = maxidle; |
| 3506 | cur_arg++; |
| 3507 | } |
| 3508 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3509 | unsigned int maxlife; |
| 3510 | const char *res; |
| 3511 | |
| 3512 | if (!*args[cur_arg + 1]) { |
| 3513 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3514 | file, linenum, args[cur_arg]); |
| 3515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3516 | goto out; |
| 3517 | } |
| 3518 | |
| 3519 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3520 | if (res) { |
| 3521 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3522 | file, linenum, *res, args[cur_arg]); |
| 3523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3524 | goto out; |
| 3525 | } |
| 3526 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3527 | cur_arg++; |
| 3528 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3529 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3530 | 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] | 3531 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3533 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3534 | } |
| 3535 | cur_arg++; |
| 3536 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3537 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3538 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3539 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3540 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3541 | } |
| 3542 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3543 | 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] | 3544 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3545 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3546 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3547 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3548 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3549 | 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] | 3550 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3551 | file, linenum); |
| 3552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3553 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3554 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3555 | else if (!strcmp(args[0], "email-alert")) { |
| 3556 | if (*(args[1]) == 0) { |
| 3557 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3558 | file, linenum, args[0]); |
| 3559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3560 | goto out; |
| 3561 | } |
| 3562 | |
| 3563 | if (!strcmp(args[1], "from")) { |
| 3564 | if (*(args[1]) == 0) { |
| 3565 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3566 | file, linenum, args[1]); |
| 3567 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3568 | goto out; |
| 3569 | } |
| 3570 | free(curproxy->email_alert.from); |
| 3571 | curproxy->email_alert.from = strdup(args[2]); |
| 3572 | } |
| 3573 | else if (!strcmp(args[1], "mailers")) { |
| 3574 | if (*(args[1]) == 0) { |
| 3575 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3576 | file, linenum, args[1]); |
| 3577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3578 | goto out; |
| 3579 | } |
| 3580 | free(curproxy->email_alert.mailers.name); |
| 3581 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3582 | } |
| 3583 | else if (!strcmp(args[1], "myhostname")) { |
| 3584 | if (*(args[1]) == 0) { |
| 3585 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3586 | file, linenum, args[1]); |
| 3587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3588 | goto out; |
| 3589 | } |
| 3590 | free(curproxy->email_alert.myhostname); |
| 3591 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3592 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3593 | else if (!strcmp(args[1], "level")) { |
| 3594 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3595 | if (curproxy->email_alert.level < 0) { |
| 3596 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3597 | file, linenum, args[1], args[2]); |
| 3598 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3599 | goto out; |
| 3600 | } |
| 3601 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3602 | else if (!strcmp(args[1], "to")) { |
| 3603 | if (*(args[1]) == 0) { |
| 3604 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3605 | file, linenum, args[1]); |
| 3606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3607 | goto out; |
| 3608 | } |
| 3609 | free(curproxy->email_alert.to); |
| 3610 | curproxy->email_alert.to = strdup(args[2]); |
| 3611 | } |
| 3612 | else { |
| 3613 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3614 | file, linenum, args[1]); |
| 3615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3616 | goto out; |
| 3617 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3618 | /* Indicate that the email_alert is at least partially configured */ |
| 3619 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3620 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3621 | else if (!strcmp(args[0], "external-check")) { |
| 3622 | if (*(args[1]) == 0) { |
| 3623 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3624 | file, linenum, args[0]); |
| 3625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3626 | goto out; |
| 3627 | } |
| 3628 | |
| 3629 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3630 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3631 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3632 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3633 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3634 | file, linenum, args[1]); |
| 3635 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3636 | goto out; |
| 3637 | } |
| 3638 | free(curproxy->check_command); |
| 3639 | curproxy->check_command = strdup(args[2]); |
| 3640 | } |
| 3641 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3642 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3643 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3644 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3645 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3646 | file, linenum, args[1]); |
| 3647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3648 | goto out; |
| 3649 | } |
| 3650 | free(curproxy->check_path); |
| 3651 | curproxy->check_path = strdup(args[2]); |
| 3652 | } |
| 3653 | else { |
| 3654 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3655 | file, linenum, args[1]); |
| 3656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3657 | goto out; |
| 3658 | } |
| 3659 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3660 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3661 | if (*(args[1]) == 0) { |
| 3662 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3663 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3665 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3669 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3670 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3671 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3672 | const char *beg, *end; |
| 3673 | |
| 3674 | beg = args[1] + 11; |
| 3675 | end = strchr(beg, ')'); |
| 3676 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3677 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3678 | goto out; |
| 3679 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3680 | if (!end || end == beg) { |
| 3681 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3682 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3683 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3684 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | free(curproxy->rdp_cookie_name); |
| 3688 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3689 | curproxy->rdp_cookie_len = end-beg; |
| 3690 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3691 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3692 | free(curproxy->rdp_cookie_name); |
| 3693 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3694 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3695 | } |
| 3696 | else { /* syntax */ |
| 3697 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3698 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3699 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3700 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | else { |
| 3704 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3705 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3707 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3708 | } |
| 3709 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3710 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3711 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3713 | goto out; |
| 3714 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3715 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3716 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3717 | err_code |= ERR_WARN; |
| 3718 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3719 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3720 | } |
| 3721 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3722 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3723 | } |
| 3724 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3725 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3726 | } |
| 3727 | else { |
| 3728 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3729 | file, linenum, args[0], args[1]); |
| 3730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3731 | goto out; |
| 3732 | } |
| 3733 | } |
| 3734 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3735 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3736 | err_code |= ERR_WARN; |
| 3737 | if (*(args[1]) == 0) { |
| 3738 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3739 | file, linenum, args[0]); |
| 3740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3741 | goto out; |
| 3742 | } |
| 3743 | else if (!strcmp(args[1], "use-backend-name")) |
| 3744 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3745 | else |
| 3746 | curproxy->server_state_file_name = strdup(args[1]); |
| 3747 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3748 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3749 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3750 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3751 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3752 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3753 | if (curproxy == &defproxy) { |
| 3754 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3756 | goto out; |
| 3757 | } |
| 3758 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3759 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3760 | goto out; |
| 3761 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3762 | if (*(args[4]) == 0) { |
| 3763 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3764 | 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 | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3767 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3768 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3769 | curproxy->capture_name = strdup(args[2]); |
| 3770 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3771 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3772 | curproxy->to_log |= LW_COOKIE; |
| 3773 | } |
| 3774 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3775 | struct cap_hdr *hdr; |
| 3776 | |
| 3777 | if (curproxy == &defproxy) { |
| 3778 | 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] | 3779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3781 | } |
| 3782 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3783 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3784 | goto out; |
| 3785 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3786 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3787 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3788 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3790 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3791 | } |
| 3792 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3793 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3794 | hdr->next = curproxy->req_cap; |
| 3795 | hdr->name = strdup(args[3]); |
| 3796 | hdr->namelen = strlen(args[3]); |
| 3797 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3798 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3799 | hdr->index = curproxy->nb_req_cap++; |
| 3800 | curproxy->req_cap = hdr; |
| 3801 | curproxy->to_log |= LW_REQHDR; |
| 3802 | } |
| 3803 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3804 | struct cap_hdr *hdr; |
| 3805 | |
| 3806 | if (curproxy == &defproxy) { |
| 3807 | 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] | 3808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3809 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3810 | } |
| 3811 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3812 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3813 | goto out; |
| 3814 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3815 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3816 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3817 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3819 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3820 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3821 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3822 | hdr->next = curproxy->rsp_cap; |
| 3823 | hdr->name = strdup(args[3]); |
| 3824 | hdr->namelen = strlen(args[3]); |
| 3825 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3826 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3827 | hdr->index = curproxy->nb_rsp_cap++; |
| 3828 | curproxy->rsp_cap = hdr; |
| 3829 | curproxy->to_log |= LW_RSPHDR; |
| 3830 | } |
| 3831 | else { |
| 3832 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3833 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3835 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3836 | } |
| 3837 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3838 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3839 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3840 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3841 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3842 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3843 | goto out; |
| 3844 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3845 | if (*(args[1]) == 0) { |
| 3846 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3847 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3849 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3850 | } |
| 3851 | curproxy->conn_retries = atol(args[1]); |
| 3852 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3853 | 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] | 3854 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3855 | |
| 3856 | if (curproxy == &defproxy) { |
| 3857 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3859 | goto out; |
| 3860 | } |
| 3861 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3862 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3863 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3864 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3865 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3866 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3867 | 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] | 3868 | 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] | 3869 | file, linenum, args[0]); |
| 3870 | err_code |= ERR_WARN; |
| 3871 | } |
| 3872 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3873 | 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] | 3874 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3875 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3876 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3877 | goto out; |
| 3878 | } |
| 3879 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3880 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3881 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3882 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3883 | file, linenum); |
| 3884 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3885 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3886 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3887 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3888 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3889 | |
| 3890 | if (curproxy == &defproxy) { |
| 3891 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3893 | goto out; |
| 3894 | } |
| 3895 | |
| 3896 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3897 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3898 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3899 | 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] | 3900 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3901 | file, linenum, args[0]); |
| 3902 | err_code |= ERR_WARN; |
| 3903 | } |
| 3904 | |
| 3905 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3906 | |
| 3907 | if (!rule) { |
| 3908 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3909 | goto out; |
| 3910 | } |
| 3911 | |
| 3912 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3913 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3914 | file, linenum); |
| 3915 | |
| 3916 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3917 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3918 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3919 | /* set the header name and length into the proxy structure */ |
| 3920 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3921 | err_code |= ERR_WARN; |
| 3922 | |
| 3923 | if (!*args[1]) { |
| 3924 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3925 | file, linenum, args[0]); |
| 3926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3927 | goto out; |
| 3928 | } |
| 3929 | |
| 3930 | /* set the desired header name */ |
| 3931 | free(curproxy->server_id_hdr_name); |
| 3932 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3933 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3934 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3935 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3936 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3937 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3938 | if (curproxy == &defproxy) { |
| 3939 | 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] | 3940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3941 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3942 | } |
| 3943 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3944 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3945 | * be processed before all http-request rules, we put them into their own list |
| 3946 | * and will insert them at the end. |
| 3947 | */ |
| 3948 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3949 | if (!rule) { |
| 3950 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3951 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3952 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3953 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3954 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3955 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3956 | file, linenum); |
| 3957 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3958 | |
| 3959 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3960 | 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]); |
| 3961 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3962 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3963 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3964 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3965 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3966 | if (curproxy == &defproxy) { |
| 3967 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3969 | goto out; |
| 3970 | } |
| 3971 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3972 | 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] | 3973 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3974 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3976 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3977 | } |
| 3978 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3979 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3980 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3981 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3982 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3983 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3984 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3985 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3986 | struct switching_rule *rule; |
| 3987 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3988 | if (curproxy == &defproxy) { |
| 3989 | 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] | 3990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3991 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3992 | } |
| 3993 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3994 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3995 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3996 | |
| 3997 | if (*(args[1]) == 0) { |
| 3998 | 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] | 3999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4000 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4001 | } |
| 4002 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4003 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 4004 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4005 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4006 | file, linenum, errmsg); |
| 4007 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4008 | goto out; |
| 4009 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4010 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4011 | 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] | 4012 | } |
| 4013 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4014 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4015 | rule->cond = cond; |
| 4016 | rule->be.name = strdup(args[1]); |
| 4017 | LIST_INIT(&rule->list); |
| 4018 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4019 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4020 | else if (strcmp(args[0], "use-server") == 0) { |
| 4021 | struct server_rule *rule; |
| 4022 | |
| 4023 | if (curproxy == &defproxy) { |
| 4024 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4026 | goto out; |
| 4027 | } |
| 4028 | |
| 4029 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4030 | err_code |= ERR_WARN; |
| 4031 | |
| 4032 | if (*(args[1]) == 0) { |
| 4033 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 4034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4035 | goto out; |
| 4036 | } |
| 4037 | |
| 4038 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4039 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4040 | file, linenum, args[0]); |
| 4041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4042 | goto out; |
| 4043 | } |
| 4044 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4045 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4046 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4047 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4049 | goto out; |
| 4050 | } |
| 4051 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4052 | 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] | 4053 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4054 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4055 | rule->cond = cond; |
| 4056 | rule->srv.name = strdup(args[1]); |
| 4057 | LIST_INIT(&rule->list); |
| 4058 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4059 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4060 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4061 | else if ((!strcmp(args[0], "force-persist")) || |
| 4062 | (!strcmp(args[0], "ignore-persist"))) { |
| 4063 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4064 | |
| 4065 | if (curproxy == &defproxy) { |
| 4066 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4068 | goto out; |
| 4069 | } |
| 4070 | |
| 4071 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4072 | err_code |= ERR_WARN; |
| 4073 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4074 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4075 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4076 | file, linenum, args[0]); |
| 4077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4078 | goto out; |
| 4079 | } |
| 4080 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4081 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 4082 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4083 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4084 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4085 | goto out; |
| 4086 | } |
| 4087 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4088 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4089 | * where force-persist is applied. |
| 4090 | */ |
| 4091 | 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] | 4092 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4093 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4094 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4095 | if (!strcmp(args[0], "force-persist")) { |
| 4096 | rule->type = PERSIST_TYPE_FORCE; |
| 4097 | } else { |
| 4098 | rule->type = PERSIST_TYPE_IGNORE; |
| 4099 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4100 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4101 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4102 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4103 | else if (!strcmp(args[0], "stick-table")) { |
| 4104 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4105 | struct proxy *other; |
| 4106 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4107 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4108 | if (other) { |
| 4109 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4110 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 4111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4112 | goto out; |
| 4113 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4114 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4115 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4116 | curproxy->table.type = (unsigned int)-1; |
| 4117 | while (*args[myidx]) { |
| 4118 | const char *err; |
| 4119 | |
| 4120 | if (strcmp(args[myidx], "size") == 0) { |
| 4121 | myidx++; |
| 4122 | if (!*(args[myidx])) { |
| 4123 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4124 | file, linenum, args[myidx-1]); |
| 4125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4126 | goto out; |
| 4127 | } |
| 4128 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 4129 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4130 | file, linenum, *err, args[myidx-1]); |
| 4131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4132 | goto out; |
| 4133 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4134 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4135 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4136 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4137 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4138 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4139 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4140 | file, linenum, args[myidx-1]); |
| 4141 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4142 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4143 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4144 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4145 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4146 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4147 | myidx++; |
| 4148 | if (!*(args[myidx])) { |
| 4149 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4150 | file, linenum, args[myidx-1]); |
| 4151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4152 | goto out; |
| 4153 | } |
| 4154 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4155 | if (err) { |
| 4156 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4157 | file, linenum, *err, args[myidx-1]); |
| 4158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4159 | goto out; |
| 4160 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4161 | if (val > INT_MAX) { |
| 4162 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4163 | file, linenum, val); |
| 4164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4165 | goto out; |
| 4166 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4167 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4168 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4169 | } |
| 4170 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4171 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4172 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4173 | } |
| 4174 | else if (strcmp(args[myidx], "type") == 0) { |
| 4175 | myidx++; |
| 4176 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4177 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4178 | file, linenum, args[myidx]); |
| 4179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4180 | goto out; |
| 4181 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4182 | /* myidx already points to next arg */ |
| 4183 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4184 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4185 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4186 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4187 | |
| 4188 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4189 | nw = args[myidx]; |
| 4190 | while (*nw) { |
| 4191 | /* the "store" keyword supports a comma-separated list */ |
| 4192 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4193 | sa = NULL; /* store arg */ |
| 4194 | while (*nw && *nw != ',') { |
| 4195 | if (*nw == '(') { |
| 4196 | *nw = 0; |
| 4197 | sa = ++nw; |
| 4198 | while (*nw != ')') { |
| 4199 | if (!*nw) { |
| 4200 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4201 | file, linenum, args[0], cw); |
| 4202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4203 | goto out; |
| 4204 | } |
| 4205 | nw++; |
| 4206 | } |
| 4207 | *nw = '\0'; |
| 4208 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4209 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4210 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4211 | if (*nw) |
| 4212 | *nw++ = '\0'; |
| 4213 | type = stktable_get_data_type(cw); |
| 4214 | if (type < 0) { |
| 4215 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4216 | file, linenum, args[0], cw); |
| 4217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4218 | goto out; |
| 4219 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4220 | |
| 4221 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4222 | switch (err) { |
| 4223 | case PE_NONE: break; |
| 4224 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4225 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4226 | file, linenum, args[0], cw); |
| 4227 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4228 | break; |
| 4229 | |
| 4230 | case PE_ARG_MISSING: |
| 4231 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4232 | file, linenum, args[0], cw); |
| 4233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4234 | goto out; |
| 4235 | |
| 4236 | case PE_ARG_NOT_USED: |
| 4237 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4238 | file, linenum, args[0], cw); |
| 4239 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4240 | goto out; |
| 4241 | |
| 4242 | default: |
| 4243 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4244 | file, linenum, args[0], cw); |
| 4245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4246 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4247 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4248 | } |
| 4249 | myidx++; |
| 4250 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4251 | else { |
| 4252 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4253 | file, linenum, args[myidx]); |
| 4254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4255 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4256 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | if (!curproxy->table.size) { |
| 4260 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4261 | file, linenum); |
| 4262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4263 | goto out; |
| 4264 | } |
| 4265 | |
| 4266 | if (curproxy->table.type == (unsigned int)-1) { |
| 4267 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4268 | file, linenum); |
| 4269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4270 | goto out; |
| 4271 | } |
| 4272 | } |
| 4273 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4274 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4275 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4276 | int myidx = 0; |
| 4277 | const char *name = NULL; |
| 4278 | int flags; |
| 4279 | |
| 4280 | if (curproxy == &defproxy) { |
| 4281 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
| 4284 | } |
| 4285 | |
| 4286 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4287 | err_code |= ERR_WARN; |
| 4288 | goto out; |
| 4289 | } |
| 4290 | |
| 4291 | myidx++; |
| 4292 | if ((strcmp(args[myidx], "store") == 0) || |
| 4293 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4294 | myidx++; |
| 4295 | flags = STK_IS_STORE; |
| 4296 | } |
| 4297 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4298 | myidx++; |
| 4299 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4300 | } |
| 4301 | else if (strcmp(args[myidx], "match") == 0) { |
| 4302 | myidx++; |
| 4303 | flags = STK_IS_MATCH; |
| 4304 | } |
| 4305 | else if (strcmp(args[myidx], "on") == 0) { |
| 4306 | myidx++; |
| 4307 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4308 | } |
| 4309 | else { |
| 4310 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4312 | goto out; |
| 4313 | } |
| 4314 | |
| 4315 | if (*(args[myidx]) == 0) { |
| 4316 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4318 | goto out; |
| 4319 | } |
| 4320 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4321 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4322 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4323 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4324 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4325 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4326 | goto out; |
| 4327 | } |
| 4328 | |
| 4329 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4330 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4331 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4332 | 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] | 4333 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4334 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4335 | goto out; |
| 4336 | } |
| 4337 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4338 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4339 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4340 | 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] | 4341 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4342 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4343 | goto out; |
| 4344 | } |
| 4345 | } |
| 4346 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4347 | /* 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] | 4348 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4349 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4350 | if (strcmp(args[myidx], "table") == 0) { |
| 4351 | myidx++; |
| 4352 | name = args[myidx++]; |
| 4353 | } |
| 4354 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4355 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4356 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4357 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4358 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4359 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4360 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4361 | goto out; |
| 4362 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4363 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4364 | else if (*(args[myidx])) { |
| 4365 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4366 | file, linenum, args[0], args[myidx]); |
| 4367 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4368 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4369 | goto out; |
| 4370 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4371 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4372 | 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] | 4373 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4374 | 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] | 4375 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4376 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4377 | rule->cond = cond; |
| 4378 | rule->expr = expr; |
| 4379 | rule->flags = flags; |
| 4380 | rule->table.name = name ? strdup(name) : NULL; |
| 4381 | LIST_INIT(&rule->list); |
| 4382 | if (flags & STK_ON_RSP) |
| 4383 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4384 | else |
| 4385 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4386 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4387 | else if (!strcmp(args[0], "stats")) { |
| 4388 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4389 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4390 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4391 | if (!*args[1]) { |
| 4392 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4393 | } else if (!strcmp(args[1], "admin")) { |
| 4394 | struct stats_admin_rule *rule; |
| 4395 | |
| 4396 | if (curproxy == &defproxy) { |
| 4397 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4399 | goto out; |
| 4400 | } |
| 4401 | |
| 4402 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4403 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4404 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4405 | goto out; |
| 4406 | } |
| 4407 | |
| 4408 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4409 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4410 | file, linenum, args[0], args[1]); |
| 4411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4412 | goto out; |
| 4413 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4414 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4415 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4416 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4418 | goto out; |
| 4419 | } |
| 4420 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4421 | err_code |= warnif_cond_conflicts(cond, |
| 4422 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4423 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4424 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4425 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4426 | rule->cond = cond; |
| 4427 | LIST_INIT(&rule->list); |
| 4428 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4429 | } else if (!strcmp(args[1], "uri")) { |
| 4430 | if (*(args[2]) == 0) { |
| 4431 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4433 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4434 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4435 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4436 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4437 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4438 | } |
| 4439 | } else if (!strcmp(args[1], "realm")) { |
| 4440 | if (*(args[2]) == 0) { |
| 4441 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4443 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4444 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4445 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4446 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4448 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4449 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4450 | unsigned interval; |
| 4451 | |
| 4452 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4453 | if (err) { |
| 4454 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4455 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4457 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4458 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4459 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4460 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4461 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4462 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4463 | } 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] | 4464 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4465 | |
| 4466 | if (curproxy == &defproxy) { |
| 4467 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4469 | goto out; |
| 4470 | } |
| 4471 | |
| 4472 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4473 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4474 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4475 | goto out; |
| 4476 | } |
| 4477 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4478 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4479 | !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] | 4480 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4481 | file, linenum, args[0]); |
| 4482 | err_code |= ERR_WARN; |
| 4483 | } |
| 4484 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4485 | 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] | 4486 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4487 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4488 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4489 | goto out; |
| 4490 | } |
| 4491 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4492 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4493 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4494 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4495 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4496 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4497 | } else if (!strcmp(args[1], "auth")) { |
| 4498 | if (*(args[2]) == 0) { |
| 4499 | 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] | 4500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4501 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4502 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4503 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4504 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4505 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4506 | } |
| 4507 | } else if (!strcmp(args[1], "scope")) { |
| 4508 | if (*(args[2]) == 0) { |
| 4509 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4512 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4513 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4514 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4515 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4516 | } |
| 4517 | } else if (!strcmp(args[1], "enable")) { |
| 4518 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4519 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4520 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4521 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4522 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4523 | } else if (!strcmp(args[1], "hide-version")) { |
| 4524 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4525 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4526 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4527 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4528 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4529 | } else if (!strcmp(args[1], "show-legends")) { |
| 4530 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4531 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4532 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4533 | goto out; |
| 4534 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4535 | } else if (!strcmp(args[1], "show-node")) { |
| 4536 | |
| 4537 | if (*args[2]) { |
| 4538 | int i; |
| 4539 | char c; |
| 4540 | |
| 4541 | for (i=0; args[2][i]; i++) { |
| 4542 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4543 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4544 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4545 | break; |
| 4546 | } |
| 4547 | |
| 4548 | if (!i || args[2][i]) { |
| 4549 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4550 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4551 | file, linenum, args[0], args[1]); |
| 4552 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4553 | goto out; |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4558 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4559 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4560 | goto out; |
| 4561 | } |
| 4562 | } else if (!strcmp(args[1], "show-desc")) { |
| 4563 | char *desc = NULL; |
| 4564 | |
| 4565 | if (*args[2]) { |
| 4566 | int i, len=0; |
| 4567 | char *d; |
| 4568 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4569 | for (i = 2; *args[i]; i++) |
| 4570 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4571 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4572 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4573 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4574 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4575 | for (i = 3; *args[i]; i++) |
| 4576 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | if (!*args[2] && !global.desc) |
| 4580 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4581 | file, linenum, args[1]); |
| 4582 | else { |
| 4583 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4584 | free(desc); |
| 4585 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4586 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4587 | goto out; |
| 4588 | } |
| 4589 | free(desc); |
| 4590 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4591 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4592 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4593 | 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] | 4594 | 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] | 4595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4596 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4600 | int optnum; |
| 4601 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4602 | if (*(args[1]) == '\0') { |
| 4603 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4604 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4606 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4607 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4608 | |
| 4609 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4610 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4611 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4612 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4613 | file, linenum, cfg_opts[optnum].name); |
| 4614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4615 | goto out; |
| 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 | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4620 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4621 | err_code |= ERR_WARN; |
| 4622 | goto out; |
| 4623 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4624 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4625 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4626 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4627 | |
| 4628 | switch (kwm) { |
| 4629 | case KWM_STD: |
| 4630 | curproxy->options |= cfg_opts[optnum].val; |
| 4631 | break; |
| 4632 | case KWM_NO: |
| 4633 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4634 | break; |
| 4635 | case KWM_DEF: /* already cleared */ |
| 4636 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4637 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4638 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4639 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4643 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4644 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4645 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4646 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4647 | file, linenum, cfg_opts2[optnum].name); |
| 4648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4649 | goto out; |
| 4650 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4651 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4652 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4653 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4654 | err_code |= ERR_WARN; |
| 4655 | goto out; |
| 4656 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4657 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4658 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4659 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4660 | |
| 4661 | switch (kwm) { |
| 4662 | case KWM_STD: |
| 4663 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4664 | break; |
| 4665 | case KWM_NO: |
| 4666 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4667 | break; |
| 4668 | case KWM_DEF: /* already cleared */ |
| 4669 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4670 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4671 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4672 | } |
| 4673 | } |
| 4674 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4675 | /* HTTP options override each other. They can be cancelled using |
| 4676 | * "no option xxx" which only switches to default mode if the mode |
| 4677 | * was this one (useful for cancelling options set in defaults |
| 4678 | * sections). |
| 4679 | */ |
| 4680 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4681 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4682 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4683 | if (kwm == KWM_STD) { |
| 4684 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4685 | curproxy->options |= PR_O_HTTP_PCL; |
| 4686 | goto out; |
| 4687 | } |
| 4688 | else if (kwm == KWM_NO) { |
| 4689 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4690 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4691 | goto out; |
| 4692 | } |
| 4693 | } |
| 4694 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4695 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4696 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4697 | if (kwm == KWM_STD) { |
| 4698 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4699 | curproxy->options |= PR_O_HTTP_FCL; |
| 4700 | goto out; |
| 4701 | } |
| 4702 | else if (kwm == KWM_NO) { |
| 4703 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4704 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4705 | goto out; |
| 4706 | } |
| 4707 | } |
| 4708 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4709 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4710 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4711 | if (kwm == KWM_STD) { |
| 4712 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4713 | curproxy->options |= PR_O_HTTP_SCL; |
| 4714 | goto out; |
| 4715 | } |
| 4716 | else if (kwm == KWM_NO) { |
| 4717 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4718 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4719 | goto out; |
| 4720 | } |
| 4721 | } |
| 4722 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4723 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4724 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4725 | if (kwm == KWM_STD) { |
| 4726 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4727 | curproxy->options |= PR_O_HTTP_KAL; |
| 4728 | goto out; |
| 4729 | } |
| 4730 | else if (kwm == KWM_NO) { |
| 4731 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4732 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4733 | goto out; |
| 4734 | } |
| 4735 | } |
| 4736 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4737 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4738 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4739 | if (kwm == KWM_STD) { |
| 4740 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4741 | curproxy->options |= PR_O_HTTP_TUN; |
| 4742 | goto out; |
| 4743 | } |
| 4744 | else if (kwm == KWM_NO) { |
| 4745 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4746 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4747 | goto out; |
| 4748 | } |
| 4749 | } |
| 4750 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4751 | /* Redispatch can take an integer argument that control when the |
| 4752 | * resispatch occurs. All values are relative to the retries option. |
| 4753 | * This can be cancelled using "no option xxx". |
| 4754 | */ |
| 4755 | if (strcmp(args[1], "redispatch") == 0) { |
| 4756 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4757 | err_code |= ERR_WARN; |
| 4758 | goto out; |
| 4759 | } |
| 4760 | |
| 4761 | curproxy->no_options &= ~PR_O_REDISP; |
| 4762 | curproxy->options &= ~PR_O_REDISP; |
| 4763 | |
| 4764 | switch (kwm) { |
| 4765 | case KWM_STD: |
| 4766 | curproxy->options |= PR_O_REDISP; |
| 4767 | curproxy->redispatch_after = -1; |
| 4768 | if(*args[2]) { |
| 4769 | curproxy->redispatch_after = atol(args[2]); |
| 4770 | } |
| 4771 | break; |
| 4772 | case KWM_NO: |
| 4773 | curproxy->no_options |= PR_O_REDISP; |
| 4774 | curproxy->redispatch_after = 0; |
| 4775 | break; |
| 4776 | case KWM_DEF: /* already cleared */ |
| 4777 | break; |
| 4778 | } |
| 4779 | goto out; |
| 4780 | } |
| 4781 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4782 | if (kwm != KWM_STD) { |
| 4783 | 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] | 4784 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4786 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4787 | } |
| 4788 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4789 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4790 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4791 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4792 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4793 | if (*(args[2]) != '\0') { |
| 4794 | if (!strcmp(args[2], "clf")) { |
| 4795 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4796 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4797 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4798 | 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] | 4799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4800 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4801 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4802 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4803 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4804 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4805 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4806 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4807 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4808 | free(curproxy->conf.logformat_string); |
| 4809 | curproxy->conf.logformat_string = logformat; |
| 4810 | |
| 4811 | free(curproxy->conf.lfs_file); |
| 4812 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4813 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4814 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4815 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4816 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4817 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4818 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4819 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4820 | free(curproxy->conf.logformat_string); |
| 4821 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4822 | |
| 4823 | free(curproxy->conf.lfs_file); |
| 4824 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4825 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4826 | |
| 4827 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4828 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4829 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4830 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4831 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4832 | 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] | 4833 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4834 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4835 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4836 | goto out; |
| 4837 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4838 | if (curproxy->cap & PR_CAP_FE) |
| 4839 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4840 | if (curproxy->cap & PR_CAP_BE) |
| 4841 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4842 | } |
| 4843 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4844 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4845 | err_code |= ERR_WARN; |
| 4846 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4847 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4848 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4849 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4850 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4851 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4852 | if (!*args[2]) { /* no argument */ |
| 4853 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4854 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4855 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4856 | 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] | 4857 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4858 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4859 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4860 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4861 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | if (*args[4]) |
| 4863 | reqlen += strlen(args[4]); |
| 4864 | else |
| 4865 | reqlen += strlen("HTTP/1.0"); |
| 4866 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4867 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4868 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4869 | "%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] | 4870 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4871 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4872 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4873 | } |
| 4874 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4875 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4876 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4877 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4878 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4879 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4880 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4881 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4882 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4883 | |
| 4884 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4885 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4886 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4887 | else if (!strcmp(args[1], "smtpchk")) { |
| 4888 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4889 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4890 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4891 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4892 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4893 | |
| 4894 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4895 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4896 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4897 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4898 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4899 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4900 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4901 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4902 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4903 | } else { |
| 4904 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4905 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4906 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4907 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4908 | } |
| 4909 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4910 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4911 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4912 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4913 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4914 | /* use PostgreSQL request to check servers' health */ |
| 4915 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4916 | err_code |= ERR_WARN; |
| 4917 | |
| 4918 | free(curproxy->check_req); |
| 4919 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4920 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4921 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4922 | |
| 4923 | if (*(args[2])) { |
| 4924 | int cur_arg = 2; |
| 4925 | |
| 4926 | while (*(args[cur_arg])) { |
| 4927 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4928 | char * packet; |
| 4929 | uint32_t packet_len; |
| 4930 | uint32_t pv; |
| 4931 | |
| 4932 | /* suboption header - needs additional argument for it */ |
| 4933 | if (*(args[cur_arg+1]) == 0) { |
| 4934 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4935 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4937 | goto out; |
| 4938 | } |
| 4939 | |
| 4940 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4941 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4942 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4943 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4944 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4945 | |
| 4946 | memcpy(packet + 4, &pv, 4); |
| 4947 | |
| 4948 | /* copy "user" */ |
| 4949 | memcpy(packet + 8, "user", 4); |
| 4950 | |
| 4951 | /* copy username */ |
| 4952 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4953 | |
| 4954 | free(curproxy->check_req); |
| 4955 | curproxy->check_req = packet; |
| 4956 | curproxy->check_len = packet_len; |
| 4957 | |
| 4958 | packet_len = htonl(packet_len); |
| 4959 | memcpy(packet, &packet_len, 4); |
| 4960 | cur_arg += 2; |
| 4961 | } else { |
| 4962 | /* unknown suboption - catchall */ |
| 4963 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4964 | file, linenum, args[0], args[1]); |
| 4965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4966 | goto out; |
| 4967 | } |
| 4968 | } /* end while loop */ |
| 4969 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4970 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4971 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4974 | else if (!strcmp(args[1], "redis-check")) { |
| 4975 | /* use REDIS PING request to check servers' health */ |
| 4976 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4977 | err_code |= ERR_WARN; |
| 4978 | |
| 4979 | free(curproxy->check_req); |
| 4980 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4981 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4982 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4983 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4984 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4985 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4986 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4987 | |
| 4988 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4989 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4990 | } |
| 4991 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4992 | else if (!strcmp(args[1], "mysql-check")) { |
| 4993 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4994 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4995 | err_code |= ERR_WARN; |
| 4996 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4997 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4998 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4999 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5000 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5001 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5002 | /* 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] | 5003 | * const char mysql40_client_auth_pkt[] = { |
| 5004 | * "\x0e\x00\x00" // packet length |
| 5005 | * "\x01" // packet number |
| 5006 | * "\x00\x00" // client capabilities |
| 5007 | * "\x00\x00\x01" // max packet |
| 5008 | * "haproxy\x00" // username (null terminated string) |
| 5009 | * "\x00" // filler (always 0x00) |
| 5010 | * "\x01\x00\x00" // packet length |
| 5011 | * "\x00" // packet number |
| 5012 | * "\x01" // COM_QUIT command |
| 5013 | * }; |
| 5014 | */ |
| 5015 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5016 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5017 | * const char mysql41_client_auth_pkt[] = { |
| 5018 | * "\x0e\x00\x00\" // packet length |
| 5019 | * "\x01" // packet number |
| 5020 | * "\x00\x00\x00\x00" // client capabilities |
| 5021 | * "\x00\x00\x00\x01" // max packet |
| 5022 | * "\x21" // character set (UTF-8) |
| 5023 | * char[23] // All zeroes |
| 5024 | * "haproxy\x00" // username (null terminated string) |
| 5025 | * "\x00" // filler (always 0x00) |
| 5026 | * "\x01\x00\x00" // packet length |
| 5027 | * "\x00" // packet number |
| 5028 | * "\x01" // COM_QUIT command |
| 5029 | * }; |
| 5030 | */ |
| 5031 | |
| 5032 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5033 | if (*(args[2])) { |
| 5034 | int cur_arg = 2; |
| 5035 | |
| 5036 | while (*(args[cur_arg])) { |
| 5037 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5038 | char *mysqluser; |
| 5039 | int packetlen, reqlen, userlen; |
| 5040 | |
| 5041 | /* suboption header - needs additional argument for it */ |
| 5042 | if (*(args[cur_arg+1]) == 0) { |
| 5043 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5044 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5046 | goto out; |
| 5047 | } |
| 5048 | mysqluser = args[cur_arg + 1]; |
| 5049 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5050 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5051 | if (*(args[cur_arg+2])) { |
| 5052 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5053 | packetlen = userlen + 7 + 27; |
| 5054 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5055 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5056 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5057 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5058 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5059 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5060 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5061 | ((unsigned char) packetlen & 0xff), |
| 5062 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5063 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5064 | |
| 5065 | curproxy->check_req[3] = 1; |
| 5066 | curproxy->check_req[5] = 130; |
| 5067 | curproxy->check_req[11] = 1; |
| 5068 | curproxy->check_req[12] = 33; |
| 5069 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5070 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5071 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5072 | cur_arg += 3; |
| 5073 | } else { |
| 5074 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 5075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5076 | goto out; |
| 5077 | } |
| 5078 | } else { |
| 5079 | packetlen = userlen + 7; |
| 5080 | reqlen = packetlen + 9; |
| 5081 | |
| 5082 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5083 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5084 | curproxy->check_len = reqlen; |
| 5085 | |
| 5086 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5087 | ((unsigned char) packetlen & 0xff), |
| 5088 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5089 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5090 | |
| 5091 | curproxy->check_req[3] = 1; |
| 5092 | curproxy->check_req[5] = 128; |
| 5093 | curproxy->check_req[8] = 1; |
| 5094 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5095 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5096 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5097 | cur_arg += 2; |
| 5098 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5099 | } else { |
| 5100 | /* unknown suboption - catchall */ |
| 5101 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5102 | file, linenum, args[0], args[1]); |
| 5103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5104 | goto out; |
| 5105 | } |
| 5106 | } /* end while loop */ |
| 5107 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5108 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5109 | else if (!strcmp(args[1], "ldap-check")) { |
| 5110 | /* use LDAP request to check servers' health */ |
| 5111 | free(curproxy->check_req); |
| 5112 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5113 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5114 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5115 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5116 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5117 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5118 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5119 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5120 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5121 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5122 | else if (!strcmp(args[1], "spop-check")) { |
| 5123 | if (curproxy == &defproxy) { |
| 5124 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5125 | file, linenum, args[0], args[1]); |
| 5126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5127 | goto out; |
| 5128 | } |
| 5129 | if (curproxy->cap & PR_CAP_FE) { |
| 5130 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5131 | file, linenum, args[0], args[1]); |
| 5132 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5133 | goto out; |
| 5134 | } |
| 5135 | |
| 5136 | /* use SPOE request to check servers' health */ |
| 5137 | free(curproxy->check_req); |
| 5138 | curproxy->check_req = NULL; |
| 5139 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5140 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5141 | |
| 5142 | if (prepare_spoe_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
| 5143 | Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
| 5144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5145 | goto out; |
| 5146 | } |
| 5147 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5148 | goto out; |
| 5149 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5150 | else if (!strcmp(args[1], "tcp-check")) { |
| 5151 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5152 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5153 | err_code |= ERR_WARN; |
| 5154 | |
| 5155 | free(curproxy->check_req); |
| 5156 | curproxy->check_req = NULL; |
| 5157 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5158 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5159 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5160 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5161 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5162 | else if (!strcmp(args[1], "external-check")) { |
| 5163 | /* excute an external command to check servers' health */ |
| 5164 | free(curproxy->check_req); |
| 5165 | curproxy->check_req = NULL; |
| 5166 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5167 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5168 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5169 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5170 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5171 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5172 | int cur_arg; |
| 5173 | |
| 5174 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5175 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5176 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5177 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5178 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5179 | |
| 5180 | free(curproxy->fwdfor_hdr_name); |
| 5181 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5182 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5183 | |
| 5184 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5185 | cur_arg = 2; |
| 5186 | while (*(args[cur_arg])) { |
| 5187 | if (!strcmp(args[cur_arg], "except")) { |
| 5188 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5189 | 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] | 5190 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5191 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5193 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5194 | } |
| 5195 | /* flush useless bits */ |
| 5196 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5197 | cur_arg += 2; |
| 5198 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5199 | /* suboption header - needs additional argument for it */ |
| 5200 | if (*(args[cur_arg+1]) == 0) { |
| 5201 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5202 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5204 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5205 | } |
| 5206 | free(curproxy->fwdfor_hdr_name); |
| 5207 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5208 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5209 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5210 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5211 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5212 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5213 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5214 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5215 | 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] | 5216 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5218 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5219 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5220 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5221 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5222 | else if (!strcmp(args[1], "originalto")) { |
| 5223 | int cur_arg; |
| 5224 | |
| 5225 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5226 | * set default options (ie: bitfield, header name, etc) |
| 5227 | */ |
| 5228 | |
| 5229 | curproxy->options |= PR_O_ORGTO; |
| 5230 | |
| 5231 | free(curproxy->orgto_hdr_name); |
| 5232 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5233 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5234 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5235 | /* 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] | 5236 | cur_arg = 2; |
| 5237 | while (*(args[cur_arg])) { |
| 5238 | if (!strcmp(args[cur_arg], "except")) { |
| 5239 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5240 | 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] | 5241 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5242 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5244 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5245 | } |
| 5246 | /* flush useless bits */ |
| 5247 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5248 | cur_arg += 2; |
| 5249 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5250 | /* suboption header - needs additional argument for it */ |
| 5251 | if (*(args[cur_arg+1]) == 0) { |
| 5252 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5253 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5255 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5256 | } |
| 5257 | free(curproxy->orgto_hdr_name); |
| 5258 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5259 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5260 | cur_arg += 2; |
| 5261 | } else { |
| 5262 | /* unknown suboption - catchall */ |
| 5263 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5264 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5266 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5267 | } |
| 5268 | } /* end while loop */ |
| 5269 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5270 | else { |
| 5271 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5273 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5274 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5275 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5276 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5277 | else if (!strcmp(args[0], "default_backend")) { |
| 5278 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5279 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5280 | |
| 5281 | if (*(args[1]) == 0) { |
| 5282 | 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] | 5283 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5284 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5285 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5286 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5287 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5288 | |
| 5289 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5290 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5291 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5292 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5293 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5294 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5295 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5296 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5297 | 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] | 5298 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5299 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5300 | /* enable reconnections to dispatch */ |
| 5301 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5302 | |
| 5303 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5304 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5305 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5306 | else if (!strcmp(args[0], "http-reuse")) { |
| 5307 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5308 | err_code |= ERR_WARN; |
| 5309 | |
| 5310 | if (strcmp(args[1], "never") == 0) { |
| 5311 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5312 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5313 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5314 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5315 | goto out; |
| 5316 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5317 | else if (strcmp(args[1], "safe") == 0) { |
| 5318 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5319 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5320 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5321 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5322 | goto out; |
| 5323 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5324 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5325 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5326 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5327 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5328 | goto out; |
| 5329 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5330 | else if (strcmp(args[1], "always") == 0) { |
| 5331 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5332 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5333 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5334 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5335 | goto out; |
| 5336 | } |
| 5337 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5338 | 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] | 5339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5340 | goto out; |
| 5341 | } |
| 5342 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5343 | else if (!strcmp(args[0], "http-check")) { |
| 5344 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5345 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5346 | |
| 5347 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5348 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5349 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5350 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5351 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5352 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5353 | else if (strcmp(args[1], "send-state") == 0) { |
| 5354 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5355 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5356 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5357 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5358 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5359 | else if (strcmp(args[1], "expect") == 0) { |
| 5360 | const char *ptr_arg; |
| 5361 | int cur_arg; |
| 5362 | |
| 5363 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5364 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5366 | goto out; |
| 5367 | } |
| 5368 | |
| 5369 | cur_arg = 2; |
| 5370 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5371 | while (*(ptr_arg = args[cur_arg])) { |
| 5372 | while (*ptr_arg == '!') { |
| 5373 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5374 | ptr_arg++; |
| 5375 | } |
| 5376 | if (*ptr_arg) |
| 5377 | break; |
| 5378 | cur_arg++; |
| 5379 | } |
| 5380 | /* now ptr_arg points to the beginning of a word past any possible |
| 5381 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5382 | */ |
| 5383 | if (strcmp(ptr_arg, "status") == 0) { |
| 5384 | if (!*(args[cur_arg + 1])) { |
| 5385 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5386 | file, linenum, args[0], args[1], ptr_arg); |
| 5387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5388 | goto out; |
| 5389 | } |
| 5390 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5391 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5392 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5393 | } |
| 5394 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5395 | if (!*(args[cur_arg + 1])) { |
| 5396 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5397 | file, linenum, args[0], args[1], ptr_arg); |
| 5398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5399 | goto out; |
| 5400 | } |
| 5401 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5402 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5403 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5404 | } |
| 5405 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5406 | if (!*(args[cur_arg + 1])) { |
| 5407 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5408 | file, linenum, args[0], args[1], ptr_arg); |
| 5409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5410 | goto out; |
| 5411 | } |
| 5412 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5413 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5414 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5415 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5416 | free(curproxy->expect_regex); |
| 5417 | curproxy->expect_regex = NULL; |
| 5418 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5419 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5420 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5421 | error = NULL; |
| 5422 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5423 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5424 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5425 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5427 | goto out; |
| 5428 | } |
| 5429 | } |
| 5430 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5431 | if (!*(args[cur_arg + 1])) { |
| 5432 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5433 | file, linenum, args[0], args[1], ptr_arg); |
| 5434 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5435 | goto out; |
| 5436 | } |
| 5437 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5438 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5439 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5440 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5441 | free(curproxy->expect_regex); |
| 5442 | curproxy->expect_regex = NULL; |
| 5443 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5444 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5445 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5446 | error = NULL; |
| 5447 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5448 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5449 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5450 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5451 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5452 | goto out; |
| 5453 | } |
| 5454 | } |
| 5455 | else { |
| 5456 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5457 | file, linenum, args[0], args[1], ptr_arg); |
| 5458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5459 | goto out; |
| 5460 | } |
| 5461 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5462 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5463 | 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] | 5464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5465 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5466 | } |
| 5467 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5468 | else if (!strcmp(args[0], "tcp-check")) { |
| 5469 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5470 | err_code |= ERR_WARN; |
| 5471 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5472 | if (strcmp(args[1], "comment") == 0) { |
| 5473 | int cur_arg; |
| 5474 | struct tcpcheck_rule *tcpcheck; |
| 5475 | |
| 5476 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5477 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5478 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5479 | |
| 5480 | if (!*args[cur_arg + 1]) { |
| 5481 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5482 | file, linenum, args[cur_arg]); |
| 5483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5484 | goto out; |
| 5485 | } |
| 5486 | |
| 5487 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5488 | |
| 5489 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5490 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5491 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5492 | } |
| 5493 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5494 | const char *ptr_arg; |
| 5495 | int cur_arg; |
| 5496 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5497 | |
| 5498 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5499 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5500 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5501 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5502 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5503 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5504 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5505 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5506 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5507 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5508 | file, linenum); |
| 5509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5510 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5514 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5515 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5516 | |
| 5517 | /* parsing each parameters to fill up the rule */ |
| 5518 | while (*(ptr_arg = args[cur_arg])) { |
| 5519 | /* tcp port */ |
| 5520 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5521 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5522 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5523 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5524 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5525 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5526 | goto out; |
| 5527 | } |
| 5528 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5529 | cur_arg += 2; |
| 5530 | } |
| 5531 | /* send proxy protocol */ |
| 5532 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5533 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5534 | cur_arg++; |
| 5535 | } |
| 5536 | #ifdef USE_OPENSSL |
| 5537 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5538 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5539 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5540 | cur_arg++; |
| 5541 | } |
| 5542 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5543 | /* comment for this tcpcheck line */ |
| 5544 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5545 | if (!*args[cur_arg + 1]) { |
| 5546 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5547 | file, linenum, args[cur_arg]); |
| 5548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5549 | goto out; |
| 5550 | } |
| 5551 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5552 | cur_arg += 2; |
| 5553 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5554 | else { |
| 5555 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5556 | 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] | 5557 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5558 | 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] | 5559 | #endif /* USE_OPENSSL */ |
| 5560 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5562 | goto out; |
| 5563 | } |
| 5564 | |
| 5565 | } |
| 5566 | |
| 5567 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5568 | } |
| 5569 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5570 | if (! *(args[2]) ) { |
| 5571 | /* SEND string expected */ |
| 5572 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5573 | file, linenum, args[0], args[1], args[2]); |
| 5574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5575 | goto out; |
| 5576 | } else { |
| 5577 | struct tcpcheck_rule *tcpcheck; |
| 5578 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5579 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5580 | |
| 5581 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5582 | tcpcheck->string_len = strlen(args[2]); |
| 5583 | tcpcheck->string = strdup(args[2]); |
| 5584 | tcpcheck->expect_regex = NULL; |
| 5585 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5586 | /* comment for this tcpcheck line */ |
| 5587 | if (strcmp(args[3], "comment") == 0) { |
| 5588 | if (!*args[4]) { |
| 5589 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5590 | file, linenum, args[3]); |
| 5591 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5592 | goto out; |
| 5593 | } |
| 5594 | tcpcheck->comment = strdup(args[4]); |
| 5595 | } |
| 5596 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5597 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5598 | } |
| 5599 | } |
| 5600 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5601 | if (! *(args[2]) ) { |
| 5602 | /* SEND binary string expected */ |
| 5603 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5604 | file, linenum, args[0], args[1], args[2]); |
| 5605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5606 | goto out; |
| 5607 | } else { |
| 5608 | struct tcpcheck_rule *tcpcheck; |
| 5609 | char *err = NULL; |
| 5610 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5611 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5612 | |
| 5613 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5614 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5615 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5616 | file, linenum, args[0], args[1], args[2], err); |
| 5617 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5618 | goto out; |
| 5619 | } |
| 5620 | tcpcheck->expect_regex = NULL; |
| 5621 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5622 | /* comment for this tcpcheck line */ |
| 5623 | if (strcmp(args[3], "comment") == 0) { |
| 5624 | if (!*args[4]) { |
| 5625 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5626 | file, linenum, args[3]); |
| 5627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5628 | goto out; |
| 5629 | } |
| 5630 | tcpcheck->comment = strdup(args[4]); |
| 5631 | } |
| 5632 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5633 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5634 | } |
| 5635 | } |
| 5636 | else if (strcmp(args[1], "expect") == 0) { |
| 5637 | const char *ptr_arg; |
| 5638 | int cur_arg; |
| 5639 | int inverse = 0; |
| 5640 | |
| 5641 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5642 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5644 | goto out; |
| 5645 | } |
| 5646 | |
| 5647 | cur_arg = 2; |
| 5648 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5649 | while (*(ptr_arg = args[cur_arg])) { |
| 5650 | while (*ptr_arg == '!') { |
| 5651 | inverse = !inverse; |
| 5652 | ptr_arg++; |
| 5653 | } |
| 5654 | if (*ptr_arg) |
| 5655 | break; |
| 5656 | cur_arg++; |
| 5657 | } |
| 5658 | /* now ptr_arg points to the beginning of a word past any possible |
| 5659 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5660 | */ |
| 5661 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5662 | struct tcpcheck_rule *tcpcheck; |
| 5663 | char *err = NULL; |
| 5664 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5665 | if (!*(args[cur_arg + 1])) { |
| 5666 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5667 | file, linenum, args[0], args[1], ptr_arg); |
| 5668 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5669 | goto out; |
| 5670 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5671 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5672 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5673 | |
| 5674 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5675 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5676 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5677 | file, linenum, args[0], args[1], args[2], err); |
| 5678 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5679 | goto out; |
| 5680 | } |
| 5681 | tcpcheck->expect_regex = NULL; |
| 5682 | tcpcheck->inverse = inverse; |
| 5683 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5684 | /* tcpcheck comment */ |
| 5685 | cur_arg += 2; |
| 5686 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5687 | if (!*args[cur_arg + 1]) { |
| 5688 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5689 | file, linenum, args[cur_arg + 1]); |
| 5690 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5691 | goto out; |
| 5692 | } |
| 5693 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5694 | } |
| 5695 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5696 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5697 | } |
| 5698 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5699 | struct tcpcheck_rule *tcpcheck; |
| 5700 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5701 | if (!*(args[cur_arg + 1])) { |
| 5702 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5703 | file, linenum, args[0], args[1], ptr_arg); |
| 5704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5705 | goto out; |
| 5706 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5707 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5708 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5709 | |
| 5710 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5711 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5712 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5713 | tcpcheck->expect_regex = NULL; |
| 5714 | tcpcheck->inverse = inverse; |
| 5715 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5716 | /* tcpcheck comment */ |
| 5717 | cur_arg += 2; |
| 5718 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5719 | if (!*args[cur_arg + 1]) { |
| 5720 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5721 | file, linenum, args[cur_arg + 1]); |
| 5722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5723 | goto out; |
| 5724 | } |
| 5725 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5726 | } |
| 5727 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5728 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5729 | } |
| 5730 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5731 | struct tcpcheck_rule *tcpcheck; |
| 5732 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5733 | if (!*(args[cur_arg + 1])) { |
| 5734 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5735 | file, linenum, args[0], args[1], ptr_arg); |
| 5736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5737 | goto out; |
| 5738 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5739 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5740 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5741 | |
| 5742 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5743 | tcpcheck->string_len = 0; |
| 5744 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5745 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5746 | error = NULL; |
| 5747 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5748 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5749 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5750 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5752 | goto out; |
| 5753 | } |
| 5754 | tcpcheck->inverse = inverse; |
| 5755 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5756 | /* tcpcheck comment */ |
| 5757 | cur_arg += 2; |
| 5758 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5759 | if (!*args[cur_arg + 1]) { |
| 5760 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5761 | file, linenum, args[cur_arg + 1]); |
| 5762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5763 | goto out; |
| 5764 | } |
| 5765 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5766 | } |
| 5767 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5768 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5769 | } |
| 5770 | else { |
| 5771 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5772 | file, linenum, args[0], args[1], ptr_arg); |
| 5773 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5774 | goto out; |
| 5775 | } |
| 5776 | } |
| 5777 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5778 | 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] | 5779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5780 | goto out; |
| 5781 | } |
| 5782 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5783 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5784 | if (curproxy == &defproxy) { |
| 5785 | 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] | 5786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5787 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5788 | } |
| 5789 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5790 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5791 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5792 | |
| 5793 | if (strcmp(args[1], "fail") == 0) { |
| 5794 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5795 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5796 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5797 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5799 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5800 | } |
| 5801 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5802 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5803 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5804 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5806 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5807 | } |
| 5808 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5809 | } |
| 5810 | else { |
| 5811 | 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] | 5812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5813 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5814 | } |
| 5815 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5816 | #ifdef TPROXY |
| 5817 | else if (!strcmp(args[0], "transparent")) { |
| 5818 | /* enable transparent proxy connections */ |
| 5819 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5820 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5821 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5822 | } |
| 5823 | #endif |
| 5824 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5825 | 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] | 5826 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5827 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5828 | if (*(args[1]) == 0) { |
| 5829 | 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] | 5830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5831 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5832 | } |
| 5833 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5834 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5835 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5836 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5837 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5838 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5839 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5840 | |
| 5841 | if (*(args[1]) == 0) { |
| 5842 | 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] | 5843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5844 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5845 | } |
| 5846 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5847 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5848 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5849 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5850 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5851 | 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] | 5852 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5853 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5854 | if (*(args[1]) == 0) { |
| 5855 | 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] | 5856 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5857 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5858 | } |
| 5859 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5860 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5861 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5862 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5863 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5864 | if (*(args[1]) == 0) { |
| 5865 | 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] | 5866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5867 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5868 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5869 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5870 | if (err) { |
| 5871 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5872 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5874 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5875 | } |
| 5876 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5877 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5878 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5879 | } |
| 5880 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5881 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5882 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5883 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5884 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5885 | if (curproxy == &defproxy) { |
| 5886 | 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] | 5887 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5889 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5890 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5891 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5892 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 5893 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5894 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5895 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5896 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5897 | goto out; |
| 5898 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5899 | |
| 5900 | proto = protocol_by_family(sk->ss_family); |
| 5901 | if (!proto || !proto->connect) { |
| 5902 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5903 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5905 | goto out; |
| 5906 | } |
| 5907 | |
| 5908 | if (port1 != port2) { |
| 5909 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5910 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5912 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5913 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5914 | |
| 5915 | if (!port1) { |
| 5916 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5917 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5919 | goto out; |
| 5920 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5921 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5922 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5923 | goto out; |
| 5924 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5925 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5926 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5927 | } |
| 5928 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5929 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5930 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5931 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5932 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5933 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5935 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5936 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5937 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5938 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5939 | /** |
| 5940 | * The syntax for hash-type config element is |
| 5941 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5942 | * |
| 5943 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5944 | */ |
| 5945 | 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] | 5946 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5947 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5948 | err_code |= ERR_WARN; |
| 5949 | |
| 5950 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5951 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5952 | } |
| 5953 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5954 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5955 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5956 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5957 | 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]); |
| 5958 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5959 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5960 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5961 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5962 | 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] | 5963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5964 | goto out; |
| 5965 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5966 | |
| 5967 | /* set the hash function to use */ |
| 5968 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5969 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5970 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5971 | |
| 5972 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5973 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5974 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5975 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5976 | /* set the hash function */ |
| 5977 | if (!strcmp(args[2], "sdbm")) { |
| 5978 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5979 | } |
| 5980 | else if (!strcmp(args[2], "djb2")) { |
| 5981 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5982 | } |
| 5983 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5984 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5985 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5986 | else if (!strcmp(args[2], "crc32")) { |
| 5987 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5988 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5989 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5990 | 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] | 5991 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5992 | goto out; |
| 5993 | } |
| 5994 | |
| 5995 | /* set the hash modifier */ |
| 5996 | if (!strcmp(args[3], "avalanche")) { |
| 5997 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5998 | } |
| 5999 | else if (*args[3]) { |
| 6000 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 6001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6002 | goto out; |
| 6003 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 6004 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6005 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6006 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 6007 | if (*(args[1]) == 0) { |
| 6008 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 6009 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6010 | goto out; |
| 6011 | } |
| 6012 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 6013 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 6014 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 6015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6016 | goto out; |
| 6017 | } |
| 6018 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6019 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 6020 | if (!*(args[1])) { |
| 6021 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6023 | goto out; |
| 6024 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6025 | if (*(args[2])) { |
| 6026 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6028 | goto out; |
| 6029 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6030 | free(curproxy->conf.uniqueid_format_string); |
| 6031 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6032 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6033 | free(curproxy->conf.uif_file); |
| 6034 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6035 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6036 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6037 | |
| 6038 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6039 | if (!*(args[1])) { |
| 6040 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6041 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6042 | goto out; |
| 6043 | } |
| 6044 | free(curproxy->header_unique_id); |
| 6045 | curproxy->header_unique_id = strdup(args[1]); |
| 6046 | } |
| 6047 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6048 | else if (strcmp(args[0], "log-format") == 0) { |
| 6049 | if (!*(args[1])) { |
| 6050 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6051 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6052 | goto out; |
| 6053 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6054 | if (*(args[2])) { |
| 6055 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6057 | goto out; |
| 6058 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6059 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6060 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6061 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6062 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6063 | free(curproxy->conf.logformat_string); |
| 6064 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6065 | |
| 6066 | free(curproxy->conf.lfs_file); |
| 6067 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6068 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6069 | |
| 6070 | /* get a chance to improve log-format error reporting by |
| 6071 | * reporting the correct line-number when possible. |
| 6072 | */ |
| 6073 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6074 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6075 | file, linenum, curproxy->id); |
| 6076 | err_code |= ERR_WARN; |
| 6077 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6078 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6079 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6080 | if (!*(args[1])) { |
| 6081 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6083 | goto out; |
| 6084 | } |
| 6085 | if (*(args[2])) { |
| 6086 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6088 | goto out; |
| 6089 | } |
| 6090 | |
| 6091 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6092 | free(curproxy->conf.logformat_sd_string); |
| 6093 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6094 | |
| 6095 | free(curproxy->conf.lfsd_file); |
| 6096 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6097 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6098 | |
| 6099 | /* get a chance to improve log-format-sd error reporting by |
| 6100 | * reporting the correct line-number when possible. |
| 6101 | */ |
| 6102 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6103 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6104 | file, linenum, curproxy->id); |
| 6105 | err_code |= ERR_WARN; |
| 6106 | } |
| 6107 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6108 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6109 | if (*(args[1]) == 0) { |
| 6110 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 6111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6112 | goto out; |
| 6113 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6114 | chunk_destroy(&curproxy->log_tag); |
| 6115 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6116 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6117 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6118 | /* delete previous herited or defined syslog servers */ |
| 6119 | struct logsrv *back; |
| 6120 | |
| 6121 | if (*(args[1]) != 0) { |
| 6122 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6123 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6124 | goto out; |
| 6125 | } |
| 6126 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6127 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6128 | LIST_DEL(&tmplogsrv->list); |
| 6129 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6130 | } |
| 6131 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6132 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6133 | struct logsrv *logsrv; |
| 6134 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6135 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6136 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6137 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6138 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6139 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6140 | LIST_INIT(&node->list); |
| 6141 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6142 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6143 | } |
| 6144 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6145 | struct sockaddr_storage *sk; |
| 6146 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6147 | int arg = 0; |
| 6148 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6149 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6150 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6151 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6152 | /* just after the address, a length may be specified */ |
| 6153 | if (strcmp(args[arg+2], "len") == 0) { |
| 6154 | len = atoi(args[arg+3]); |
| 6155 | if (len < 80 || len > 65535) { |
| 6156 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6157 | file, linenum, args[arg+3]); |
| 6158 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6159 | goto out; |
| 6160 | } |
| 6161 | logsrv->maxlen = len; |
| 6162 | |
| 6163 | /* skip these two args */ |
| 6164 | arg += 2; |
| 6165 | } |
| 6166 | else |
| 6167 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6168 | |
| 6169 | if (logsrv->maxlen > global.max_syslog_len) { |
| 6170 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 6171 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 6172 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 6173 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 6174 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6175 | } |
| 6176 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6177 | /* after the length, a format may be specified */ |
| 6178 | if (strcmp(args[arg+2], "format") == 0) { |
| 6179 | logsrv->format = get_log_format(args[arg+3]); |
| 6180 | if (logsrv->format < 0) { |
| 6181 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6182 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6183 | goto out; |
| 6184 | } |
| 6185 | |
| 6186 | /* skip these two args */ |
| 6187 | arg += 2; |
| 6188 | } |
| 6189 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6190 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6191 | goto out; |
| 6192 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6193 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6194 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6195 | 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] | 6196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6197 | goto out; |
| 6198 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6199 | } |
| 6200 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6201 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6202 | if (*(args[arg+3])) { |
| 6203 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6204 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6205 | 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] | 6206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6207 | goto out; |
| 6208 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6209 | } |
| 6210 | } |
| 6211 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6212 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6213 | if (*(args[arg+4])) { |
| 6214 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6215 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6216 | 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] | 6217 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6218 | goto out; |
| 6219 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6220 | } |
| 6221 | } |
| 6222 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6223 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6224 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6225 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6226 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6227 | goto out; |
| 6228 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6229 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6230 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6231 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6232 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6233 | if (port1 != port2) { |
| 6234 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6235 | file, linenum, args[0], args[1]); |
| 6236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6237 | goto out; |
| 6238 | } |
| 6239 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6240 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6241 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6242 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6243 | |
| 6244 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6245 | } |
| 6246 | else { |
| 6247 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6248 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6250 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | 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] | 6254 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6255 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6256 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6257 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6258 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6259 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6260 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6261 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6262 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6263 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6264 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6266 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6267 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6268 | |
| 6269 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6270 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6271 | free(curproxy->conn_src.iface_name); |
| 6272 | curproxy->conn_src.iface_name = NULL; |
| 6273 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6274 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6275 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6276 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6277 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6278 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6279 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6280 | goto out; |
| 6281 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6282 | |
| 6283 | proto = protocol_by_family(sk->ss_family); |
| 6284 | if (!proto || !proto->connect) { |
| 6285 | 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] | 6286 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6288 | goto out; |
| 6289 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6290 | |
| 6291 | if (port1 != port2) { |
| 6292 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6293 | file, linenum, args[0], args[1]); |
| 6294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6295 | goto out; |
| 6296 | } |
| 6297 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6298 | curproxy->conn_src.source_addr = *sk; |
| 6299 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6300 | |
| 6301 | cur_arg = 2; |
| 6302 | while (*(args[cur_arg])) { |
| 6303 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6304 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6305 | if (!*args[cur_arg + 1]) { |
| 6306 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6307 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6309 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6313 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6314 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6315 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6316 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6317 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6318 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6319 | char *name, *end; |
| 6320 | |
| 6321 | name = args[cur_arg+1] + 7; |
| 6322 | while (isspace(*name)) |
| 6323 | name++; |
| 6324 | |
| 6325 | end = name; |
| 6326 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6327 | end++; |
| 6328 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6329 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6330 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6331 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6332 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6333 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6334 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6335 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6336 | |
| 6337 | /* now look for an occurrence number */ |
| 6338 | while (isspace(*end)) |
| 6339 | end++; |
| 6340 | if (*end == ',') { |
| 6341 | end++; |
| 6342 | name = end; |
| 6343 | if (*end == '-') |
| 6344 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6345 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6346 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6347 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6348 | } |
| 6349 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6350 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6351 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6352 | " occurrences values smaller than %d.\n", |
| 6353 | file, linenum, MAX_HDR_HISTORY); |
| 6354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6355 | goto out; |
| 6356 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6357 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6358 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6359 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6360 | sk = str2sa_range(args[cur_arg + 1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6361 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6362 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6363 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6364 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6365 | goto out; |
| 6366 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6367 | |
| 6368 | proto = protocol_by_family(sk->ss_family); |
| 6369 | if (!proto || !proto->connect) { |
| 6370 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6371 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6373 | goto out; |
| 6374 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6375 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6376 | if (port1 != port2) { |
| 6377 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6378 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6379 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6380 | goto out; |
| 6381 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6382 | curproxy->conn_src.tproxy_addr = *sk; |
| 6383 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6384 | } |
| 6385 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6386 | #else /* no TPROXY support */ |
| 6387 | 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] | 6388 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6390 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6391 | #endif |
| 6392 | cur_arg += 2; |
| 6393 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6394 | } |
| 6395 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6396 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6397 | #ifdef SO_BINDTODEVICE |
| 6398 | if (!*args[cur_arg + 1]) { |
| 6399 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6400 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6402 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6403 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6404 | free(curproxy->conn_src.iface_name); |
| 6405 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6406 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6407 | global.last_checks |= LSTCHK_NETADM; |
| 6408 | #else |
| 6409 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6410 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6412 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6413 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6414 | cur_arg += 2; |
| 6415 | continue; |
| 6416 | } |
| 6417 | 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] | 6418 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6419 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6420 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6421 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6422 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6423 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6424 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6425 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6427 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6428 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6429 | 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] | 6430 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6431 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6432 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6434 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6435 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6436 | |
| 6437 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6438 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6439 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6440 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6441 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6442 | } |
| 6443 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6444 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6445 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6446 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6447 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6448 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6449 | } |
| 6450 | 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] | 6451 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6452 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6453 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6454 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6455 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6456 | } |
| 6457 | 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] | 6458 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6459 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6460 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6461 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6462 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6463 | } |
| 6464 | 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] | 6465 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6466 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6467 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6468 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6469 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6470 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6471 | 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] | 6472 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6473 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6474 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6475 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6476 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6477 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6478 | 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] | 6479 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6480 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6481 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6483 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6484 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6485 | |
| 6486 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6487 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6488 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6489 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6490 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6491 | } |
| 6492 | 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] | 6493 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6494 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6495 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6496 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6497 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6498 | } |
| 6499 | 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] | 6500 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6501 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6502 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6503 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6504 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6505 | } |
| 6506 | 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] | 6507 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6508 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6509 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6510 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6511 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6512 | } |
| 6513 | 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] | 6514 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6515 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6516 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6517 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6519 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6520 | 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] | 6521 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6522 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6523 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6524 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6525 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6526 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6527 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6528 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6529 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6530 | if (curproxy == &defproxy) { |
| 6531 | 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] | 6532 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6533 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6534 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6535 | 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] | 6536 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6537 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6538 | if (*(args[1]) == 0) { |
| 6539 | 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] | 6540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6541 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6542 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6543 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6544 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6545 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6546 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6547 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6549 | goto out; |
| 6550 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6551 | err_code |= warnif_cond_conflicts(cond, |
| 6552 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6553 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6554 | } |
| 6555 | else if (*args[2]) { |
| 6556 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6557 | file, linenum, args[0], args[2]); |
| 6558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6559 | goto out; |
| 6560 | } |
| 6561 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6562 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6563 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6564 | wl->s = strdup(args[1]); |
| 6565 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6566 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6567 | } |
| 6568 | 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] | 6569 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6570 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6571 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6573 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6574 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6575 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6576 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6577 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6578 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6579 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6580 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6581 | } |
| 6582 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6583 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6584 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6585 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6586 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6587 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6588 | } |
| 6589 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6590 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6591 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6592 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6593 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6594 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6595 | } |
| 6596 | 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] | 6597 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6598 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6599 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6601 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6602 | } |
| 6603 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6604 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6605 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6606 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6607 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6608 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6609 | } |
| 6610 | 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] | 6611 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6612 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6613 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6614 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6616 | } |
| 6617 | 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] | 6618 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6619 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6620 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6621 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6622 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6623 | } |
| 6624 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6625 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6626 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6627 | if (curproxy == &defproxy) { |
| 6628 | 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] | 6629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6630 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6631 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6632 | 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] | 6633 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6634 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6635 | if (*(args[1]) == 0) { |
| 6636 | 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] | 6637 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6638 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6639 | } |
| 6640 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6641 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6642 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6643 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6644 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6646 | goto out; |
| 6647 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6648 | err_code |= warnif_cond_conflicts(cond, |
| 6649 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6650 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6651 | } |
| 6652 | else if (*args[2]) { |
| 6653 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6654 | file, linenum, args[0], args[2]); |
| 6655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6656 | goto out; |
| 6657 | } |
| 6658 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6659 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6660 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6661 | wl->s = strdup(args[1]); |
| 6662 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6663 | } |
| 6664 | else if (!strcmp(args[0], "errorloc") || |
| 6665 | !strcmp(args[0], "errorloc302") || |
| 6666 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6667 | int errnum, errlen; |
| 6668 | char *err; |
| 6669 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6670 | 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] | 6671 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6672 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6673 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6674 | 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] | 6675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6676 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6677 | } |
| 6678 | |
| 6679 | errnum = atol(args[1]); |
| 6680 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6681 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6682 | err = malloc(errlen); |
| 6683 | 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] | 6684 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6685 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6686 | err = malloc(errlen); |
| 6687 | 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] | 6688 | } |
| 6689 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6690 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6691 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6692 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6693 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6694 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6695 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6696 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6697 | |
| 6698 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6699 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6700 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6701 | free(err); |
| 6702 | } |
| 6703 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6704 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6705 | int errnum, errlen, fd; |
| 6706 | char *err; |
| 6707 | struct stat stat; |
| 6708 | |
| 6709 | 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] | 6710 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6711 | |
| 6712 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6713 | 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] | 6714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6715 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | fd = open(args[2], O_RDONLY); |
| 6719 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6720 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6721 | file, linenum, args[2], args[1]); |
| 6722 | if (fd >= 0) |
| 6723 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6725 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6726 | } |
| 6727 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6728 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6729 | errlen = stat.st_size; |
| 6730 | } else { |
| 6731 | 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] | 6732 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6733 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6734 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6735 | } |
| 6736 | |
| 6737 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6738 | errnum = read(fd, err, errlen); |
| 6739 | if (errnum != errlen) { |
| 6740 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6741 | file, linenum, args[2], args[1]); |
| 6742 | close(fd); |
| 6743 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6745 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6746 | } |
| 6747 | close(fd); |
| 6748 | |
| 6749 | errnum = atol(args[1]); |
| 6750 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6751 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6752 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6753 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6754 | break; |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6759 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6760 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6761 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6762 | free(err); |
| 6763 | } |
| 6764 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6765 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6766 | struct cfg_kw_list *kwl; |
| 6767 | int index; |
| 6768 | |
| 6769 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6770 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6771 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6772 | continue; |
| 6773 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6774 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6775 | 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] | 6776 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6777 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6779 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6780 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6781 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6782 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6783 | err_code |= ERR_WARN; |
| 6784 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6785 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6786 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6787 | } |
| 6788 | } |
| 6789 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6790 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6791 | 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] | 6792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6793 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6794 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6795 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6796 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6797 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6798 | } |
| 6799 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6800 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6801 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6802 | { |
| 6803 | #ifdef CONFIG_HAP_NS |
| 6804 | const char *err; |
| 6805 | const char *item = args[0]; |
| 6806 | |
| 6807 | if (!strcmp(item, "namespace_list")) { |
| 6808 | return 0; |
| 6809 | } |
| 6810 | else if (!strcmp(item, "namespace")) { |
| 6811 | size_t idx = 1; |
| 6812 | const char *current; |
| 6813 | while (*(current = args[idx++])) { |
| 6814 | err = invalid_char(current); |
| 6815 | if (err) { |
| 6816 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6817 | file, linenum, *err, item, current); |
| 6818 | return ERR_ALERT | ERR_FATAL; |
| 6819 | } |
| 6820 | |
| 6821 | if (netns_store_lookup(current, strlen(current))) { |
| 6822 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6823 | file, linenum, current); |
| 6824 | return ERR_ALERT | ERR_FATAL; |
| 6825 | } |
| 6826 | if (!netns_store_insert(current)) { |
| 6827 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6828 | file, linenum, current); |
| 6829 | return ERR_ALERT | ERR_FATAL; |
| 6830 | } |
| 6831 | } |
| 6832 | } |
| 6833 | |
| 6834 | return 0; |
| 6835 | #else |
| 6836 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6837 | file, linenum); |
| 6838 | return ERR_ALERT | ERR_FATAL; |
| 6839 | #endif |
| 6840 | } |
| 6841 | |
| 6842 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6843 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6844 | { |
| 6845 | |
| 6846 | int err_code = 0; |
| 6847 | const char *err; |
| 6848 | |
| 6849 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6850 | struct userlist *newul; |
| 6851 | |
| 6852 | if (!*args[1]) { |
| 6853 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6854 | file, linenum, args[0]); |
| 6855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6856 | goto out; |
| 6857 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6858 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6859 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6860 | |
| 6861 | err = invalid_char(args[1]); |
| 6862 | if (err) { |
| 6863 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6864 | file, linenum, *err, args[0], args[1]); |
| 6865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6866 | goto out; |
| 6867 | } |
| 6868 | |
| 6869 | for (newul = userlist; newul; newul = newul->next) |
| 6870 | if (!strcmp(newul->name, args[1])) { |
| 6871 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6872 | file, linenum, args[1]); |
| 6873 | err_code |= ERR_WARN; |
| 6874 | goto out; |
| 6875 | } |
| 6876 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6877 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6878 | if (!newul) { |
| 6879 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6880 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6881 | goto out; |
| 6882 | } |
| 6883 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6884 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6885 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6886 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6887 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6888 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6889 | goto out; |
| 6890 | } |
| 6891 | |
| 6892 | newul->next = userlist; |
| 6893 | userlist = newul; |
| 6894 | |
| 6895 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6896 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6897 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6898 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6899 | |
| 6900 | if (!*args[1]) { |
| 6901 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6902 | file, linenum, args[0]); |
| 6903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6904 | goto out; |
| 6905 | } |
| 6906 | |
| 6907 | err = invalid_char(args[1]); |
| 6908 | if (err) { |
| 6909 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6910 | file, linenum, *err, args[0], args[1]); |
| 6911 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6912 | goto out; |
| 6913 | } |
| 6914 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6915 | if (!userlist) |
| 6916 | goto out; |
| 6917 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6918 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6919 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6920 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6921 | file, linenum, args[1], userlist->name); |
| 6922 | err_code |= ERR_ALERT; |
| 6923 | goto out; |
| 6924 | } |
| 6925 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6926 | ag = calloc(1, sizeof(*ag)); |
| 6927 | if (!ag) { |
| 6928 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6929 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6930 | goto out; |
| 6931 | } |
| 6932 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6933 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6934 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6935 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6936 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6937 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6938 | goto out; |
| 6939 | } |
| 6940 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6941 | cur_arg = 2; |
| 6942 | |
| 6943 | while (*args[cur_arg]) { |
| 6944 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6945 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6946 | cur_arg += 2; |
| 6947 | continue; |
| 6948 | } else { |
| 6949 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6950 | file, linenum, args[0]); |
| 6951 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6952 | free(ag->groupusers); |
| 6953 | free(ag->name); |
| 6954 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6955 | goto out; |
| 6956 | } |
| 6957 | } |
| 6958 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6959 | ag->next = userlist->groups; |
| 6960 | userlist->groups = ag; |
| 6961 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6962 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6963 | struct auth_users *newuser; |
| 6964 | int cur_arg; |
| 6965 | |
| 6966 | if (!*args[1]) { |
| 6967 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6968 | file, linenum, args[0]); |
| 6969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6970 | goto out; |
| 6971 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6972 | if (!userlist) |
| 6973 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6974 | |
| 6975 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6976 | if (!strcmp(newuser->user, args[1])) { |
| 6977 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6978 | file, linenum, args[1], userlist->name); |
| 6979 | err_code |= ERR_ALERT; |
| 6980 | goto out; |
| 6981 | } |
| 6982 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6983 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6984 | if (!newuser) { |
| 6985 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6986 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6987 | goto out; |
| 6988 | } |
| 6989 | |
| 6990 | newuser->user = strdup(args[1]); |
| 6991 | |
| 6992 | newuser->next = userlist->users; |
| 6993 | userlist->users = newuser; |
| 6994 | |
| 6995 | cur_arg = 2; |
| 6996 | |
| 6997 | while (*args[cur_arg]) { |
| 6998 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6999 | #ifdef CONFIG_HAP_CRYPT |
| 7000 | if (!crypt("", args[cur_arg + 1])) { |
| 7001 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 7002 | file, linenum, newuser->user); |
| 7003 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7004 | goto out; |
| 7005 | } |
| 7006 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7007 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 7008 | file, linenum); |
| 7009 | err_code |= ERR_ALERT; |
| 7010 | #endif |
| 7011 | newuser->pass = strdup(args[cur_arg + 1]); |
| 7012 | cur_arg += 2; |
| 7013 | continue; |
| 7014 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 7015 | newuser->pass = strdup(args[cur_arg + 1]); |
| 7016 | newuser->flags |= AU_O_INSECURE; |
| 7017 | cur_arg += 2; |
| 7018 | continue; |
| 7019 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7020 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7021 | cur_arg += 2; |
| 7022 | continue; |
| 7023 | } else { |
| 7024 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 7025 | file, linenum, args[0]); |
| 7026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7027 | goto out; |
| 7028 | } |
| 7029 | } |
| 7030 | } else { |
| 7031 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 7032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7033 | } |
| 7034 | |
| 7035 | out: |
| 7036 | return err_code; |
| 7037 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7038 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7039 | int |
| 7040 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 7041 | { |
| 7042 | char *beg, *end, *scope = NULL; |
| 7043 | int err_code = 0; |
| 7044 | const char *err; |
| 7045 | |
| 7046 | beg = line + 1; |
| 7047 | end = strchr(beg, ']'); |
| 7048 | |
| 7049 | /* Detect end of scope declaration */ |
| 7050 | if (!end || end == beg) { |
| 7051 | Alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 7052 | file, linenum); |
| 7053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7054 | goto out; |
| 7055 | } |
| 7056 | |
| 7057 | /* Get scope name and check its validity */ |
| 7058 | scope = my_strndup(beg, end-beg); |
| 7059 | err = invalid_char(scope); |
| 7060 | if (err) { |
| 7061 | Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 7062 | file, linenum, *err); |
| 7063 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7064 | goto out; |
| 7065 | } |
| 7066 | |
| 7067 | /* Be sure to have a scope declaration alone on its line */ |
| 7068 | line = end+1; |
| 7069 | while (isspace((unsigned char)*line)) |
| 7070 | line++; |
| 7071 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
| 7072 | Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 7073 | file, linenum, *line); |
| 7074 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7075 | goto out; |
| 7076 | } |
| 7077 | |
| 7078 | /* We have a valid scope declaration, save it */ |
| 7079 | free(cfg_scope); |
| 7080 | cfg_scope = scope; |
| 7081 | scope = NULL; |
| 7082 | |
| 7083 | out: |
| 7084 | free(scope); |
| 7085 | return err_code; |
| 7086 | } |
| 7087 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7088 | /* |
| 7089 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7090 | * Returns the error code, 0 if OK, or any combination of : |
| 7091 | * - ERR_ABORT: must abort ASAP |
| 7092 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7093 | * - ERR_WARN: a warning has been emitted |
| 7094 | * - ERR_ALERT: an alert has been emitted |
| 7095 | * Only the two first ones can stop processing, the two others are just |
| 7096 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7097 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7098 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7099 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7100 | char *thisline; |
| 7101 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7102 | FILE *f; |
| 7103 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7104 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7105 | struct cfg_section *cs = NULL; |
| 7106 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7107 | int readbytes = 0; |
| 7108 | |
| 7109 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7110 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7111 | return -1; |
| 7112 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7113 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7114 | if ((f=fopen(file,"r")) == NULL) { |
| 7115 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7116 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7117 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7118 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7119 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7120 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7121 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7122 | char *end; |
| 7123 | char *args[MAX_LINE_ARGS + 1]; |
| 7124 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7125 | int dquote = 0; /* double quote */ |
| 7126 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7127 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7128 | linenum++; |
| 7129 | |
| 7130 | end = line + strlen(line); |
| 7131 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7132 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7133 | /* Check if we reached the limit and the last char is not \n. |
| 7134 | * Watch out for the last line without the terminating '\n'! |
| 7135 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7136 | char *newline; |
| 7137 | int newlinesize = linesize * 2; |
| 7138 | |
| 7139 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7140 | if (newline == NULL) { |
| 7141 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7142 | file, linenum); |
| 7143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7144 | continue; |
| 7145 | } |
| 7146 | |
| 7147 | readbytes = linesize - 1; |
| 7148 | linesize = newlinesize; |
| 7149 | thisline = newline; |
| 7150 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7151 | } |
| 7152 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7153 | readbytes = 0; |
| 7154 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7155 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7156 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7157 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7158 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7159 | |
| 7160 | if (*line == '[') {/* This is the begining if a scope */ |
| 7161 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7162 | goto next_line; |
| 7163 | } |
| 7164 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7165 | arg = 0; |
| 7166 | args[arg] = line; |
| 7167 | |
| 7168 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7169 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7170 | if (dquote) |
| 7171 | dquote = 0; |
| 7172 | else |
| 7173 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7174 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7175 | end--; |
| 7176 | } |
| 7177 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7178 | if (squote) |
| 7179 | squote = 0; |
| 7180 | else |
| 7181 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7182 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7183 | end--; |
| 7184 | } |
| 7185 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7186 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7187 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7188 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7189 | int skip = 0; |
| 7190 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7191 | *line = line[1]; |
| 7192 | skip = 1; |
| 7193 | } |
| 7194 | else if (line[1] == 'r') { |
| 7195 | *line = '\r'; |
| 7196 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7197 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7198 | else if (line[1] == 'n') { |
| 7199 | *line = '\n'; |
| 7200 | skip = 1; |
| 7201 | } |
| 7202 | else if (line[1] == 't') { |
| 7203 | *line = '\t'; |
| 7204 | skip = 1; |
| 7205 | } |
| 7206 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7207 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7208 | unsigned char hex1, hex2; |
| 7209 | hex1 = toupper(line[2]) - '0'; |
| 7210 | hex2 = toupper(line[3]) - '0'; |
| 7211 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7212 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7213 | *line = (hex1<<4) + hex2; |
| 7214 | skip = 3; |
| 7215 | } |
| 7216 | else { |
| 7217 | 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] | 7218 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7219 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7220 | } else if (line[1] == '"') { |
| 7221 | *line = '"'; |
| 7222 | skip = 1; |
| 7223 | } else if (line[1] == '\'') { |
| 7224 | *line = '\''; |
| 7225 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7226 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7227 | *line = '$'; |
| 7228 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7229 | } |
| 7230 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7231 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7232 | end -= skip; |
| 7233 | } |
| 7234 | line++; |
| 7235 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7236 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7237 | /* end of string, end of loop */ |
| 7238 | *line = 0; |
| 7239 | break; |
| 7240 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7241 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7242 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7243 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7244 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7245 | line++; |
| 7246 | args[++arg] = line; |
| 7247 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7248 | else if (dquote && *line == '$') { |
| 7249 | /* environment variables are evaluated inside double quotes */ |
| 7250 | char *var_beg; |
| 7251 | char *var_end; |
| 7252 | char save_char; |
| 7253 | char *value; |
| 7254 | int val_len; |
| 7255 | int newlinesize; |
| 7256 | int braces = 0; |
| 7257 | |
| 7258 | var_beg = line + 1; |
| 7259 | var_end = var_beg; |
| 7260 | |
| 7261 | if (*var_beg == '{') { |
| 7262 | var_beg++; |
| 7263 | var_end++; |
| 7264 | braces = 1; |
| 7265 | } |
| 7266 | |
| 7267 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7268 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7270 | goto next_line; /* skip current line */ |
| 7271 | } |
| 7272 | |
| 7273 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7274 | var_end++; |
| 7275 | |
| 7276 | save_char = *var_end; |
| 7277 | *var_end = '\0'; |
| 7278 | value = getenv(var_beg); |
| 7279 | *var_end = save_char; |
| 7280 | val_len = value ? strlen(value) : 0; |
| 7281 | |
| 7282 | if (braces) { |
| 7283 | if (*var_end == '}') { |
| 7284 | var_end++; |
| 7285 | braces = 0; |
| 7286 | } else { |
| 7287 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7289 | goto next_line; /* skip current line */ |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7294 | |
| 7295 | /* if not enough space in thisline */ |
| 7296 | if (newlinesize > linesize) { |
| 7297 | char *newline; |
| 7298 | |
| 7299 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7300 | if (newline == NULL) { |
| 7301 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7303 | goto next_line; /* slip current line */ |
| 7304 | } |
| 7305 | /* recompute pointers if realloc returns a new pointer */ |
| 7306 | if (newline != thisline) { |
| 7307 | int i; |
| 7308 | int diff; |
| 7309 | |
| 7310 | for (i = 0; i <= arg; i++) { |
| 7311 | diff = args[i] - thisline; |
| 7312 | args[i] = newline + diff; |
| 7313 | } |
| 7314 | |
| 7315 | diff = var_end - thisline; |
| 7316 | var_end = newline + diff; |
| 7317 | diff = end - thisline; |
| 7318 | end = newline + diff; |
| 7319 | diff = line - thisline; |
| 7320 | line = newline + diff; |
| 7321 | thisline = newline; |
| 7322 | } |
| 7323 | linesize = newlinesize; |
| 7324 | } |
| 7325 | |
| 7326 | /* insert value inside the line */ |
| 7327 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7328 | memcpy(line, value, val_len); |
| 7329 | end += val_len - (var_end - line); |
| 7330 | line += val_len; |
| 7331 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7332 | else { |
| 7333 | line++; |
| 7334 | } |
| 7335 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7336 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7337 | if (dquote) { |
| 7338 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7340 | } |
| 7341 | |
| 7342 | if (squote) { |
| 7343 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7345 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7346 | |
| 7347 | /* empty line */ |
| 7348 | if (!**args) |
| 7349 | continue; |
| 7350 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7351 | if (*line) { |
| 7352 | /* we had to stop due to too many args. |
| 7353 | * Let's terminate the string, print the offending part then cut the |
| 7354 | * last arg. |
| 7355 | */ |
| 7356 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7357 | line++; |
| 7358 | *line = '\0'; |
| 7359 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7360 | 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] | 7361 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7362 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7363 | args[arg] = line; |
| 7364 | } |
| 7365 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7366 | /* zero out remaining args and ensure that at least one entry |
| 7367 | * is zeroed out. |
| 7368 | */ |
| 7369 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7370 | args[arg] = line; |
| 7371 | } |
| 7372 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7373 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7374 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7375 | char *tmp; |
| 7376 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7377 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7378 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7379 | for (arg=0; *args[arg+1]; arg++) |
| 7380 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7381 | *tmp = '\0'; // fix the next arg to \0 |
| 7382 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7383 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7384 | else if (!strcmp(args[0], "default")) { |
| 7385 | kwm = KWM_DEF; |
| 7386 | for (arg=0; *args[arg+1]; arg++) |
| 7387 | args[arg] = args[arg+1]; // shift args after inversion |
| 7388 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7389 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7390 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7391 | strcmp(args[0], "log") != 0) { |
| 7392 | 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] | 7393 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7394 | } |
| 7395 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7396 | /* detect section start */ |
| 7397 | list_for_each_entry(ics, §ions, list) { |
| 7398 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7399 | cursection = ics->section_name; |
| 7400 | cs = ics; |
| 7401 | break; |
| 7402 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7403 | } |
| 7404 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7405 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7406 | if (cs) |
| 7407 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7408 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7409 | 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] | 7410 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7411 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7412 | |
| 7413 | if (err_code & ERR_ABORT) |
| 7414 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7415 | } |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7416 | free(cfg_scope); |
| 7417 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7418 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7419 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7420 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7421 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7422 | } |
| 7423 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7424 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7425 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7426 | * bound to all of its processes. After that, if the target is a "listen" |
| 7427 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7428 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7429 | * checked first to ensure that <to> is already bound to all processes of |
| 7430 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7431 | * path to the destination. |
| 7432 | * |
| 7433 | * It is possible to set <to> to NULL for the first call so that the function |
| 7434 | * takes care of visiting the initial frontend in <from>. |
| 7435 | * |
| 7436 | * It is important to note that the function relies on the fact that all names |
| 7437 | * have already been resolved. |
| 7438 | */ |
| 7439 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7440 | { |
| 7441 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7442 | |
| 7443 | if (to) { |
| 7444 | /* check whether we need to go down */ |
| 7445 | if (from->bind_proc && |
| 7446 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7447 | return; |
| 7448 | |
| 7449 | if (!from->bind_proc && !to->bind_proc) |
| 7450 | return; |
| 7451 | |
| 7452 | to->bind_proc = from->bind_proc ? |
| 7453 | (to->bind_proc | from->bind_proc) : 0; |
| 7454 | |
| 7455 | /* now propagate down */ |
| 7456 | from = to; |
| 7457 | } |
| 7458 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7459 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7460 | return; |
| 7461 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7462 | if (from->state == PR_STSTOPPED) |
| 7463 | return; |
| 7464 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7465 | /* default_backend */ |
| 7466 | if (from->defbe.be) |
| 7467 | propagate_processes(from, from->defbe.be); |
| 7468 | |
| 7469 | /* use_backend */ |
| 7470 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7471 | if (rule->dynamic) |
| 7472 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7473 | to = rule->be.backend; |
| 7474 | propagate_processes(from, to); |
| 7475 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7476 | } |
| 7477 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7478 | /* |
| 7479 | * Returns the error code, 0 if OK, or any combination of : |
| 7480 | * - ERR_ABORT: must abort ASAP |
| 7481 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7482 | * - ERR_WARN: a warning has been emitted |
| 7483 | * - ERR_ALERT: an alert has been emitted |
| 7484 | * Only the two first ones can stop processing, the two others are just |
| 7485 | * indicators. |
| 7486 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7487 | int check_config_validity() |
| 7488 | { |
| 7489 | int cfgerr = 0; |
| 7490 | struct proxy *curproxy = NULL; |
| 7491 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7492 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7493 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7494 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7495 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7496 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7497 | /* |
| 7498 | * Now, check for the integrity of all that we have collected. |
| 7499 | */ |
| 7500 | |
| 7501 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7502 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7503 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7504 | if (!global.tune.max_http_hdr) |
| 7505 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7506 | |
| 7507 | if (!global.tune.cookie_len) |
| 7508 | global.tune.cookie_len = CAPTURE_LEN; |
| 7509 | |
| 7510 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7511 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7512 | /* Post initialisation of the users and groups lists. */ |
| 7513 | err_code = userlist_postinit(); |
| 7514 | if (err_code != ERR_NONE) |
| 7515 | goto out; |
| 7516 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7517 | /* first, we will invert the proxy list order */ |
| 7518 | curproxy = NULL; |
| 7519 | while (proxy) { |
| 7520 | struct proxy *next; |
| 7521 | |
| 7522 | next = proxy->next; |
| 7523 | proxy->next = curproxy; |
| 7524 | curproxy = proxy; |
| 7525 | if (!next) |
| 7526 | break; |
| 7527 | proxy = next; |
| 7528 | } |
| 7529 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7530 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7531 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7532 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7533 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7534 | struct act_rule *trule; |
| 7535 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7536 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7537 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7538 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7539 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7540 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7541 | /* proxy ID not set, use automatic numbering with first |
| 7542 | * spare entry starting with next_pxid. |
| 7543 | */ |
| 7544 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7545 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7546 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7547 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7548 | next_pxid++; |
| 7549 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7550 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7551 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7552 | /* ensure we don't keep listeners uselessly bound */ |
| 7553 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7554 | free((void *)curproxy->table.peers.name); |
| 7555 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7556 | continue; |
| 7557 | } |
| 7558 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7559 | /* Check multi-process mode compatibility for the current proxy */ |
| 7560 | |
| 7561 | if (curproxy->bind_proc) { |
| 7562 | /* an explicit bind-process was specified, let's check how many |
| 7563 | * processes remain. |
| 7564 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7565 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7566 | |
| 7567 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7568 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7569 | 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); |
| 7570 | curproxy->bind_proc = 1; |
| 7571 | } |
| 7572 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7573 | 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); |
| 7574 | curproxy->bind_proc = 0; |
| 7575 | } |
| 7576 | } |
| 7577 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7578 | /* check and reduce the bind-proc of each listener */ |
| 7579 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7580 | unsigned long mask; |
| 7581 | |
| 7582 | if (!bind_conf->bind_proc) |
| 7583 | continue; |
| 7584 | |
| 7585 | mask = nbits(global.nbproc); |
| 7586 | if (curproxy->bind_proc) |
| 7587 | mask &= curproxy->bind_proc; |
| 7588 | /* mask cannot be null here thanks to the previous checks */ |
| 7589 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7590 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7591 | bind_conf->bind_proc &= mask; |
| 7592 | |
| 7593 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7594 | 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", |
| 7595 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7596 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7597 | } |
| 7598 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7599 | 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", |
| 7600 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7601 | bind_conf->bind_proc = 0; |
| 7602 | } |
| 7603 | } |
| 7604 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7605 | switch (curproxy->mode) { |
| 7606 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7607 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7608 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7609 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7610 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7611 | cfgerr++; |
| 7612 | } |
| 7613 | |
| 7614 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7615 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7616 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7617 | break; |
| 7618 | |
| 7619 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7620 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7621 | break; |
| 7622 | |
| 7623 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7624 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7625 | break; |
| 7626 | } |
| 7627 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7628 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7629 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7630 | proxy_type_str(curproxy), curproxy->id); |
| 7631 | err_code |= ERR_WARN; |
| 7632 | } |
| 7633 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7634 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7635 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7636 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7637 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7638 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7639 | cfgerr++; |
| 7640 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7641 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7642 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7643 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7644 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7645 | cfgerr++; |
| 7646 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7647 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7648 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7649 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7650 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7651 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7652 | } |
| 7653 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7654 | 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] | 7655 | /* If no LB algo is set in a backend, and we're not in |
| 7656 | * transparent mode, dispatch mode nor proxy mode, we |
| 7657 | * want to use balance roundrobin by default. |
| 7658 | */ |
| 7659 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7660 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7661 | } |
| 7662 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7663 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7664 | if (curproxy->options & PR_O_DISPATCH) |
| 7665 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7666 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7667 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7668 | else if (curproxy->options & PR_O_TRANSP) |
| 7669 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7670 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7671 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7672 | if (curproxy->options & PR_O_DISABLE404) { |
| 7673 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7674 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7675 | err_code |= ERR_WARN; |
| 7676 | curproxy->options &= ~PR_O_DISABLE404; |
| 7677 | } |
| 7678 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7679 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7680 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7681 | err_code |= ERR_WARN; |
| 7682 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7683 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7684 | } |
| 7685 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7686 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7687 | if (!global.external_check) { |
| 7688 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7689 | curproxy->id, "option external-check"); |
| 7690 | cfgerr++; |
| 7691 | } |
| 7692 | if (!curproxy->check_command) { |
| 7693 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7694 | curproxy->id, "option external-check"); |
| 7695 | cfgerr++; |
| 7696 | } |
| 7697 | } |
| 7698 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7699 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7700 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7701 | 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] | 7702 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7703 | "'email-alert myhostname', or 'email-alert to' " |
| 7704 | "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] | 7705 | "to be present).\n", |
| 7706 | proxy_type_str(curproxy), curproxy->id); |
| 7707 | err_code |= ERR_WARN; |
| 7708 | free_email_alert(curproxy); |
| 7709 | } |
| 7710 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7711 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7712 | } |
| 7713 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7714 | if (curproxy->check_command) { |
| 7715 | int clear = 0; |
| 7716 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7717 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7718 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7719 | err_code |= ERR_WARN; |
| 7720 | clear = 1; |
| 7721 | } |
| 7722 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7723 | 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] | 7724 | curproxy->id, "external-check command"); |
| 7725 | cfgerr++; |
| 7726 | } |
| 7727 | if (clear) { |
| 7728 | free(curproxy->check_command); |
| 7729 | curproxy->check_command = NULL; |
| 7730 | } |
| 7731 | } |
| 7732 | |
| 7733 | if (curproxy->check_path) { |
| 7734 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7735 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7736 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7737 | err_code |= ERR_WARN; |
| 7738 | free(curproxy->check_path); |
| 7739 | curproxy->check_path = NULL; |
| 7740 | } |
| 7741 | } |
| 7742 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7743 | /* if a default backend was specified, let's find it */ |
| 7744 | if (curproxy->defbe.name) { |
| 7745 | struct proxy *target; |
| 7746 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7747 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7748 | if (!target) { |
| 7749 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7750 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7751 | cfgerr++; |
| 7752 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7753 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7754 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7755 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7756 | } else if (target->mode != curproxy->mode && |
| 7757 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7758 | |
| 7759 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7760 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7761 | curproxy->conf.file, curproxy->conf.line, |
| 7762 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7763 | target->conf.file, target->conf.line); |
| 7764 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7765 | } else { |
| 7766 | free(curproxy->defbe.name); |
| 7767 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7768 | |
| 7769 | /* Emit a warning if this proxy also has some servers */ |
| 7770 | if (curproxy->srv) { |
| 7771 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7772 | curproxy->id); |
| 7773 | err_code |= ERR_WARN; |
| 7774 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7775 | } |
| 7776 | } |
| 7777 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7778 | /* find the target proxy for 'use_backend' rules */ |
| 7779 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7780 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7781 | struct logformat_node *node; |
| 7782 | char *pxname; |
| 7783 | |
| 7784 | /* Try to parse the string as a log format expression. If the result |
| 7785 | * of the parsing is only one entry containing a simple string, then |
| 7786 | * it's a standard string corresponding to a static rule, thus the |
| 7787 | * parsing is cancelled and be.name is restored to be resolved. |
| 7788 | */ |
| 7789 | pxname = rule->be.name; |
| 7790 | LIST_INIT(&rule->be.expr); |
| 7791 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 7792 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 7793 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7794 | |
| 7795 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7796 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7797 | rule->dynamic = 1; |
| 7798 | free(pxname); |
| 7799 | continue; |
| 7800 | } |
| 7801 | /* simple string: free the expression and fall back to static rule */ |
| 7802 | free(node->arg); |
| 7803 | free(node); |
| 7804 | } |
| 7805 | |
| 7806 | rule->dynamic = 0; |
| 7807 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7808 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7809 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7810 | if (!target) { |
| 7811 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7812 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7813 | cfgerr++; |
| 7814 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7815 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7816 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7817 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7818 | } else if (target->mode != curproxy->mode && |
| 7819 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7820 | |
| 7821 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7822 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7823 | curproxy->conf.file, curproxy->conf.line, |
| 7824 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7825 | target->conf.file, target->conf.line); |
| 7826 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7827 | } else { |
| 7828 | free((void *)rule->be.name); |
| 7829 | rule->be.backend = target; |
| 7830 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7831 | } |
| 7832 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7833 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7834 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7835 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7836 | |
| 7837 | if (!target) { |
| 7838 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7839 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7840 | cfgerr++; |
| 7841 | continue; |
| 7842 | } |
| 7843 | free((void *)srule->srv.name); |
| 7844 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7845 | } |
| 7846 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7847 | /* find the target table for 'stick' rules */ |
| 7848 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7849 | struct proxy *target; |
| 7850 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7851 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7852 | if (mrule->flags & STK_IS_STORE) |
| 7853 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7854 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7855 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7856 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7857 | else |
| 7858 | target = curproxy; |
| 7859 | |
| 7860 | if (!target) { |
| 7861 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7862 | curproxy->id, mrule->table.name); |
| 7863 | cfgerr++; |
| 7864 | } |
| 7865 | else if (target->table.size == 0) { |
| 7866 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7867 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7868 | cfgerr++; |
| 7869 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7870 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7871 | 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] | 7872 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7873 | cfgerr++; |
| 7874 | } |
| 7875 | else { |
| 7876 | free((void *)mrule->table.name); |
| 7877 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7878 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7879 | } |
| 7880 | } |
| 7881 | |
| 7882 | /* find the target table for 'store response' rules */ |
| 7883 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7884 | struct proxy *target; |
| 7885 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7886 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7887 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7888 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7889 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7890 | else |
| 7891 | target = curproxy; |
| 7892 | |
| 7893 | if (!target) { |
| 7894 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7895 | curproxy->id, mrule->table.name); |
| 7896 | cfgerr++; |
| 7897 | } |
| 7898 | else if (target->table.size == 0) { |
| 7899 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7900 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7901 | cfgerr++; |
| 7902 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7903 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7904 | 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] | 7905 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7906 | cfgerr++; |
| 7907 | } |
| 7908 | else { |
| 7909 | free((void *)mrule->table.name); |
| 7910 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7911 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7912 | } |
| 7913 | } |
| 7914 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7915 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7916 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7917 | struct proxy *target; |
| 7918 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7919 | 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] | 7920 | continue; |
| 7921 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7922 | if (trule->arg.trk_ctr.table.n) |
| 7923 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7924 | else |
| 7925 | target = curproxy; |
| 7926 | |
| 7927 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7928 | 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] | 7929 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7930 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7931 | cfgerr++; |
| 7932 | } |
| 7933 | else if (target->table.size == 0) { |
| 7934 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7935 | 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] | 7936 | cfgerr++; |
| 7937 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7938 | 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] | 7939 | 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] | 7940 | 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] | 7941 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7942 | cfgerr++; |
| 7943 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7944 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7945 | free(trule->arg.trk_ctr.table.n); |
| 7946 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7947 | /* 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] | 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 | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7954 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7955 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7956 | struct proxy *target; |
| 7957 | |
| 7958 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7959 | continue; |
| 7960 | |
| 7961 | if (trule->arg.trk_ctr.table.n) |
| 7962 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7963 | else |
| 7964 | target = curproxy; |
| 7965 | |
| 7966 | if (!target) { |
| 7967 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7968 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7969 | tcp_trk_idx(trule->action)); |
| 7970 | cfgerr++; |
| 7971 | } |
| 7972 | else if (target->table.size == 0) { |
| 7973 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7974 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7975 | cfgerr++; |
| 7976 | } |
| 7977 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7978 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7979 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7980 | tcp_trk_idx(trule->action)); |
| 7981 | cfgerr++; |
| 7982 | } |
| 7983 | else { |
| 7984 | free(trule->arg.trk_ctr.table.n); |
| 7985 | trule->arg.trk_ctr.table.t = &target->table; |
| 7986 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7987 | * to pass a list of counters to track and allocate them right here using |
| 7988 | * stktable_alloc_data_type(). |
| 7989 | */ |
| 7990 | } |
| 7991 | } |
| 7992 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7993 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7994 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7995 | struct proxy *target; |
| 7996 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7997 | 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] | 7998 | continue; |
| 7999 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8000 | if (trule->arg.trk_ctr.table.n) |
| 8001 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8002 | else |
| 8003 | target = curproxy; |
| 8004 | |
| 8005 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 8006 | 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] | 8007 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 8008 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8009 | cfgerr++; |
| 8010 | } |
| 8011 | else if (target->table.size == 0) { |
| 8012 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8013 | 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] | 8014 | cfgerr++; |
| 8015 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8016 | 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] | 8017 | 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] | 8018 | 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] | 8019 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 8020 | cfgerr++; |
| 8021 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8022 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8023 | free(trule->arg.trk_ctr.table.n); |
| 8024 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 8025 | /* 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] | 8026 | * to pass a list of counters to track and allocate them right here using |
| 8027 | * stktable_alloc_data_type(). |
| 8028 | */ |
| 8029 | } |
| 8030 | } |
| 8031 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8032 | /* parse http-request capture rules to ensure id really exists */ |
| 8033 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 8034 | if (hrqrule->action != ACT_CUSTOM || |
| 8035 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 8036 | continue; |
| 8037 | |
| 8038 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 8039 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 8040 | curproxy->id, hrqrule->arg.capid.idx); |
| 8041 | cfgerr++; |
| 8042 | } |
| 8043 | } |
| 8044 | |
| 8045 | /* parse http-response capture rules to ensure id really exists */ |
| 8046 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8047 | if (hrqrule->action != ACT_CUSTOM || |
| 8048 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 8049 | continue; |
| 8050 | |
| 8051 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 8052 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 8053 | curproxy->id, hrqrule->arg.capid.idx); |
| 8054 | cfgerr++; |
| 8055 | } |
| 8056 | } |
| 8057 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8058 | /* find the target table for 'http-request' layer 7 rules */ |
| 8059 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 8060 | struct proxy *target; |
| 8061 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8062 | 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] | 8063 | continue; |
| 8064 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8065 | if (hrqrule->arg.trk_ctr.table.n) |
| 8066 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8067 | else |
| 8068 | target = curproxy; |
| 8069 | |
| 8070 | if (!target) { |
| 8071 | 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] | 8072 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8073 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8074 | cfgerr++; |
| 8075 | } |
| 8076 | else if (target->table.size == 0) { |
| 8077 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8078 | 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] | 8079 | cfgerr++; |
| 8080 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8081 | 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] | 8082 | 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] | 8083 | 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] | 8084 | http_trk_idx(hrqrule->action)); |
| 8085 | cfgerr++; |
| 8086 | } |
| 8087 | else { |
| 8088 | free(hrqrule->arg.trk_ctr.table.n); |
| 8089 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 8090 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8091 | * to pass a list of counters to track and allocate them right here using |
| 8092 | * stktable_alloc_data_type(). |
| 8093 | */ |
| 8094 | } |
| 8095 | } |
| 8096 | |
| 8097 | /* find the target table for 'http-response' layer 7 rules */ |
| 8098 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8099 | struct proxy *target; |
| 8100 | |
| 8101 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 8102 | continue; |
| 8103 | |
| 8104 | if (hrqrule->arg.trk_ctr.table.n) |
| 8105 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 8106 | else |
| 8107 | target = curproxy; |
| 8108 | |
| 8109 | if (!target) { |
| 8110 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 8111 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 8112 | http_trk_idx(hrqrule->action)); |
| 8113 | cfgerr++; |
| 8114 | } |
| 8115 | else if (target->table.size == 0) { |
| 8116 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 8117 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 8118 | cfgerr++; |
| 8119 | } |
| 8120 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 8121 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 8122 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 8123 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8124 | cfgerr++; |
| 8125 | } |
| 8126 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8127 | free(hrqrule->arg.trk_ctr.table.n); |
| 8128 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8129 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8130 | * to pass a list of counters to track and allocate them right here using |
| 8131 | * stktable_alloc_data_type(). |
| 8132 | */ |
| 8133 | } |
| 8134 | } |
| 8135 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8136 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8137 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8138 | /* insert block_rules into http_req_rules at the beginning */ |
| 8139 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8140 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8141 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8142 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8143 | LIST_INIT(&curproxy->block_rules); |
| 8144 | } |
| 8145 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8146 | if (curproxy->table.peers.name) { |
| 8147 | struct peers *curpeers = peers; |
| 8148 | |
| 8149 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 8150 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8151 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8152 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8153 | break; |
| 8154 | } |
| 8155 | } |
| 8156 | |
| 8157 | if (!curpeers) { |
| 8158 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8159 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8160 | free((void *)curproxy->table.peers.name); |
| 8161 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8162 | cfgerr++; |
| 8163 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8164 | else if (curpeers->state == PR_STSTOPPED) { |
| 8165 | /* silently disable this peers section */ |
| 8166 | curproxy->table.peers.p = NULL; |
| 8167 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8168 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8169 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8170 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8171 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8172 | cfgerr++; |
| 8173 | } |
| 8174 | } |
| 8175 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8176 | |
| 8177 | if (curproxy->email_alert.mailers.name) { |
| 8178 | struct mailers *curmailers = mailers; |
| 8179 | |
| 8180 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 8181 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8182 | free(curproxy->email_alert.mailers.name); |
| 8183 | curproxy->email_alert.mailers.m = curmailers; |
| 8184 | curmailers->users++; |
| 8185 | break; |
| 8186 | } |
| 8187 | } |
| 8188 | |
| 8189 | if (!curmailers) { |
| 8190 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8191 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8192 | free_email_alert(curproxy); |
| 8193 | cfgerr++; |
| 8194 | } |
| 8195 | } |
| 8196 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8197 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8198 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8199 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8200 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8201 | "proxy", curproxy->id); |
| 8202 | cfgerr++; |
| 8203 | goto out_uri_auth_compat; |
| 8204 | } |
| 8205 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8206 | 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] | 8207 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8208 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8209 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8210 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8211 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8212 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8213 | |
| 8214 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8215 | uri_auth_compat_req[i++] = "realm"; |
| 8216 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8217 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8218 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8219 | uri_auth_compat_req[i++] = "unless"; |
| 8220 | uri_auth_compat_req[i++] = "{"; |
| 8221 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8222 | uri_auth_compat_req[i++] = "}"; |
| 8223 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8224 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8225 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8226 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8227 | cfgerr++; |
| 8228 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8229 | } |
| 8230 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8231 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8232 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8233 | if (curproxy->uri_auth->auth_realm) { |
| 8234 | free(curproxy->uri_auth->auth_realm); |
| 8235 | curproxy->uri_auth->auth_realm = NULL; |
| 8236 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8237 | |
| 8238 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8239 | } |
| 8240 | out_uri_auth_compat: |
| 8241 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8242 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8243 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8244 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8245 | if (!curproxy->conf.logformat_sd_string) { |
| 8246 | /* set the default logformat_sd_string */ |
| 8247 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8248 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8249 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8250 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8251 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8252 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8253 | /* compile the log format */ |
| 8254 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8255 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8256 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8257 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8258 | free(curproxy->conf.logformat_string); |
| 8259 | curproxy->conf.logformat_string = NULL; |
| 8260 | free(curproxy->conf.lfs_file); |
| 8261 | curproxy->conf.lfs_file = NULL; |
| 8262 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8263 | |
| 8264 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8265 | free(curproxy->conf.logformat_sd_string); |
| 8266 | curproxy->conf.logformat_sd_string = NULL; |
| 8267 | free(curproxy->conf.lfsd_file); |
| 8268 | curproxy->conf.lfsd_file = NULL; |
| 8269 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8270 | } |
| 8271 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8272 | if (curproxy->conf.logformat_string) { |
| 8273 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8274 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8275 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 8276 | parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 8277 | SMP_VAL_FE_LOG_END, curproxy->conf.lfs_file, curproxy->conf.lfs_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8278 | curproxy->conf.args.file = NULL; |
| 8279 | curproxy->conf.args.line = 0; |
| 8280 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8281 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8282 | if (curproxy->conf.logformat_sd_string) { |
| 8283 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8284 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8285 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
| 8286 | parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
| 8287 | SMP_VAL_FE_LOG_END, curproxy->conf.lfsd_file, curproxy->conf.lfsd_line); |
| 8288 | add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd); |
| 8289 | curproxy->conf.args.file = NULL; |
| 8290 | curproxy->conf.args.line = 0; |
| 8291 | } |
| 8292 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8293 | if (curproxy->conf.uniqueid_format_string) { |
| 8294 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8295 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8296 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 8297 | parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Godbach | d972203 | 2014-12-18 15:44:58 +0800 | [diff] [blame] | 8298 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 8299 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8300 | curproxy->conf.args.file = NULL; |
| 8301 | curproxy->conf.args.line = 0; |
| 8302 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8303 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8304 | /* only now we can check if some args remain unresolved. |
| 8305 | * This must be done after the users and groups resolution. |
| 8306 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8307 | cfgerr += smp_resolve_args(curproxy); |
| 8308 | if (!cfgerr) |
| 8309 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8310 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8311 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8312 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8313 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8314 | (!curproxy->timeout.connect || |
| 8315 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8316 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8317 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8318 | " | 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] | 8319 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8320 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8321 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8322 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8323 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8324 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8325 | * We must still support older configurations, so let's find out whether those |
| 8326 | * parameters have been set or must be copied from contimeouts. |
| 8327 | */ |
| 8328 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8329 | if (!curproxy->timeout.tarpit || |
| 8330 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8331 | /* tarpit timeout not set. We search in the following order: |
| 8332 | * default.tarpit, curr.connect, default.connect. |
| 8333 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8334 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8335 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8336 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8337 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8338 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8339 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8340 | } |
| 8341 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8342 | (!curproxy->timeout.queue || |
| 8343 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8344 | /* queue timeout not set. We search in the following order: |
| 8345 | * default.queue, curr.connect, default.connect. |
| 8346 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8347 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8348 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8349 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8350 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8351 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8352 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8353 | } |
| 8354 | } |
| 8355 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8356 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8357 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8358 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8359 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8360 | } |
| 8361 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8362 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8363 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8364 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8365 | proxy_type_str(curproxy), curproxy->id); |
| 8366 | err_code |= ERR_WARN; |
| 8367 | } |
| 8368 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8369 | /* ensure that cookie capture length is not too large */ |
| 8370 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8371 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8372 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8373 | err_code |= ERR_WARN; |
| 8374 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8375 | } |
| 8376 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8377 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8378 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8379 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8380 | curproxy->nb_req_cap * sizeof(char *), |
| 8381 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8382 | } |
| 8383 | |
| 8384 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8385 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8386 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8387 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8388 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8389 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8390 | switch (curproxy->load_server_state_from_file) { |
| 8391 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8392 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8393 | break; |
| 8394 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8395 | if (!global.server_state_file) { |
| 8396 | 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", |
| 8397 | curproxy->id); |
| 8398 | err_code |= ERR_WARN; |
| 8399 | } |
| 8400 | break; |
| 8401 | } |
| 8402 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8403 | /* first, we will invert the servers list order */ |
| 8404 | newsrv = NULL; |
| 8405 | while (curproxy->srv) { |
| 8406 | struct server *next; |
| 8407 | |
| 8408 | next = curproxy->srv->next; |
| 8409 | curproxy->srv->next = newsrv; |
| 8410 | newsrv = curproxy->srv; |
| 8411 | if (!next) |
| 8412 | break; |
| 8413 | curproxy->srv = next; |
| 8414 | } |
| 8415 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8416 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8417 | * We only emit a warning for the first conflict affecting each server, |
| 8418 | * in order to avoid combinatory explosion if all servers have the same |
| 8419 | * name. We do that only for servers which do not have an explicit ID, |
| 8420 | * because these IDs were made also for distinguishing them and we don't |
| 8421 | * want to annoy people who correctly manage them. |
| 8422 | */ |
| 8423 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8424 | struct server *other_srv; |
| 8425 | |
| 8426 | if (newsrv->puid) |
| 8427 | continue; |
| 8428 | |
| 8429 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8430 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8431 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8432 | newsrv->conf.file, newsrv->conf.line, |
| 8433 | proxy_type_str(curproxy), curproxy->id, |
| 8434 | newsrv->id, other_srv->conf.line); |
| 8435 | break; |
| 8436 | } |
| 8437 | } |
| 8438 | } |
| 8439 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8440 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8441 | next_id = 1; |
| 8442 | newsrv = curproxy->srv; |
| 8443 | while (newsrv != NULL) { |
| 8444 | if (!newsrv->puid) { |
| 8445 | /* server ID not set, use automatic numbering with first |
| 8446 | * spare entry starting with next_svid. |
| 8447 | */ |
| 8448 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8449 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8450 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8451 | } |
| 8452 | next_id++; |
| 8453 | newsrv = newsrv->next; |
| 8454 | } |
| 8455 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8456 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8457 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8458 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8459 | /* |
| 8460 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8461 | * tasks to fill the emptied slots when a connection leaves. |
| 8462 | * Also, resolve deferred tracking dependency if needed. |
| 8463 | */ |
| 8464 | newsrv = curproxy->srv; |
| 8465 | while (newsrv != NULL) { |
| 8466 | if (newsrv->minconn > newsrv->maxconn) { |
| 8467 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8468 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8469 | * this will avoid further useless expensive computations. |
| 8470 | */ |
| 8471 | newsrv->maxconn = newsrv->minconn; |
| 8472 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8473 | /* minconn was not specified, so we set it to maxconn */ |
| 8474 | newsrv->minconn = newsrv->maxconn; |
| 8475 | } |
| 8476 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8477 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8478 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 8479 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8480 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8481 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8482 | /* set the check type on the server */ |
| 8483 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8484 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8485 | if (newsrv->trackit) { |
| 8486 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8487 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8488 | char *pname, *sname; |
| 8489 | |
| 8490 | pname = newsrv->trackit; |
| 8491 | sname = strrchr(pname, '/'); |
| 8492 | |
| 8493 | if (sname) |
| 8494 | *sname++ = '\0'; |
| 8495 | else { |
| 8496 | sname = pname; |
| 8497 | pname = NULL; |
| 8498 | } |
| 8499 | |
| 8500 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8501 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8502 | if (!px) { |
| 8503 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8504 | proxy_type_str(curproxy), curproxy->id, |
| 8505 | newsrv->id, pname); |
| 8506 | cfgerr++; |
| 8507 | goto next_srv; |
| 8508 | } |
| 8509 | } else |
| 8510 | px = curproxy; |
| 8511 | |
| 8512 | srv = findserver(px, sname); |
| 8513 | if (!srv) { |
| 8514 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8515 | proxy_type_str(curproxy), curproxy->id, |
| 8516 | newsrv->id, sname); |
| 8517 | cfgerr++; |
| 8518 | goto next_srv; |
| 8519 | } |
| 8520 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8521 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8522 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8523 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8524 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8525 | "tracking as it does not have any check nor agent enabled.\n", |
| 8526 | proxy_type_str(curproxy), curproxy->id, |
| 8527 | newsrv->id, px->id, srv->id); |
| 8528 | cfgerr++; |
| 8529 | goto next_srv; |
| 8530 | } |
| 8531 | |
| 8532 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8533 | |
| 8534 | if (loop) { |
| 8535 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8536 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8537 | proxy_type_str(curproxy), curproxy->id, |
| 8538 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8539 | cfgerr++; |
| 8540 | goto next_srv; |
| 8541 | } |
| 8542 | |
| 8543 | if (curproxy != px && |
| 8544 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8545 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8546 | "tracking: disable-on-404 option inconsistency.\n", |
| 8547 | proxy_type_str(curproxy), curproxy->id, |
| 8548 | newsrv->id, px->id, srv->id); |
| 8549 | cfgerr++; |
| 8550 | goto next_srv; |
| 8551 | } |
| 8552 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8553 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8554 | newsrv->tracknext = srv->trackers; |
| 8555 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8556 | |
| 8557 | free(newsrv->trackit); |
| 8558 | newsrv->trackit = NULL; |
| 8559 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8560 | |
| 8561 | /* |
| 8562 | * resolve server's resolvers name and update the resolvers pointer |
| 8563 | * accordingly |
| 8564 | */ |
| 8565 | if (newsrv->resolvers_id) { |
| 8566 | struct dns_resolvers *curr_resolvers; |
| 8567 | int found; |
| 8568 | |
| 8569 | found = 0; |
| 8570 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8571 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8572 | found = 1; |
| 8573 | break; |
| 8574 | } |
| 8575 | } |
| 8576 | |
| 8577 | if (!found) { |
| 8578 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8579 | proxy_type_str(curproxy), curproxy->id, |
| 8580 | newsrv->id, newsrv->resolvers_id); |
| 8581 | cfgerr++; |
| 8582 | } else { |
| 8583 | free(newsrv->resolvers_id); |
| 8584 | newsrv->resolvers_id = NULL; |
| 8585 | if (newsrv->resolution) |
| 8586 | newsrv->resolution->resolvers = curr_resolvers; |
| 8587 | } |
| 8588 | } |
| 8589 | else { |
| 8590 | /* if no resolvers section associated to this server |
| 8591 | * we can clean up the associated resolution structure |
| 8592 | */ |
| 8593 | if (newsrv->resolution) { |
| 8594 | free(newsrv->resolution->hostname_dn); |
| 8595 | newsrv->resolution->hostname_dn = NULL; |
| 8596 | free(newsrv->resolution); |
| 8597 | newsrv->resolution = NULL; |
| 8598 | } |
| 8599 | } |
| 8600 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8601 | next_srv: |
| 8602 | newsrv = newsrv->next; |
| 8603 | } |
| 8604 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8605 | /* We have to initialize the server lookup mechanism depending |
| 8606 | * on what LB algorithm was choosen. |
| 8607 | */ |
| 8608 | |
| 8609 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8610 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8611 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8612 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8613 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8614 | init_server_map(curproxy); |
| 8615 | } else { |
| 8616 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8617 | fwrr_init_server_groups(curproxy); |
| 8618 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8619 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8620 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8621 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8622 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8623 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8624 | fwlc_init_server_tree(curproxy); |
| 8625 | } else { |
| 8626 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8627 | fas_init_server_tree(curproxy); |
| 8628 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8629 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8630 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8631 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8632 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8633 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8634 | chash_init_server_tree(curproxy); |
| 8635 | } else { |
| 8636 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8637 | init_server_map(curproxy); |
| 8638 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8639 | break; |
| 8640 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8641 | |
| 8642 | if (curproxy->options & PR_O_LOGASAP) |
| 8643 | curproxy->to_log &= ~LW_BYTES; |
| 8644 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8645 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8646 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8647 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8648 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8649 | proxy_type_str(curproxy), curproxy->id); |
| 8650 | err_code |= ERR_WARN; |
| 8651 | } |
| 8652 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8653 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8654 | int optnum; |
| 8655 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8656 | if (curproxy->uri_auth) { |
| 8657 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8658 | proxy_type_str(curproxy), curproxy->id); |
| 8659 | err_code |= ERR_WARN; |
| 8660 | curproxy->uri_auth = NULL; |
| 8661 | } |
| 8662 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8663 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8664 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8665 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8666 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8667 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8668 | } |
| 8669 | |
| 8670 | if (curproxy->options & PR_O_ORGTO) { |
| 8671 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8672 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8673 | err_code |= ERR_WARN; |
| 8674 | curproxy->options &= ~PR_O_ORGTO; |
| 8675 | } |
| 8676 | |
| 8677 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8678 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8679 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8680 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8681 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8682 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8683 | err_code |= ERR_WARN; |
| 8684 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8685 | } |
| 8686 | } |
| 8687 | |
| 8688 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8689 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8690 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8691 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8692 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8693 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8694 | err_code |= ERR_WARN; |
| 8695 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8696 | } |
| 8697 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8698 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8699 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8700 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8701 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8702 | 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] | 8703 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8704 | err_code |= ERR_WARN; |
| 8705 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8706 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8707 | } |
| 8708 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8709 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8710 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8711 | */ |
| 8712 | newsrv = curproxy->srv; |
| 8713 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8714 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8715 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8716 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8717 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8718 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8719 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8720 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8721 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8722 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8723 | err_code |= ERR_WARN; |
| 8724 | } |
| 8725 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8726 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8727 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8728 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8729 | err_code |= ERR_WARN; |
| 8730 | } |
| 8731 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8732 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8733 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8734 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8735 | 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] | 8736 | 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] | 8737 | err_code |= ERR_WARN; |
| 8738 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8739 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8740 | newsrv = newsrv->next; |
| 8741 | } |
| 8742 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8743 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8744 | * with no inspect-delay |
| 8745 | */ |
| 8746 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8747 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8748 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8749 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8750 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8751 | 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] | 8752 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8753 | break; |
| 8754 | } |
| 8755 | |
| 8756 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8757 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8758 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8759 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8760 | " setting the tcp-request inspect-delay.\n", |
| 8761 | proxy_type_str(curproxy), curproxy->id); |
| 8762 | err_code |= ERR_WARN; |
| 8763 | } |
| 8764 | } |
| 8765 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8766 | /* Check filter configuration, if any */ |
| 8767 | cfgerr += flt_check(curproxy); |
| 8768 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8769 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8770 | if (!curproxy->accept) |
| 8771 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8772 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8773 | if (curproxy->tcp_req.inspect_delay || |
| 8774 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8775 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8776 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8777 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8778 | 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] | 8779 | 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] | 8780 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8781 | |
| 8782 | /* both TCP and HTTP must check switching rules */ |
| 8783 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8784 | |
| 8785 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8786 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8787 | curproxy->fe_req_ana |= AN_FLT_ALL_FE; |
| 8788 | curproxy->fe_rsp_ana |= AN_FLT_ALL_FE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8789 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8790 | curproxy->fe_req_ana |= AN_FLT_HTTP_HDRS; |
| 8791 | curproxy->fe_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8792 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8793 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8794 | } |
| 8795 | |
| 8796 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8797 | if (curproxy->tcp_req.inspect_delay || |
| 8798 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8799 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8800 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8801 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8802 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8803 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8804 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8805 | 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] | 8806 | 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] | 8807 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8808 | |
| 8809 | /* If the backend does requires RDP cookie persistence, we have to |
| 8810 | * enable the corresponding analyser. |
| 8811 | */ |
| 8812 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8813 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8814 | |
| 8815 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8816 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8817 | curproxy->be_req_ana |= AN_FLT_ALL_BE; |
| 8818 | curproxy->be_rsp_ana |= AN_FLT_ALL_BE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8819 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8820 | curproxy->be_req_ana |= AN_FLT_HTTP_HDRS; |
| 8821 | curproxy->be_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8822 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8823 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8824 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8825 | } |
| 8826 | |
| 8827 | /***********************************************************/ |
| 8828 | /* At this point, target names have already been resolved. */ |
| 8829 | /***********************************************************/ |
| 8830 | |
| 8831 | /* Check multi-process mode compatibility */ |
| 8832 | |
| 8833 | if (global.nbproc > 1 && global.stats_fe) { |
| 8834 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8835 | unsigned long mask; |
| 8836 | |
| 8837 | mask = nbits(global.nbproc); |
| 8838 | if (global.stats_fe->bind_proc) |
| 8839 | mask &= global.stats_fe->bind_proc; |
| 8840 | |
| 8841 | if (bind_conf->bind_proc) |
| 8842 | mask &= bind_conf->bind_proc; |
| 8843 | |
| 8844 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8845 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8846 | break; |
| 8847 | } |
| 8848 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8849 | 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"); |
| 8850 | } |
| 8851 | } |
| 8852 | |
| 8853 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8854 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8855 | if (curproxy->bind_proc) |
| 8856 | continue; |
| 8857 | |
| 8858 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8859 | unsigned long mask; |
| 8860 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8861 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8862 | curproxy->bind_proc |= mask; |
| 8863 | } |
| 8864 | |
| 8865 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8866 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8867 | } |
| 8868 | |
| 8869 | if (global.stats_fe) { |
| 8870 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8871 | unsigned long mask; |
| 8872 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8873 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8874 | global.stats_fe->bind_proc |= mask; |
| 8875 | } |
| 8876 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8877 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8878 | } |
| 8879 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8880 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8881 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8882 | */ |
| 8883 | if (!cfgerr) { |
| 8884 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8885 | if (curproxy->cap & PR_CAP_FE) |
| 8886 | propagate_processes(curproxy, NULL); |
| 8887 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8888 | } |
| 8889 | |
| 8890 | /* Bind each unbound backend to all processes when not specified. */ |
| 8891 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8892 | if (curproxy->bind_proc) |
| 8893 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8894 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8895 | } |
| 8896 | |
| 8897 | /*******************************************************/ |
| 8898 | /* At this step, all proxies have a non-null bind_proc */ |
| 8899 | /*******************************************************/ |
| 8900 | |
| 8901 | /* perform the final checks before creating tasks */ |
| 8902 | |
| 8903 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8904 | struct listener *listener; |
| 8905 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8906 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8907 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8908 | /* Configure SSL for each bind line. |
| 8909 | * Note: if configuration fails at some point, the ->ctx member |
| 8910 | * remains NULL so that listeners can later detach. |
| 8911 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8912 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8913 | int alloc_ctx; |
| 8914 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8915 | if (!bind_conf->is_ssl) { |
| 8916 | if (bind_conf->default_ctx) { |
| 8917 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 8918 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8919 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8920 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8921 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8922 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8923 | Alert("Proxy '%s': no SSL certificate specified for bind '%s' at [%s:%d] (use 'crt').\n", |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8924 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8925 | cfgerr++; |
| 8926 | continue; |
| 8927 | } |
| 8928 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 8929 | alloc_ctx = shared_context_init(global.tune.sslcachesize, (!global.tune.sslprivatecache && (global.nbproc > 1)) ? 1 : 0); |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8930 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8931 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 8932 | Alert("Unable to initialize the lock for the shared SSL session cache. You can retry using the global statement 'tune.ssl.force-private-cache' but it could increase CPU usage due to renegotiations if nbproc > 1.\n"); |
| 8933 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8934 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8935 | cfgerr++; |
| 8936 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8937 | } |
| 8938 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8939 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8940 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8941 | |
| 8942 | /* initialize CA variables if the certificates generation is enabled */ |
| 8943 | cfgerr += ssl_sock_load_ca(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8944 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8945 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8946 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8947 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8948 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8949 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8950 | int nbproc; |
| 8951 | |
| 8952 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8953 | (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] | 8954 | nbits(global.nbproc)); |
| 8955 | |
| 8956 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8957 | nbproc = 1; |
| 8958 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8959 | if (!listener->luid) { |
| 8960 | /* listener ID not set, use automatic numbering with first |
| 8961 | * spare entry starting with next_luid. |
| 8962 | */ |
| 8963 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8964 | listener->conf.id.key = listener->luid = next_id; |
| 8965 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8966 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8967 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8968 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8969 | /* enable separate counters */ |
| 8970 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8971 | listener->counters = calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8972 | if (!listener->name) |
| 8973 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8974 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8975 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8976 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8977 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8978 | if (!listener->maxconn) |
| 8979 | listener->maxconn = curproxy->maxconn; |
| 8980 | if (!listener->backlog) |
| 8981 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8982 | if (!listener->maxaccept) |
| 8983 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8984 | |
| 8985 | /* we want to have an optimal behaviour on single process mode to |
| 8986 | * maximize the work at once, but in multi-process we want to keep |
| 8987 | * some fairness between processes, so we target half of the max |
| 8988 | * number of events to be balanced over all the processes the proxy |
| 8989 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8990 | * used to disable the limit. |
| 8991 | */ |
| 8992 | if (listener->maxaccept > 0) { |
| 8993 | if (nbproc > 1) |
| 8994 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8995 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8996 | } |
| 8997 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8998 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8999 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 9000 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 9001 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 9002 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9003 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 9004 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9005 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 9006 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 9007 | listener->options |= LI_O_TCP_L5_RULES; |
| 9008 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 9009 | if (curproxy->mon_mask.s_addr) |
| 9010 | listener->options |= LI_O_CHK_MONNET; |
| 9011 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9012 | /* smart accept mode is automatic in HTTP mode */ |
| 9013 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9014 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9015 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 9016 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 9017 | } |
| 9018 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9019 | /* Release unused SSL configs */ |
| 9020 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 9021 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9022 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9023 | #ifdef USE_OPENSSL |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9024 | ssl_sock_free_ca(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9025 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 9026 | free(bind_conf->ca_file); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9027 | free(bind_conf->ca_sign_file); |
| 9028 | free(bind_conf->ca_sign_pass); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9029 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 9030 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 9031 | free(bind_conf->crl_file); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 9032 | if(bind_conf->keys_ref) { |
| 9033 | free(bind_conf->keys_ref->filename); |
| 9034 | free(bind_conf->keys_ref->tlskeys); |
William Lallemand | 7bba4cc | 2016-05-20 17:28:07 +0200 | [diff] [blame] | 9035 | LIST_DEL(&bind_conf->keys_ref->list); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 9036 | free(bind_conf->keys_ref); |
| 9037 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9038 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9039 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9040 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 9041 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9042 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9043 | int count, maxproc = 0; |
| 9044 | |
| 9045 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9046 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9047 | if (count > maxproc) |
| 9048 | maxproc = count; |
| 9049 | } |
| 9050 | /* backends have 0, frontends have 1 or more */ |
| 9051 | if (maxproc != 1) |
| 9052 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 9053 | " limited to process assigned to the current request.\n", |
| 9054 | curproxy->id); |
| 9055 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9056 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 9057 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 9058 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9059 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9060 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9061 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 9062 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 9063 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9064 | } |
| 9065 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9066 | |
| 9067 | /* create the task associated with the proxy */ |
| 9068 | curproxy->task = task_new(); |
| 9069 | if (curproxy->task) { |
| 9070 | curproxy->task->context = curproxy; |
| 9071 | curproxy->task->process = manage_proxy; |
| 9072 | /* no need to queue, it will be done automatically if some |
| 9073 | * listener gets limited. |
| 9074 | */ |
| 9075 | curproxy->task->expire = TICK_ETERNITY; |
| 9076 | } else { |
| 9077 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 9078 | curproxy->id); |
| 9079 | cfgerr++; |
| 9080 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 9081 | } |
| 9082 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9083 | /* automatically compute fullconn if not set. We must not do it in the |
| 9084 | * loop above because cross-references are not yet fully resolved. |
| 9085 | */ |
| 9086 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9087 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9088 | * the possible incoming frontend's maxconns. |
| 9089 | */ |
| 9090 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 9091 | struct proxy *fe; |
| 9092 | int total = 0; |
| 9093 | |
| 9094 | /* sum up the number of maxconns of frontends which |
| 9095 | * reference this backend at least once or which are |
| 9096 | * the same one ('listen'). |
| 9097 | */ |
| 9098 | for (fe = proxy; fe; fe = fe->next) { |
| 9099 | struct switching_rule *rule; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9100 | int found = 0; |
| 9101 | |
| 9102 | if (!(fe->cap & PR_CAP_FE)) |
| 9103 | continue; |
| 9104 | |
| 9105 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 9106 | found = 1; |
| 9107 | |
| 9108 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 9109 | found = 1; |
| 9110 | |
| 9111 | /* check if a "use_backend" rule matches */ |
| 9112 | if (!found) { |
| 9113 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9114 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9115 | found = 1; |
| 9116 | break; |
| 9117 | } |
| 9118 | } |
| 9119 | } |
| 9120 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9121 | /* now we've checked all possible ways to reference a backend |
| 9122 | * from a frontend. |
| 9123 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9124 | if (!found) |
| 9125 | continue; |
| 9126 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9127 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9128 | /* we have the sum of the maxconns in <total>. We only |
| 9129 | * keep 10% of that sum to set the default fullconn, with |
| 9130 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9131 | */ |
| 9132 | curproxy->fullconn = (total + 9) / 10; |
| 9133 | if (!curproxy->fullconn) |
| 9134 | curproxy->fullconn = 1; |
| 9135 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9136 | } |
| 9137 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9138 | /* |
| 9139 | * Recount currently required checks. |
| 9140 | */ |
| 9141 | |
| 9142 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 9143 | int optnum; |
| 9144 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9145 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9146 | if (curproxy->options & cfg_opts[optnum].val) |
| 9147 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9148 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9149 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9150 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9151 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9152 | } |
| 9153 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9154 | /* compute the required process bindings for the peers */ |
| 9155 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 9156 | if (curproxy->table.peers.p) |
| 9157 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9158 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9159 | if (peers) { |
| 9160 | struct peers *curpeers = peers, **last; |
| 9161 | struct peer *p, *pb; |
| 9162 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9163 | /* Remove all peers sections which don't have a valid listener, |
| 9164 | * which are not used by any table, or which are bound to more |
| 9165 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9166 | */ |
| 9167 | last = &peers; |
| 9168 | while (*last) { |
| 9169 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9170 | |
| 9171 | if (curpeers->state == PR_STSTOPPED) { |
| 9172 | /* the "disabled" keyword was present */ |
| 9173 | if (curpeers->peers_fe) |
| 9174 | stop_proxy(curpeers->peers_fe); |
| 9175 | curpeers->peers_fe = NULL; |
| 9176 | } |
| 9177 | else if (!curpeers->peers_fe) { |
| 9178 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9179 | curpeers->id, localpeer); |
| 9180 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9181 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9182 | /* either it's totally stopped or too much used */ |
| 9183 | if (curpeers->peers_fe->bind_proc) { |
| 9184 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 9185 | "running in different processes (%d different ones). " |
| 9186 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9187 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9188 | cfgerr++; |
| 9189 | } |
| 9190 | stop_proxy(curpeers->peers_fe); |
| 9191 | curpeers->peers_fe = NULL; |
| 9192 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9193 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9194 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9195 | last = &curpeers->next; |
| 9196 | continue; |
| 9197 | } |
| 9198 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9199 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9200 | p = curpeers->remote; |
| 9201 | while (p) { |
| 9202 | pb = p->next; |
| 9203 | free(p->id); |
| 9204 | free(p); |
| 9205 | p = pb; |
| 9206 | } |
| 9207 | |
| 9208 | /* Destroy and unlink this curpeers section. |
| 9209 | * Note: curpeers is backed up into *last. |
| 9210 | */ |
| 9211 | free(curpeers->id); |
| 9212 | curpeers = curpeers->next; |
| 9213 | free(*last); |
| 9214 | *last = curpeers; |
| 9215 | } |
| 9216 | } |
| 9217 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9218 | /* initialize stick-tables on backend capable proxies. This must not |
| 9219 | * be done earlier because the data size may be discovered while parsing |
| 9220 | * other proxies. |
| 9221 | */ |
| 9222 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9223 | if (curproxy->state == PR_STSTOPPED) |
| 9224 | continue; |
| 9225 | |
| 9226 | if (!stktable_init(&curproxy->table)) { |
| 9227 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9228 | cfgerr++; |
| 9229 | } |
| 9230 | } |
| 9231 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9232 | if (mailers) { |
| 9233 | struct mailers *curmailers = mailers, **last; |
| 9234 | struct mailer *m, *mb; |
| 9235 | |
| 9236 | /* Remove all mailers sections which don't have a valid listener. |
| 9237 | * This can happen when a mailers section is never referenced. |
| 9238 | */ |
| 9239 | last = &mailers; |
| 9240 | while (*last) { |
| 9241 | curmailers = *last; |
| 9242 | if (curmailers->users) { |
| 9243 | last = &curmailers->next; |
| 9244 | continue; |
| 9245 | } |
| 9246 | |
| 9247 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9248 | curmailers->id); |
| 9249 | |
| 9250 | m = curmailers->mailer_list; |
| 9251 | while (m) { |
| 9252 | mb = m->next; |
| 9253 | free(m->id); |
| 9254 | free(m); |
| 9255 | m = mb; |
| 9256 | } |
| 9257 | |
| 9258 | /* Destroy and unlink this curmailers section. |
| 9259 | * Note: curmailers is backed up into *last. |
| 9260 | */ |
| 9261 | free(curmailers->id); |
| 9262 | curmailers = curmailers->next; |
| 9263 | free(*last); |
| 9264 | *last = curmailers; |
| 9265 | } |
| 9266 | } |
| 9267 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9268 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9269 | * a server-state file locally defined and none has been provided */ |
| 9270 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9271 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9272 | curproxy->server_state_file_name == NULL) |
| 9273 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9274 | } |
| 9275 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9276 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9277 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9278 | MEM_F_SHARED); |
| 9279 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9280 | if (cfgerr > 0) |
| 9281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9282 | out: |
| 9283 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9284 | } |
| 9285 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9286 | /* |
| 9287 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9288 | * parsing sessions. |
| 9289 | */ |
| 9290 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9291 | { |
| 9292 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9293 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9294 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9295 | /* |
| 9296 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9297 | */ |
| 9298 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9299 | { |
| 9300 | LIST_DEL(&kwl->list); |
| 9301 | LIST_INIT(&kwl->list); |
| 9302 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9303 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9304 | /* this function register new section in the haproxy configuration file. |
| 9305 | * <section_name> is the name of this new section and <section_parser> |
| 9306 | * is the called parser. If two section declaration have the same name, |
| 9307 | * only the first declared is used. |
| 9308 | */ |
| 9309 | int cfg_register_section(char *section_name, |
| 9310 | int (*section_parser)(const char *, int, char **, int)) |
| 9311 | { |
| 9312 | struct cfg_section *cs; |
| 9313 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9314 | list_for_each_entry(cs, §ions, list) { |
| 9315 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9316 | Alert("register section '%s': already registered.\n", section_name); |
| 9317 | return 0; |
| 9318 | } |
| 9319 | } |
| 9320 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9321 | cs = calloc(1, sizeof(*cs)); |
| 9322 | if (!cs) { |
| 9323 | Alert("register section '%s': out of memory.\n", section_name); |
| 9324 | return 0; |
| 9325 | } |
| 9326 | |
| 9327 | cs->section_name = section_name; |
| 9328 | cs->section_parser = section_parser; |
| 9329 | |
| 9330 | LIST_ADDQ(§ions, &cs->list); |
| 9331 | |
| 9332 | return 1; |
| 9333 | } |
| 9334 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9335 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9336 | * free all config section entries |
| 9337 | */ |
| 9338 | void cfg_unregister_sections(void) |
| 9339 | { |
| 9340 | struct cfg_section *cs, *ics; |
| 9341 | |
| 9342 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9343 | LIST_DEL(&cs->list); |
| 9344 | free(cs); |
| 9345 | } |
| 9346 | } |
| 9347 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9348 | void cfg_backup_sections(struct list *backup_sections) |
| 9349 | { |
| 9350 | struct cfg_section *cs, *ics; |
| 9351 | |
| 9352 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9353 | LIST_DEL(&cs->list); |
| 9354 | LIST_ADDQ(backup_sections, &cs->list); |
| 9355 | } |
| 9356 | } |
| 9357 | |
| 9358 | void cfg_restore_sections(struct list *backup_sections) |
| 9359 | { |
| 9360 | struct cfg_section *cs, *ics; |
| 9361 | |
| 9362 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9363 | LIST_DEL(&cs->list); |
| 9364 | LIST_ADDQ(§ions, &cs->list); |
| 9365 | } |
| 9366 | } |
| 9367 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9368 | __attribute__((constructor)) |
| 9369 | static void cfgparse_init(void) |
| 9370 | { |
| 9371 | /* Register internal sections */ |
| 9372 | cfg_register_section("listen", cfg_parse_listen); |
| 9373 | cfg_register_section("frontend", cfg_parse_listen); |
| 9374 | cfg_register_section("backend", cfg_parse_listen); |
| 9375 | cfg_register_section("defaults", cfg_parse_listen); |
| 9376 | cfg_register_section("global", cfg_parse_global); |
| 9377 | cfg_register_section("userlist", cfg_parse_users); |
| 9378 | cfg_register_section("peers", cfg_parse_peers); |
| 9379 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9380 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9381 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9382 | } |
| 9383 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9384 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9385 | * Local variables: |
| 9386 | * c-indent-level: 8 |
| 9387 | * c-basic-offset: 8 |
| 9388 | * End: |
| 9389 | */ |