Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Configuration parser |
| 3 | * |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_HAP_CRYPT |
| 14 | /* This is to have crypt() defined on Linux */ |
| 15 | #define _GNU_SOURCE |
| 16 | |
| 17 | #ifdef NEED_CRYPT_H |
| 18 | /* some platforms such as Solaris need this */ |
| 19 | #include <crypt.h> |
| 20 | #endif |
| 21 | #endif /* CONFIG_HAP_CRYPT */ |
| 22 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <netdb.h> |
| 27 | #include <ctype.h> |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 28 | #include <pwd.h> |
| 29 | #include <grp.h> |
Willy Tarreau | 0b4ed90 | 2007-03-26 00:18:40 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <unistd.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 36 | #include <common/cfgparse.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 37 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 38 | #include <common/config.h> |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 39 | #include <common/errors.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 40 | #include <common/memory.h> |
| 41 | #include <common/standard.h> |
| 42 | #include <common/time.h> |
| 43 | #include <common/uri_auth.h> |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 44 | #include <common/namespace.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
| 46 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 47 | #include <types/compression.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 48 | #include <types/filters.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 50 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 51 | #include <types/peers.h> |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 52 | #include <types/mailers.h> |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 53 | #include <types/dns.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 55 | #include <proto/acl.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 56 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 58 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 60 | #include <proto/compression.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 61 | #include <proto/dumpstats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 62 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 63 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 64 | #include <proto/hdr_idx.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 65 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 66 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 67 | #include <proto/lb_fwlc.h> |
| 68 | #include <proto/lb_fwrr.h> |
| 69 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 70 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 72 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 73 | #include <proto/proto_tcp.h> |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 74 | #include <proto/proto_uxst.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 75 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 76 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 77 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 78 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 79 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 80 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 81 | #include <proto/stream.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 82 | #include <proto/raw_sock.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 83 | #include <proto/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 84 | #include <proto/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 86 | #ifdef USE_OPENSSL |
| 87 | #include <types/ssl_sock.h> |
| 88 | #include <proto/ssl_sock.h> |
| 89 | #include <proto/shctx.h> |
| 90 | #endif /*USE_OPENSSL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 91 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 92 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 93 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 94 | * |
| 95 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 96 | */ |
| 97 | const char sslv3_client_hello_pkt[] = { |
| 98 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 99 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 100 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 101 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 102 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 103 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 104 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 105 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 106 | "\x00" /* Session ID length : empty (no session ID) */ |
| 107 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 108 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 109 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 110 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 111 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 112 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 113 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 114 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 115 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 116 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 117 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 118 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 119 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 120 | }; |
| 121 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 122 | /* various keyword modifiers */ |
| 123 | enum kw_mod { |
| 124 | KWM_STD = 0, /* normal */ |
| 125 | KWM_NO, /* "no" prefixed before the keyword */ |
| 126 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 127 | }; |
| 128 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 129 | /* permit to store configuration section */ |
| 130 | struct cfg_section { |
| 131 | struct list list; |
| 132 | char *section_name; |
| 133 | int (*section_parser)(const char *, int, char **, int); |
| 134 | }; |
| 135 | |
| 136 | /* Used to chain configuration sections definitions. This list |
| 137 | * stores struct cfg_section |
| 138 | */ |
| 139 | struct list sections = LIST_HEAD_INIT(sections); |
| 140 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 141 | /* some of the most common options which are also the easiest to handle */ |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 142 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 143 | const char *name; |
| 144 | unsigned int val; |
| 145 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 146 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 147 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* proxy->options */ |
| 151 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 152 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 153 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 154 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 155 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 156 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 157 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 158 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 159 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 160 | { "http-buffer-request", PR_O_WREQ_BODY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 0f228a0 | 2015-05-01 15:37:53 +0200 | [diff] [blame] | 161 | { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 9420b12 | 2013-12-15 18:58:25 +0100 | [diff] [blame] | 162 | { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 163 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 164 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 165 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 166 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 167 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 168 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 169 | #else |
| 170 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 171 | #endif |
| 172 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 173 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 176 | /* proxy->options2 */ |
| 177 | static const struct cfg_opt cfg_opts2[] = |
| 178 | { |
| 179 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 180 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 181 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 182 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 183 | #else |
| 184 | { "splice-request", 0, 0, 0, 0 }, |
| 185 | { "splice-response", 0, 0, 0, 0 }, |
| 186 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 187 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 188 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 189 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 190 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 191 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 192 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 193 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 194 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 195 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 196 | { "independant-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Jamie Gloudon | 801a0a3 | 2012-08-25 00:18:33 -0400 | [diff] [blame] | 197 | { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 198 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 199 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 200 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 201 | { NULL, 0, 0, 0 } |
| 202 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 204 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 206 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 207 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 208 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 209 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 210 | /* List head of all known configuration keywords */ |
| 211 | static struct cfg_kw_list cfg_keywords = { |
| 212 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 213 | }; |
| 214 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 215 | /* |
| 216 | * converts <str> to a list of listeners which are dynamically allocated. |
| 217 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 218 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 219 | * - <port> is a numerical port from 1 to 65535 ; |
| 220 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 221 | * 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] | 222 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 223 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 224 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 225 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 226 | 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] | 227 | { |
| 228 | struct listener *l; |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 229 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | int port, end; |
| 231 | |
| 232 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 233 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 234 | while (next && *next) { |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 235 | struct sockaddr_storage ss, *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 236 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 237 | |
| 238 | str = next; |
| 239 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 240 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 241 | *next++ = 0; |
| 242 | } |
| 243 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 244 | ss2 = str2sa_range(str, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 245 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 246 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 247 | if (!ss2) |
| 248 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 250 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 251 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 252 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 253 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 254 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 255 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 256 | if (!port || !end) { |
| 257 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 258 | goto fail; |
| 259 | } |
| 260 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 261 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 262 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 263 | goto fail; |
| 264 | } |
| 265 | |
| 266 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 267 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 268 | goto fail; |
| 269 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 270 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 271 | else if (ss2->ss_family == AF_UNSPEC) { |
| 272 | socklen_t addr_len; |
| 273 | |
| 274 | /* We want to attach to an already bound fd whose number |
| 275 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 276 | * Note that by definition there is a single listener. |
| 277 | * We still have to determine the address family to |
| 278 | * register the correct protocol. |
| 279 | */ |
| 280 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 281 | addr_len = sizeof(*ss2); |
| 282 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 283 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 284 | goto fail; |
| 285 | } |
| 286 | |
| 287 | port = end = get_host_port(ss2); |
| 288 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 289 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 290 | /* OK the address looks correct */ |
Vincent Bernat | 6e61589 | 2016-05-18 16:17:44 +0200 | [diff] [blame] | 291 | memcpy(&ss, ss2, sizeof(ss)); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 292 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | for (; port <= end; port++) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 294 | l = calloc(1, sizeof(*l)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 295 | l->obj_type = OBJ_TYPE_LISTENER; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 296 | LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe); |
| 297 | LIST_ADDQ(&bind_conf->listeners, &l->by_bind); |
| 298 | l->frontend = curproxy; |
| 299 | l->bind_conf = bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 300 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 301 | l->fd = fd; |
Vincent Bernat | 6e46ff1 | 2016-05-19 11:29:43 +0200 | [diff] [blame] | 302 | memcpy(&l->addr, &ss, sizeof(ss)); |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 303 | l->xprt = &raw_sock; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 304 | l->state = LI_INIT; |
| 305 | |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 306 | if (ss.ss_family == AF_INET) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 307 | ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port); |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 308 | tcpv4_add_listener(l); |
| 309 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 310 | else if (ss.ss_family == AF_INET6) { |
| 311 | ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port); |
| 312 | tcpv6_add_listener(l); |
| 313 | } |
| 314 | else { |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 315 | uxst_add_listener(l); |
| 316 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 317 | |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 318 | jobs++; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 319 | listeners++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 320 | } /* end for(port) */ |
| 321 | } /* end while(next) */ |
| 322 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 323 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 324 | fail: |
| 325 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 326 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 327 | } |
| 328 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 329 | /* |
| 330 | * Report a fatal Alert when there is too much arguments |
| 331 | * The index is the current keyword in args |
| 332 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 333 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 334 | */ |
| 335 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 336 | { |
| 337 | char *kw = NULL; |
| 338 | int i; |
| 339 | |
| 340 | if (!*args[index + maxarg + 1]) |
| 341 | return 0; |
| 342 | |
| 343 | memprintf(&kw, "%s", args[0]); |
| 344 | for (i = 1; i <= index; i++) { |
| 345 | memprintf(&kw, "%s %s", kw, args[i]); |
| 346 | } |
| 347 | |
| 348 | Alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
| 349 | free(kw); |
| 350 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 351 | return 1; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * same as alertif_too_many_args_idx with a 0 index |
| 356 | */ |
| 357 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 358 | { |
| 359 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 360 | } |
| 361 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 362 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 363 | * Return 1 if the warning has been emitted, otherwise 0. |
| 364 | */ |
| 365 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 366 | { |
| 367 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 368 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 369 | file, line, arg); |
| 370 | return 1; |
| 371 | } |
| 372 | return 0; |
| 373 | } |
| 374 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 375 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 376 | * Return 1 if the warning has been emitted, otherwise 0. |
| 377 | */ |
| 378 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 379 | { |
| 380 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 381 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 382 | file, line, arg); |
| 383 | return 1; |
| 384 | } |
| 385 | return 0; |
| 386 | } |
| 387 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 388 | /* Report a warning if a rule is placed after a 'block' rule. |
| 389 | * Return 1 if the warning has been emitted, otherwise 0. |
| 390 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 391 | 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] | 392 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 393 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 394 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 395 | file, line, arg); |
| 396 | return 1; |
| 397 | } |
| 398 | return 0; |
| 399 | } |
| 400 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 401 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 402 | * Return 1 if the warning has been emitted, otherwise 0. |
| 403 | */ |
| 404 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 405 | { |
| 406 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 407 | Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 408 | file, line, arg); |
| 409 | return 1; |
| 410 | } |
| 411 | return 0; |
| 412 | } |
| 413 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 414 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 415 | * Return 1 if the warning has been emitted, otherwise 0. |
| 416 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 417 | 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] | 418 | { |
| 419 | if (proxy->req_exp) { |
| 420 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 421 | file, line, arg); |
| 422 | return 1; |
| 423 | } |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /* Report a warning if a rule is placed after a reqadd rule. |
| 428 | * Return 1 if the warning has been emitted, otherwise 0. |
| 429 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 430 | 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] | 431 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 432 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 433 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 434 | file, line, arg); |
| 435 | return 1; |
| 436 | } |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* Report a warning if a rule is placed after a redirect rule. |
| 441 | * Return 1 if the warning has been emitted, otherwise 0. |
| 442 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 443 | 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] | 444 | { |
| 445 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 446 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 447 | file, line, arg); |
| 448 | return 1; |
| 449 | } |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 454 | * Return 1 if the warning has been emitted, otherwise 0. |
| 455 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 459 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 460 | file, line, arg); |
| 461 | return 1; |
| 462 | } |
| 463 | return 0; |
| 464 | } |
| 465 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 466 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 467 | * Return 1 if the warning has been emitted, otherwise 0. |
| 468 | */ |
| 469 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 470 | { |
| 471 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 472 | Warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 473 | file, line, arg); |
| 474 | return 1; |
| 475 | } |
| 476 | return 0; |
| 477 | } |
| 478 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 479 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 480 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 481 | { |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 482 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 483 | warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 484 | warnif_rule_after_block(proxy, file, line, arg) || |
| 485 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 486 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 487 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 488 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 489 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 490 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 491 | } |
| 492 | |
| 493 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 494 | { |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 495 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 496 | warnif_rule_after_block(proxy, file, line, arg) || |
| 497 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 498 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 499 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 500 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 501 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 502 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 503 | } |
| 504 | |
| 505 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 506 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 507 | { |
| 508 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 509 | warnif_rule_after_http_req(proxy, file, line, arg) || |
| 510 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 511 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 512 | warnif_rule_after_redirect(proxy, file, line, arg) || |
| 513 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 514 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 515 | } |
| 516 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 517 | /* report a warning if a block rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 518 | 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] | 519 | { |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 520 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 521 | warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 522 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 523 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 524 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 525 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /* report a warning if an http-request rule is dangerously placed */ |
| 529 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 530 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 531 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
| 532 | warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 533 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 534 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 535 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /* report a warning if a reqxxx rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 539 | 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] | 540 | { |
| 541 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 542 | warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 543 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 544 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* report a warning if a reqadd rule is dangerously placed */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 548 | 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] | 549 | { |
| 550 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 551 | warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 552 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 553 | } |
| 554 | |
| 555 | /* report a warning if a redirect rule is dangerously placed */ |
| 556 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 557 | { |
| 558 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 559 | warnif_rule_after_use_server(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 562 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 563 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 564 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 565 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 566 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 567 | 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] | 568 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 569 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 570 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 571 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 572 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 573 | return 0; |
| 574 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 575 | acl = acl_cond_conflicts(cond, where); |
| 576 | if (acl) { |
| 577 | if (acl->name && *acl->name) |
| 578 | Warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 579 | file, line, acl->name, sample_ckp_names(where)); |
| 580 | else |
| 581 | 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] | 582 | 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] | 583 | return ERR_WARN; |
| 584 | } |
| 585 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 586 | return 0; |
| 587 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 588 | if (acl->name && *acl->name) |
| 589 | 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] | 590 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 591 | else |
| 592 | 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] | 593 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 594 | return ERR_WARN; |
| 595 | } |
| 596 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 597 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 598 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 599 | * any combination of : |
| 600 | * - ERR_ABORT: must abort ASAP |
| 601 | * - ERR_FATAL: we can continue parsing but not start the service |
| 602 | * - ERR_WARN: a warning has been emitted |
| 603 | * - ERR_ALERT: an alert has been emitted |
| 604 | * Only the two first ones can stop processing, the two others are just |
| 605 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 606 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 607 | 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] | 608 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 609 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 610 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 611 | |
| 612 | if (!strcmp(args[0], "global")) { /* new section */ |
| 613 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 614 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 615 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 616 | } |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 617 | else if (!strcmp(args[0], "ca-base")) { |
| 618 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 619 | if(alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 620 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 621 | if (global.ca_base != NULL) { |
| 622 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 623 | err_code |= ERR_ALERT; |
| 624 | goto out; |
| 625 | } |
| 626 | if (*(args[1]) == 0) { |
| 627 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 629 | goto out; |
| 630 | } |
| 631 | global.ca_base = strdup(args[1]); |
| 632 | #else |
| 633 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 635 | goto out; |
| 636 | #endif |
| 637 | } |
| 638 | else if (!strcmp(args[0], "crt-base")) { |
| 639 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 640 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 641 | goto out; |
Emeric Brun | c8e8d12 | 2012-10-02 18:42:10 +0200 | [diff] [blame] | 642 | if (global.crt_base != NULL) { |
| 643 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 644 | err_code |= ERR_ALERT; |
| 645 | goto out; |
| 646 | } |
| 647 | if (*(args[1]) == 0) { |
| 648 | Alert("parsing [%s:%d] : '%s' expects a directory path as an argument.\n", file, linenum, args[0]); |
| 649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 650 | goto out; |
| 651 | } |
| 652 | global.crt_base = strdup(args[1]); |
| 653 | #else |
| 654 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 656 | goto out; |
| 657 | #endif |
| 658 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 659 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 660 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 661 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 662 | global.mode |= MODE_DAEMON; |
| 663 | } |
| 664 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 665 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 666 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 667 | global.mode |= MODE_DEBUG; |
| 668 | } |
| 669 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 670 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 671 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 672 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 673 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 674 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 675 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 676 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 677 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 678 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 679 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 680 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 681 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 682 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 683 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 684 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 685 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 686 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 687 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 688 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 689 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 690 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 691 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 692 | global.tune.options &= ~GTUNE_USE_GAI; |
| 693 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 694 | else if (!strcmp(args[0], "noreuseport")) { |
| 695 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 696 | goto out; |
| 697 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 698 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 699 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 700 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 701 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 702 | global.mode |= MODE_QUIET; |
| 703 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 704 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 705 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 706 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 707 | if (global.tune.maxpollevents != 0) { |
| 708 | 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] | 709 | err_code |= ERR_ALERT; |
| 710 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 711 | } |
| 712 | if (*(args[1]) == 0) { |
| 713 | 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] | 714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 715 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 716 | } |
| 717 | global.tune.maxpollevents = atol(args[1]); |
| 718 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 719 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 720 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 721 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 722 | if (global.tune.maxaccept != 0) { |
| 723 | 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] | 724 | err_code |= ERR_ALERT; |
| 725 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 726 | } |
| 727 | if (*(args[1]) == 0) { |
| 728 | 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] | 729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 730 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 731 | } |
| 732 | global.tune.maxaccept = atol(args[1]); |
| 733 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 734 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 735 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 736 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 737 | if (*(args[1]) == 0) { |
| 738 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 740 | goto out; |
| 741 | } |
| 742 | global.tune.chksize = atol(args[1]); |
| 743 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 744 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 745 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 746 | goto out; |
| 747 | if (*(args[1]) == 0) { |
| 748 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 749 | err_code |= ERR_ALERT | ERR_FATAL; |
| 750 | goto out; |
| 751 | } |
| 752 | global.tune.recv_enough = atol(args[1]); |
| 753 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 754 | #ifdef USE_OPENSSL |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 755 | else if (!strcmp(args[0], "tune.ssl.force-private-cache")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 756 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 757 | goto out; |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 758 | global.tune.sslprivatecache = 1; |
| 759 | } |
Willy Tarreau | 6ec58db | 2012-11-16 16:32:15 +0100 | [diff] [blame] | 760 | else if (!strcmp(args[0], "tune.ssl.cachesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 761 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 762 | goto out; |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 763 | if (*(args[1]) == 0) { |
| 764 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 765 | err_code |= ERR_ALERT | ERR_FATAL; |
| 766 | goto out; |
| 767 | } |
| 768 | global.tune.sslcachesize = atol(args[1]); |
| 769 | } |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 770 | else if (!strcmp(args[0], "tune.ssl.lifetime")) { |
| 771 | unsigned int ssllifetime; |
| 772 | const char *res; |
| 773 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 774 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 775 | goto out; |
Emeric Brun | 4f65bff | 2012-11-16 15:11:00 +0100 | [diff] [blame] | 776 | if (*(args[1]) == 0) { |
| 777 | Alert("parsing [%s:%d] : '%s' expects ssl sessions <lifetime> in seconds as argument.\n", file, linenum, args[0]); |
| 778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 779 | goto out; |
| 780 | } |
| 781 | |
| 782 | res = parse_time_err(args[1], &ssllifetime, TIME_UNIT_S); |
| 783 | if (res) { |
| 784 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 785 | file, linenum, *res, args[0]); |
| 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | goto out; |
| 788 | } |
| 789 | |
| 790 | global.tune.ssllifetime = ssllifetime; |
| 791 | } |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 792 | else if (!strcmp(args[0], "tune.ssl.maxrecord")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 794 | goto out; |
Willy Tarreau | bfd5946 | 2013-02-21 07:46:09 +0100 | [diff] [blame] | 795 | if (*(args[1]) == 0) { |
| 796 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 798 | goto out; |
| 799 | } |
| 800 | global.tune.ssl_max_record = atol(args[1]); |
| 801 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 802 | #ifndef OPENSSL_NO_DH |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 803 | else if (!strcmp(args[0], "tune.ssl.default-dh-param")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 804 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 805 | goto out; |
Remi Gacogne | f46cd6e | 2014-06-12 14:58:40 +0200 | [diff] [blame] | 806 | if (*(args[1]) == 0) { |
| 807 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 809 | goto out; |
| 810 | } |
| 811 | global.tune.ssl_default_dh_param = atol(args[1]); |
| 812 | if (global.tune.ssl_default_dh_param < 1024) { |
| 813 | Alert("parsing [%s:%d] : '%s' expects a value >= 1024.\n", file, linenum, args[0]); |
| 814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 815 | goto out; |
| 816 | } |
| 817 | } |
Emeric Brun | fc32aca | 2012-09-03 12:10:29 +0200 | [diff] [blame] | 818 | #endif |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 819 | else if (!strcmp(args[0], "tune.ssl.ssl-ctx-cache-size")) { |
| 820 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 821 | goto out; |
| 822 | if (*(args[1]) == 0) { |
| 823 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 824 | err_code |= ERR_ALERT | ERR_FATAL; |
| 825 | goto out; |
| 826 | } |
| 827 | global.tune.ssl_ctx_cache = atoi(args[1]); |
| 828 | if (global.tune.ssl_ctx_cache < 0) { |
| 829 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 830 | file, linenum, args[0]); |
| 831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 832 | goto out; |
| 833 | } |
| 834 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 835 | #endif |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 836 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 837 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 838 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 839 | if (*(args[1]) == 0) { |
| 840 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 842 | goto out; |
| 843 | } |
| 844 | global.tune.buf_limit = atol(args[1]); |
| 845 | if (global.tune.buf_limit) { |
| 846 | if (global.tune.buf_limit < 3) |
| 847 | global.tune.buf_limit = 3; |
| 848 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 849 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 850 | } |
| 851 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 852 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 853 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 854 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 855 | if (*(args[1]) == 0) { |
| 856 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 858 | goto out; |
| 859 | } |
| 860 | global.tune.reserved_bufs = atol(args[1]); |
| 861 | if (global.tune.reserved_bufs < 2) |
| 862 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 863 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 864 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 865 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 866 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 867 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 868 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 869 | if (*(args[1]) == 0) { |
| 870 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 872 | goto out; |
| 873 | } |
| 874 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 875 | if (global.tune.bufsize <= 0) { |
| 876 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
| 879 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 880 | chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize); |
Willy Tarreau | 2819e99 | 2013-12-13 14:41:10 +0100 | [diff] [blame] | 881 | alloc_trash_buffers(global.tune.bufsize); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 882 | } |
| 883 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 884 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 885 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 886 | if (*(args[1]) == 0) { |
| 887 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 889 | goto out; |
| 890 | } |
| 891 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 892 | if (global.tune.maxrewrite < 0) { |
| 893 | Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 894 | err_code |= ERR_ALERT | ERR_FATAL; |
| 895 | goto out; |
| 896 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 897 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 898 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 899 | unsigned int idle; |
| 900 | const char *res; |
| 901 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 902 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 903 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 904 | if (*(args[1]) == 0) { |
| 905 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto out; |
| 908 | } |
| 909 | |
| 910 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 911 | if (res) { |
| 912 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 913 | file, linenum, *res, args[0]); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
| 917 | |
| 918 | if (idle > 65535) { |
| 919 | Alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 920 | err_code |= ERR_ALERT | ERR_FATAL; |
| 921 | goto out; |
| 922 | } |
| 923 | global.tune.idle_timer = idle; |
| 924 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 925 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 926 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 927 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 928 | if (global.tune.client_rcvbuf != 0) { |
| 929 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 930 | err_code |= ERR_ALERT; |
| 931 | goto out; |
| 932 | } |
| 933 | if (*(args[1]) == 0) { |
| 934 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 936 | goto out; |
| 937 | } |
| 938 | global.tune.client_rcvbuf = atol(args[1]); |
| 939 | } |
| 940 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 941 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 942 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 943 | if (global.tune.server_rcvbuf != 0) { |
| 944 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 945 | err_code |= ERR_ALERT; |
| 946 | goto out; |
| 947 | } |
| 948 | if (*(args[1]) == 0) { |
| 949 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
| 952 | } |
| 953 | global.tune.server_rcvbuf = atol(args[1]); |
| 954 | } |
| 955 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 956 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 957 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 958 | if (global.tune.client_sndbuf != 0) { |
| 959 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 960 | err_code |= ERR_ALERT; |
| 961 | goto out; |
| 962 | } |
| 963 | if (*(args[1]) == 0) { |
| 964 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 966 | goto out; |
| 967 | } |
| 968 | global.tune.client_sndbuf = atol(args[1]); |
| 969 | } |
| 970 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 971 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 972 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 973 | if (global.tune.server_sndbuf != 0) { |
| 974 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 975 | err_code |= ERR_ALERT; |
| 976 | goto out; |
| 977 | } |
| 978 | if (*(args[1]) == 0) { |
| 979 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 981 | goto out; |
| 982 | } |
| 983 | global.tune.server_sndbuf = atol(args[1]); |
| 984 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 985 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 986 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 987 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 988 | if (*(args[1]) == 0) { |
| 989 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 991 | goto out; |
| 992 | } |
| 993 | global.tune.pipesize = atol(args[1]); |
| 994 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 995 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 996 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 997 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 998 | if (*(args[1]) == 0) { |
| 999 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1001 | goto out; |
| 1002 | } |
| 1003 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1004 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1005 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1006 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1007 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1008 | if (*(args[1]) == 0) { |
| 1009 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | global.tune.max_http_hdr = atol(args[1]); |
| 1014 | } |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1015 | else if (!strcmp(args[0], "tune.zlib.memlevel")) { |
| 1016 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1017 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1018 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1019 | if (*args[1]) { |
| 1020 | global.tune.zlibmemlevel = atoi(args[1]); |
| 1021 | if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) { |
| 1022 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1023 | file, linenum, args[0]); |
| 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | } else { |
| 1028 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1029 | file, linenum, args[0]); |
| 1030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1031 | goto out; |
| 1032 | } |
| 1033 | #else |
| 1034 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1036 | goto out; |
| 1037 | #endif |
| 1038 | } |
| 1039 | else if (!strcmp(args[0], "tune.zlib.windowsize")) { |
| 1040 | #ifdef USE_ZLIB |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1041 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1042 | goto out; |
William Lallemand | a509e4c | 2012-11-07 16:54:34 +0100 | [diff] [blame] | 1043 | if (*args[1]) { |
| 1044 | global.tune.zlibwindowsize = atoi(args[1]); |
| 1045 | if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) { |
| 1046 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1047 | file, linenum, args[0]); |
| 1048 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1049 | goto out; |
| 1050 | } |
| 1051 | } else { |
| 1052 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n", |
| 1053 | file, linenum, args[0]); |
| 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | #else |
| 1058 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1060 | goto out; |
| 1061 | #endif |
| 1062 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1063 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1064 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1065 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1066 | if (*args[1]) { |
| 1067 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1068 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 1069 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1070 | file, linenum, args[0]); |
| 1071 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | } else { |
| 1075 | Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1076 | file, linenum, args[0]); |
| 1077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1078 | goto out; |
| 1079 | } |
| 1080 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1081 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1082 | if (*args[1]) { |
| 1083 | global.tune.pattern_cache = atoi(args[1]); |
| 1084 | if (global.tune.pattern_cache < 0) { |
| 1085 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1086 | file, linenum, args[0]); |
| 1087 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1088 | goto out; |
| 1089 | } |
| 1090 | } else { |
| 1091 | Alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1092 | file, linenum, args[0]); |
| 1093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1094 | goto out; |
| 1095 | } |
| 1096 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1098 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1099 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1100 | if (global.uid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1101 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1102 | err_code |= ERR_ALERT; |
| 1103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1104 | } |
| 1105 | if (*(args[1]) == 0) { |
| 1106 | 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] | 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1109 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1110 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 1111 | 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]); |
| 1112 | err_code |= ERR_WARN; |
| 1113 | goto out; |
| 1114 | } |
| 1115 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1116 | } |
| 1117 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1118 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1119 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1120 | if (global.gid != 0) { |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1121 | Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1122 | err_code |= ERR_ALERT; |
| 1123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1124 | } |
| 1125 | if (*(args[1]) == 0) { |
| 1126 | 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] | 1127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1128 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1129 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1130 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 1131 | 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]); |
| 1132 | err_code |= ERR_WARN; |
| 1133 | goto out; |
| 1134 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1135 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1136 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1137 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1138 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1139 | global.external_check = 1; |
| 1140 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1141 | /* user/group name handling */ |
| 1142 | else if (!strcmp(args[0], "user")) { |
| 1143 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1144 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1145 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1146 | if (global.uid != 0) { |
| 1147 | Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1148 | err_code |= ERR_ALERT; |
| 1149 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1150 | } |
| 1151 | errno = 0; |
| 1152 | ha_user = getpwnam(args[1]); |
| 1153 | if (ha_user != NULL) { |
| 1154 | global.uid = (int)ha_user->pw_uid; |
| 1155 | } |
| 1156 | else { |
| 1157 | 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] | 1158 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | else if (!strcmp(args[0], "group")) { |
| 1162 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1163 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1164 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1165 | if (global.gid != 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1166 | 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] | 1167 | err_code |= ERR_ALERT; |
| 1168 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1169 | } |
| 1170 | errno = 0; |
| 1171 | ha_group = getgrnam(args[1]); |
| 1172 | if (ha_group != NULL) { |
| 1173 | global.gid = (int)ha_group->gr_gid; |
| 1174 | } |
| 1175 | else { |
| 1176 | 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] | 1177 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1181 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1182 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1183 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1184 | if (*(args[1]) == 0) { |
| 1185 | 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] | 1186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1188 | } |
| 1189 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1190 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
| 1191 | Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1192 | file, linenum, args[0], LONGBITS, global.nbproc); |
| 1193 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1194 | goto out; |
| 1195 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1196 | } |
| 1197 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1198 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1199 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1200 | if (global.maxconn != 0) { |
| 1201 | 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] | 1202 | err_code |= ERR_ALERT; |
| 1203 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1204 | } |
| 1205 | if (*(args[1]) == 0) { |
| 1206 | 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] | 1207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1208 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1209 | } |
| 1210 | global.maxconn = atol(args[1]); |
| 1211 | #ifdef SYSTEM_MAXCONN |
| 1212 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
| 1213 | 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); |
| 1214 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1215 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1216 | } |
| 1217 | #endif /* SYSTEM_MAXCONN */ |
| 1218 | } |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1219 | else if (!strcmp(args[0], "maxsslconn")) { |
| 1220 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1221 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1222 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1223 | if (*(args[1]) == 0) { |
| 1224 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1226 | goto out; |
| 1227 | } |
| 1228 | global.maxsslconn = atol(args[1]); |
| 1229 | #else |
Emeric Brun | 0914df8 | 2012-10-02 18:45:42 +0200 | [diff] [blame] | 1230 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1231 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1232 | goto out; |
Willy Tarreau | 403edff | 2012-09-06 11:58:37 +0200 | [diff] [blame] | 1233 | #endif |
| 1234 | } |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1235 | else if (!strcmp(args[0], "ssl-default-bind-ciphers")) { |
| 1236 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1237 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1238 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1239 | if (*(args[1]) == 0) { |
| 1240 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1242 | goto out; |
| 1243 | } |
| 1244 | free(global.listen_default_ciphers); |
| 1245 | global.listen_default_ciphers = strdup(args[1]); |
| 1246 | #else |
| 1247 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1249 | goto out; |
| 1250 | #endif |
| 1251 | } |
| 1252 | else if (!strcmp(args[0], "ssl-default-server-ciphers")) { |
| 1253 | #ifdef USE_OPENSSL |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1254 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1255 | goto out; |
Willy Tarreau | 610f04b | 2014-02-13 11:36:41 +0100 | [diff] [blame] | 1256 | if (*(args[1]) == 0) { |
| 1257 | Alert("parsing [%s:%d] : '%s' expects a cipher suite as an argument.\n", file, linenum, args[0]); |
| 1258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | free(global.connect_default_ciphers); |
| 1262 | global.connect_default_ciphers = strdup(args[1]); |
| 1263 | #else |
| 1264 | Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]); |
| 1265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1266 | goto out; |
| 1267 | #endif |
| 1268 | } |
Remi Gacogne | 47783ef | 2015-05-29 15:53:22 +0200 | [diff] [blame] | 1269 | #ifdef USE_OPENSSL |
| 1270 | #ifndef OPENSSL_NO_DH |
| 1271 | else if (!strcmp(args[0], "ssl-dh-param-file")) { |
| 1272 | if (*(args[1]) == 0) { |
| 1273 | Alert("parsing [%s:%d] : '%s' expects a file path as an argument.\n", file, linenum, args[0]); |
| 1274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1275 | goto out; |
| 1276 | } |
| 1277 | if (ssl_sock_load_global_dh_param_from_file(args[1])) { |
| 1278 | Alert("parsing [%s:%d] : '%s': unable to load DH parameters from file <%s>.\n", file, linenum, args[0], args[1]); |
| 1279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1280 | goto out; |
| 1281 | } |
| 1282 | } |
| 1283 | #endif |
| 1284 | #endif |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1285 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1286 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1287 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1288 | if (*(args[1]) == 0) { |
| 1289 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1291 | goto out; |
| 1292 | } |
| 1293 | if (strcmp(args[1],"none") == 0) |
| 1294 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1295 | else if (strcmp(args[1],"required") == 0) |
| 1296 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1297 | else { |
| 1298 | Alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 1299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1300 | goto out; |
| 1301 | } |
| 1302 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1303 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1304 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1305 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1306 | if (global.cps_lim != 0) { |
| 1307 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1308 | err_code |= ERR_ALERT; |
| 1309 | goto out; |
| 1310 | } |
| 1311 | if (*(args[1]) == 0) { |
| 1312 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1313 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1314 | goto out; |
| 1315 | } |
| 1316 | global.cps_lim = atol(args[1]); |
| 1317 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1318 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1319 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1320 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1321 | if (global.sps_lim != 0) { |
| 1322 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1323 | err_code |= ERR_ALERT; |
| 1324 | goto out; |
| 1325 | } |
| 1326 | if (*(args[1]) == 0) { |
| 1327 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | global.sps_lim = atol(args[1]); |
| 1332 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1333 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1334 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1335 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1336 | if (global.ssl_lim != 0) { |
| 1337 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1338 | err_code |= ERR_ALERT; |
| 1339 | goto out; |
| 1340 | } |
| 1341 | if (*(args[1]) == 0) { |
| 1342 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1344 | goto out; |
| 1345 | } |
| 1346 | global.ssl_lim = atol(args[1]); |
| 1347 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1348 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1349 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1350 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1351 | if (*(args[1]) == 0) { |
| 1352 | Alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 1353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1354 | goto out; |
| 1355 | } |
| 1356 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1357 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1358 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1359 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1360 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1361 | if (global.maxpipes != 0) { |
| 1362 | 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] | 1363 | err_code |= ERR_ALERT; |
| 1364 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1365 | } |
| 1366 | if (*(args[1]) == 0) { |
| 1367 | 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] | 1368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1369 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1370 | } |
| 1371 | global.maxpipes = atol(args[1]); |
| 1372 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1373 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1374 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1375 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1376 | if (*(args[1]) == 0) { |
| 1377 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 1378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1379 | goto out; |
| 1380 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1381 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1382 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1383 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1384 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1385 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1386 | if (*(args[1]) == 0) { |
| 1387 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1389 | goto out; |
| 1390 | } |
| 1391 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1392 | if (compress_min_idle > 100) { |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1393 | Alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 1394 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1395 | goto out; |
| 1396 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1397 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1398 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1399 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1400 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1401 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1402 | if (global.rlimit_nofile != 0) { |
| 1403 | 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] | 1404 | err_code |= ERR_ALERT; |
| 1405 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1406 | } |
| 1407 | if (*(args[1]) == 0) { |
| 1408 | 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] | 1409 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1410 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1411 | } |
| 1412 | global.rlimit_nofile = atol(args[1]); |
| 1413 | } |
| 1414 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1415 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1416 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1417 | if (global.chroot != NULL) { |
| 1418 | 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] | 1419 | err_code |= ERR_ALERT; |
| 1420 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1421 | } |
| 1422 | if (*(args[1]) == 0) { |
| 1423 | 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] | 1424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1425 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1426 | } |
| 1427 | global.chroot = strdup(args[1]); |
| 1428 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1429 | else if (!strcmp(args[0], "description")) { |
| 1430 | int i, len=0; |
| 1431 | char *d; |
| 1432 | |
| 1433 | if (!*args[1]) { |
| 1434 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1435 | file, linenum, args[0]); |
| 1436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1437 | goto out; |
| 1438 | } |
| 1439 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1440 | for (i = 1; *args[i]; i++) |
| 1441 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1442 | |
| 1443 | if (global.desc) |
| 1444 | free(global.desc); |
| 1445 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1446 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1447 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1448 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1449 | for (i = 2; *args[i]; i++) |
| 1450 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1451 | } |
| 1452 | else if (!strcmp(args[0], "node")) { |
| 1453 | int i; |
| 1454 | char c; |
| 1455 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1456 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1457 | goto out; |
| 1458 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1459 | for (i=0; args[1][i]; i++) { |
| 1460 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1461 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1462 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1463 | break; |
| 1464 | } |
| 1465 | |
| 1466 | if (!i || args[1][i]) { |
| 1467 | Alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1468 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1469 | file, linenum, args[0]); |
| 1470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1471 | goto out; |
| 1472 | } |
| 1473 | |
| 1474 | if (global.node) |
| 1475 | free(global.node); |
| 1476 | |
| 1477 | global.node = strdup(args[1]); |
| 1478 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1479 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1480 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1481 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1482 | if (global.pidfile != NULL) { |
| 1483 | 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] | 1484 | err_code |= ERR_ALERT; |
| 1485 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1486 | } |
| 1487 | if (*(args[1]) == 0) { |
| 1488 | 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] | 1489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1490 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1491 | } |
| 1492 | global.pidfile = strdup(args[1]); |
| 1493 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1494 | else if (!strcmp(args[0], "unix-bind")) { |
| 1495 | int cur_arg = 1; |
| 1496 | while (*(args[cur_arg])) { |
| 1497 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1498 | if (global.unix_bind.prefix != NULL) { |
| 1499 | Alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 1500 | err_code |= ERR_ALERT; |
| 1501 | cur_arg += 2; |
| 1502 | continue; |
| 1503 | } |
| 1504 | |
| 1505 | if (*(args[cur_arg+1]) == 0) { |
| 1506 | Alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 1507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1508 | goto out; |
| 1509 | } |
| 1510 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1511 | cur_arg += 2; |
| 1512 | continue; |
| 1513 | } |
| 1514 | |
| 1515 | if (!strcmp(args[cur_arg], "mode")) { |
| 1516 | |
| 1517 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1518 | cur_arg += 2; |
| 1519 | continue; |
| 1520 | } |
| 1521 | |
| 1522 | if (!strcmp(args[cur_arg], "uid")) { |
| 1523 | |
| 1524 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1525 | cur_arg += 2; |
| 1526 | continue; |
| 1527 | } |
| 1528 | |
| 1529 | if (!strcmp(args[cur_arg], "gid")) { |
| 1530 | |
| 1531 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1532 | cur_arg += 2; |
| 1533 | continue; |
| 1534 | } |
| 1535 | |
| 1536 | if (!strcmp(args[cur_arg], "user")) { |
| 1537 | struct passwd *user; |
| 1538 | |
| 1539 | user = getpwnam(args[cur_arg + 1]); |
| 1540 | if (!user) { |
| 1541 | Alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1542 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1543 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1544 | goto out; |
| 1545 | } |
| 1546 | |
| 1547 | global.unix_bind.ux.uid = user->pw_uid; |
| 1548 | cur_arg += 2; |
| 1549 | continue; |
| 1550 | } |
| 1551 | |
| 1552 | if (!strcmp(args[cur_arg], "group")) { |
| 1553 | struct group *group; |
| 1554 | |
| 1555 | group = getgrnam(args[cur_arg + 1]); |
| 1556 | if (!group) { |
| 1557 | Alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1558 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 1559 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1560 | goto out; |
| 1561 | } |
| 1562 | |
| 1563 | global.unix_bind.ux.gid = group->gr_gid; |
| 1564 | cur_arg += 2; |
| 1565 | continue; |
| 1566 | } |
| 1567 | |
Willy Tarreau | b48f958 | 2011-09-05 01:17:06 +0200 | [diff] [blame] | 1568 | 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] | 1569 | file, linenum, args[0]); |
| 1570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1571 | goto out; |
| 1572 | } |
| 1573 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1574 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { /* no log */ |
| 1575 | /* delete previous herited or defined syslog servers */ |
| 1576 | struct logsrv *back; |
| 1577 | struct logsrv *tmp; |
| 1578 | |
| 1579 | if (*(args[1]) != 0) { |
| 1580 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 1581 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1582 | goto out; |
| 1583 | } |
| 1584 | |
| 1585 | list_for_each_entry_safe(tmp, back, &global.logsrvs, list) { |
| 1586 | LIST_DEL(&tmp->list); |
| 1587 | free(tmp); |
| 1588 | } |
| 1589 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1590 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1591 | struct sockaddr_storage *sk; |
| 1592 | int port1, port2; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1593 | struct logsrv *logsrv; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1594 | int arg = 0; |
| 1595 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1596 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1597 | if (alertif_too_many_args(8, file, linenum, args, &err_code)) /* does not strictly check optional arguments */ |
| 1598 | goto out; |
| 1599 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1600 | if (*(args[1]) == 0 || *(args[2]) == 0) { |
| 1601 | 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] | 1602 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1603 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1604 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1605 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 1606 | logsrv = calloc(1, sizeof(*logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1607 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1608 | /* just after the address, a length may be specified */ |
| 1609 | if (strcmp(args[arg+2], "len") == 0) { |
| 1610 | len = atoi(args[arg+3]); |
| 1611 | if (len < 80 || len > 65535) { |
| 1612 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 1613 | file, linenum, args[arg+3]); |
| 1614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1615 | goto out; |
| 1616 | } |
| 1617 | logsrv->maxlen = len; |
| 1618 | |
| 1619 | /* skip these two args */ |
| 1620 | arg += 2; |
| 1621 | } |
| 1622 | else |
| 1623 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 1624 | |
| 1625 | if (logsrv->maxlen > global.max_syslog_len) { |
| 1626 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 1627 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 1628 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 1629 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 1630 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1631 | } |
| 1632 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1633 | /* after the length, a format may be specified */ |
| 1634 | if (strcmp(args[arg+2], "format") == 0) { |
| 1635 | logsrv->format = get_log_format(args[arg+3]); |
| 1636 | if (logsrv->format < 0) { |
| 1637 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 1638 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 1639 | free(logsrv); |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 1640 | goto out; |
| 1641 | } |
| 1642 | |
| 1643 | /* skip these two args */ |
| 1644 | arg += 2; |
| 1645 | } |
| 1646 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1647 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) { |
| 1648 | free(logsrv); |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1649 | goto out; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 1650 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1651 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1652 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1653 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1654 | 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] | 1655 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1656 | logsrv->facility = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1657 | } |
| 1658 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1659 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1660 | if (*(args[arg+3])) { |
| 1661 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1662 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1663 | 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] | 1664 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1665 | logsrv->level = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1669 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1670 | if (*(args[arg+4])) { |
| 1671 | logsrv->minlvl = get_log_level(args[arg+4]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1672 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 1673 | 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] | 1674 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1675 | logsrv->minlvl = 0; |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 1679 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1680 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1681 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1682 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1683 | free(logsrv); |
| 1684 | goto out; |
| 1685 | } |
| 1686 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1687 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1688 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1689 | if (port1 != port2) { |
| 1690 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 1691 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1692 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1693 | free(logsrv); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 1694 | goto out; |
| 1695 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1696 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1697 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 1698 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1699 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 1700 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1701 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1702 | LIST_ADDQ(&global.logsrvs, &logsrv->list); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1703 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1704 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1705 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1706 | |
| 1707 | if (global.log_send_hostname != NULL) { |
| 1708 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1709 | err_code |= ERR_ALERT; |
| 1710 | goto out; |
| 1711 | } |
| 1712 | |
| 1713 | if (*(args[1])) |
| 1714 | name = args[1]; |
| 1715 | else |
| 1716 | name = hostname; |
| 1717 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1718 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1719 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1720 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1721 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1722 | if (global.server_state_base != NULL) { |
| 1723 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1724 | err_code |= ERR_ALERT; |
| 1725 | goto out; |
| 1726 | } |
| 1727 | |
| 1728 | if (!*(args[1])) { |
| 1729 | Alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 1730 | err_code |= ERR_FATAL; |
| 1731 | goto out; |
| 1732 | } |
| 1733 | |
| 1734 | global.server_state_base = strdup(args[1]); |
| 1735 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1736 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1737 | if (global.server_state_file != NULL) { |
| 1738 | Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 1739 | err_code |= ERR_ALERT; |
| 1740 | goto out; |
| 1741 | } |
| 1742 | |
| 1743 | if (!*(args[1])) { |
| 1744 | Alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 1745 | err_code |= ERR_FATAL; |
| 1746 | goto out; |
| 1747 | } |
| 1748 | |
| 1749 | global.server_state_file = strdup(args[1]); |
| 1750 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1751 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1752 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1753 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1754 | if (*(args[1]) == 0) { |
| 1755 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 1756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1757 | goto out; |
| 1758 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1759 | chunk_destroy(&global.log_tag); |
| 1760 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1761 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1762 | 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] | 1763 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1764 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1765 | if (global.spread_checks != 0) { |
| 1766 | Alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1767 | err_code |= ERR_ALERT; |
| 1768 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1769 | } |
| 1770 | if (*(args[1]) == 0) { |
| 1771 | 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] | 1772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1773 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1774 | } |
| 1775 | global.spread_checks = atol(args[1]); |
| 1776 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 1777 | 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] | 1778 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1779 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1780 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1781 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1782 | const char *err; |
| 1783 | unsigned int val; |
| 1784 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1785 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1786 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1787 | if (*(args[1]) == 0) { |
| 1788 | Alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 1789 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1790 | goto out; |
| 1791 | } |
| 1792 | |
| 1793 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1794 | if (err) { |
| 1795 | Alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
| 1796 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1797 | } |
| 1798 | global.max_spread_checks = val; |
| 1799 | if (global.max_spread_checks < 0) { |
| 1800 | Alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
| 1801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1802 | } |
| 1803 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1804 | else if (strcmp(args[0], "cpu-map") == 0) { /* map a process list to a CPU set */ |
| 1805 | #ifdef USE_CPU_AFFINITY |
| 1806 | int cur_arg, i; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1807 | unsigned long proc = 0; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1808 | unsigned long cpus = 0; |
| 1809 | |
| 1810 | if (strcmp(args[1], "all") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1811 | proc = ~0UL; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1812 | else if (strcmp(args[1], "odd") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1813 | proc = ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1814 | else if (strcmp(args[1], "even") == 0) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1815 | proc = (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1816 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1817 | proc = atol(args[1]); |
| 1818 | if (proc >= 1 && proc <= LONGBITS) |
| 1819 | proc = 1UL << (proc - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | if (!proc || !*args[2]) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1823 | 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", |
| 1824 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1826 | goto out; |
| 1827 | } |
| 1828 | |
| 1829 | cur_arg = 2; |
| 1830 | while (*args[cur_arg]) { |
| 1831 | unsigned int low, high; |
| 1832 | |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 1833 | if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1834 | char *dash = strchr(args[cur_arg], '-'); |
| 1835 | |
| 1836 | low = high = str2uic(args[cur_arg]); |
| 1837 | if (dash) |
| 1838 | high = str2uic(dash + 1); |
| 1839 | |
| 1840 | if (high < low) { |
| 1841 | unsigned int swap = low; |
| 1842 | low = high; |
| 1843 | high = swap; |
| 1844 | } |
| 1845 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1846 | if (high >= LONGBITS) { |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1847 | 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] | 1848 | file, linenum, args[0], LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1850 | goto out; |
| 1851 | } |
| 1852 | |
| 1853 | while (low <= high) |
| 1854 | cpus |= 1UL << low++; |
| 1855 | } |
| 1856 | else { |
| 1857 | Alert("parsing [%s:%d]: %s : '%s' is not a CPU range.\n", |
| 1858 | file, linenum, args[0], args[cur_arg]); |
| 1859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1860 | goto out; |
| 1861 | } |
| 1862 | cur_arg++; |
| 1863 | } |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1864 | for (i = 0; i < LONGBITS; i++) |
| 1865 | if (proc & (1UL << i)) |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1866 | global.cpu_map[i] = cpus; |
| 1867 | #else |
| 1868 | Alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", file, linenum, args[0]); |
| 1869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1870 | goto out; |
| 1871 | #endif |
| 1872 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1873 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1874 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1875 | goto out; |
| 1876 | |
| 1877 | if (*(args[2]) == 0) { |
| 1878 | Alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1880 | goto out; |
| 1881 | } |
| 1882 | |
| 1883 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1884 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1885 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1887 | goto out; |
| 1888 | } |
| 1889 | } |
| 1890 | else if (!strcmp(args[0], "unsetenv")) { |
| 1891 | int arg; |
| 1892 | |
| 1893 | if (*(args[1]) == 0) { |
| 1894 | Alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1896 | goto out; |
| 1897 | } |
| 1898 | |
| 1899 | for (arg = 1; *args[arg]; arg++) { |
| 1900 | if (unsetenv(args[arg]) != 0) { |
| 1901 | Alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1903 | goto out; |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | else if (!strcmp(args[0], "resetenv")) { |
| 1908 | extern char **environ; |
| 1909 | char **env = environ; |
| 1910 | |
| 1911 | /* args contain variable names to keep, one per argument */ |
| 1912 | while (*env) { |
| 1913 | int arg; |
| 1914 | |
| 1915 | /* look for current variable in among all those we want to keep */ |
| 1916 | for (arg = 1; *args[arg]; arg++) { |
| 1917 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1918 | (*env)[strlen(args[arg])] == '=') |
| 1919 | break; |
| 1920 | } |
| 1921 | |
| 1922 | /* delete this variable */ |
| 1923 | if (!*args[arg]) { |
| 1924 | char *delim = strchr(*env, '='); |
| 1925 | |
| 1926 | if (!delim || delim - *env >= trash.size) { |
| 1927 | Alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1929 | goto out; |
| 1930 | } |
| 1931 | |
| 1932 | memcpy(trash.str, *env, delim - *env); |
| 1933 | trash.str[delim - *env] = 0; |
| 1934 | |
| 1935 | if (unsetenv(trash.str) != 0) { |
| 1936 | Alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1938 | goto out; |
| 1939 | } |
| 1940 | } |
| 1941 | else |
| 1942 | env++; |
| 1943 | } |
| 1944 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1945 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1946 | struct cfg_kw_list *kwl; |
| 1947 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1948 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1949 | |
| 1950 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1951 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1952 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1953 | continue; |
| 1954 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1955 | 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] | 1956 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1957 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1958 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1959 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1960 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1961 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1962 | err_code |= ERR_WARN; |
| 1963 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1964 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1965 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | } |
| 1969 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1970 | 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] | 1971 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1972 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1973 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1974 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1975 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1976 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1977 | } |
| 1978 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1979 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1980 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1981 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1982 | defproxy.mode = PR_MODE_TCP; |
| 1983 | defproxy.state = PR_STNEW; |
| 1984 | defproxy.maxconn = cfg_maxpconn; |
| 1985 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1986 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1987 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1988 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1989 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1990 | defproxy.defsrv.check.fastinter = 0; |
| 1991 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1992 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1993 | defproxy.defsrv.agent.fastinter = 0; |
| 1994 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1995 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1996 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1997 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1998 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1999 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 2000 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2001 | defproxy.defsrv.maxqueue = 0; |
| 2002 | defproxy.defsrv.minconn = 0; |
| 2003 | defproxy.defsrv.maxconn = 0; |
| 2004 | defproxy.defsrv.slowstart = 0; |
| 2005 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 2006 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 2007 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 2008 | |
| 2009 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2010 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2011 | } |
| 2012 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2013 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2014 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 2015 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 2016 | * ERR_FATAL in case of error. |
| 2017 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2018 | static int create_cond_regex_rule(const char *file, int line, |
| 2019 | struct proxy *px, int dir, int action, int flags, |
| 2020 | const char *cmd, const char *reg, const char *repl, |
| 2021 | const char **cond_start) |
| 2022 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2023 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2024 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2025 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2026 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2027 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2028 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2029 | int cs; |
| 2030 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2031 | |
| 2032 | if (px == &defproxy) { |
| 2033 | 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] | 2034 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2035 | goto err; |
| 2036 | } |
| 2037 | |
| 2038 | if (*reg == 0) { |
| 2039 | 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] | 2040 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2041 | goto err; |
| 2042 | } |
| 2043 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2044 | 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] | 2045 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2046 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2047 | if (cond_start && |
| 2048 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 2049 | if ((cond = build_acl_cond(file, line, px, cond_start, &errmsg)) == NULL) { |
| 2050 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 2051 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2052 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2053 | goto err; |
| 2054 | } |
| 2055 | } |
| 2056 | else if (cond_start && **cond_start) { |
| 2057 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 2058 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2059 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2060 | goto err; |
| 2061 | } |
| 2062 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2063 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 2064 | (dir == SMP_OPT_DIR_REQ) ? |
| 2065 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 2066 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 2067 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 2068 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2069 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2070 | if (!preg) { |
| 2071 | 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] | 2072 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2073 | goto err; |
| 2074 | } |
| 2075 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2076 | cs = !(flags & REG_ICASE); |
| 2077 | cap = !(flags & REG_NOSUB); |
| 2078 | error = NULL; |
| 2079 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
| 2080 | Alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
| 2081 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2082 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2083 | goto err; |
| 2084 | } |
| 2085 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2086 | 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] | 2087 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2088 | if (repl && err) { |
| 2089 | Alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 2090 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2091 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 2092 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2093 | } |
| 2094 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2095 | 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] | 2096 | ret_code |= ERR_WARN; |
| 2097 | |
| 2098 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2099 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2100 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2101 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2102 | err: |
| 2103 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 2104 | free(errmsg); |
| 2105 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2108 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2109 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2110 | * Returns the error code, 0 if OK, or any combination of : |
| 2111 | * - ERR_ABORT: must abort ASAP |
| 2112 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2113 | * - ERR_WARN: a warning has been emitted |
| 2114 | * - ERR_ALERT: an alert has been emitted |
| 2115 | * Only the two first ones can stop processing, the two others are just |
| 2116 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2117 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2118 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 2119 | { |
| 2120 | static struct peers *curpeers = NULL; |
| 2121 | struct peer *newpeer = NULL; |
| 2122 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2123 | struct bind_conf *bind_conf; |
| 2124 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2125 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2126 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2127 | |
| 2128 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2129 | if (!*args[1]) { |
| 2130 | Alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2131 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2132 | goto out; |
| 2133 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2134 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2135 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2136 | goto out; |
| 2137 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2138 | err = invalid_char(args[1]); |
| 2139 | if (err) { |
| 2140 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2141 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 2142 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2143 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) { |
| 2147 | /* |
| 2148 | * If there are two proxies with the same name only following |
| 2149 | * combinations are allowed: |
| 2150 | */ |
| 2151 | if (strcmp(curpeers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2152 | 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] | 2153 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2154 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2158 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2159 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2160 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2161 | goto out; |
| 2162 | } |
| 2163 | |
| 2164 | curpeers->next = peers; |
| 2165 | peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2166 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2167 | curpeers->conf.line = linenum; |
| 2168 | curpeers->last_change = now.tv_sec; |
| 2169 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2170 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2171 | } |
| 2172 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2173 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2174 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2175 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2176 | |
| 2177 | if (!*args[2]) { |
| 2178 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2179 | file, linenum, args[0]); |
| 2180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2181 | goto out; |
| 2182 | } |
| 2183 | |
| 2184 | err = invalid_char(args[1]); |
| 2185 | if (err) { |
| 2186 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2187 | file, linenum, *err, args[1]); |
| 2188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2189 | goto out; |
| 2190 | } |
| 2191 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2192 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2193 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2194 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2195 | goto out; |
| 2196 | } |
| 2197 | |
| 2198 | /* the peers are linked backwards first */ |
| 2199 | curpeers->count++; |
| 2200 | newpeer->next = curpeers->remote; |
| 2201 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2202 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2203 | newpeer->conf.line = linenum; |
| 2204 | |
| 2205 | newpeer->last_change = now.tv_sec; |
| 2206 | newpeer->id = strdup(args[1]); |
| 2207 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2208 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2209 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2210 | 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] | 2211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2212 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2213 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2214 | |
| 2215 | proto = protocol_by_family(sk->ss_family); |
| 2216 | if (!proto || !proto->connect) { |
| 2217 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2218 | file, linenum, args[0], args[1]); |
| 2219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2220 | goto out; |
| 2221 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2222 | |
| 2223 | if (port1 != port2) { |
| 2224 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2225 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2226 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2227 | goto out; |
| 2228 | } |
| 2229 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2230 | if (!port1) { |
| 2231 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2232 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2234 | goto out; |
| 2235 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2236 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2237 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2238 | newpeer->proto = proto; |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 2239 | newpeer->xprt = &raw_sock; |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2240 | newpeer->sock_init_arg = NULL; |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2241 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2242 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2243 | /* Current is local peer, it define a frontend */ |
| 2244 | newpeer->local = 1; |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 2245 | peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2246 | |
| 2247 | if (!curpeers->peers_fe) { |
| 2248 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
| 2249 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2250 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2251 | goto out; |
| 2252 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2253 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2254 | init_new_proxy(curpeers->peers_fe); |
| 2255 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2256 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2257 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2258 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2259 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2260 | |
| 2261 | bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); |
| 2262 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2263 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2264 | if (errmsg && *errmsg) { |
| 2265 | indent_msg(&errmsg, 2); |
| 2266 | 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] | 2267 | } |
| 2268 | else |
| 2269 | Alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2270 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2271 | err_code |= ERR_FATAL; |
| 2272 | goto out; |
| 2273 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2274 | |
| 2275 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2276 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2277 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2278 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2279 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2280 | l->handler = process_stream; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2281 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2282 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2283 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2284 | global.maxsock += l->maxconn; |
| 2285 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2286 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2287 | else { |
| 2288 | Alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2289 | file, linenum, args[0], args[1], |
| 2290 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
| 2291 | err_code |= ERR_FATAL; |
| 2292 | goto out; |
| 2293 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2294 | } |
| 2295 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2296 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2297 | curpeers->state = PR_STSTOPPED; |
| 2298 | } |
| 2299 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2300 | curpeers->state = PR_STNEW; |
| 2301 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2302 | else if (*args[0] != 0) { |
| 2303 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2305 | goto out; |
| 2306 | } |
| 2307 | |
| 2308 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2309 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2310 | return err_code; |
| 2311 | } |
| 2312 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2313 | /* |
| 2314 | * Parse a <resolvers> section. |
| 2315 | * Returns the error code, 0 if OK, or any combination of : |
| 2316 | * - ERR_ABORT: must abort ASAP |
| 2317 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2318 | * - ERR_WARN: a warning has been emitted |
| 2319 | * - ERR_ALERT: an alert has been emitted |
| 2320 | * Only the two first ones can stop processing, the two others are just |
| 2321 | * indicators. |
| 2322 | */ |
| 2323 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2324 | { |
| 2325 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2326 | struct dns_nameserver *newnameserver = NULL; |
| 2327 | const char *err; |
| 2328 | int err_code = 0; |
| 2329 | char *errmsg = NULL; |
| 2330 | |
| 2331 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2332 | if (!*args[1]) { |
| 2333 | Alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
| 2334 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2335 | goto out; |
| 2336 | } |
| 2337 | |
| 2338 | err = invalid_char(args[1]); |
| 2339 | if (err) { |
| 2340 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2341 | file, linenum, *err, args[0], args[1]); |
| 2342 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2343 | goto out; |
| 2344 | } |
| 2345 | |
| 2346 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2347 | /* Error if two resolvers owns the same name */ |
| 2348 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
| 2349 | Alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2350 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2351 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2352 | } |
| 2353 | } |
| 2354 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2355 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2356 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2357 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2358 | goto out; |
| 2359 | } |
| 2360 | |
| 2361 | /* default values */ |
| 2362 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2363 | curr_resolvers->conf.file = strdup(file); |
| 2364 | curr_resolvers->conf.line = linenum; |
| 2365 | curr_resolvers->id = strdup(args[1]); |
| 2366 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2367 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2368 | curr_resolvers->hold.nx = 30000; |
| 2369 | curr_resolvers->hold.other = 30000; |
| 2370 | curr_resolvers->hold.refused = 30000; |
| 2371 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2372 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2373 | curr_resolvers->hold.valid = 10000; |
| 2374 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2375 | curr_resolvers->resolve_retries = 3; |
| 2376 | LIST_INIT(&curr_resolvers->nameserver_list); |
| 2377 | LIST_INIT(&curr_resolvers->curr_resolution); |
| 2378 | } |
| 2379 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2380 | struct sockaddr_storage *sk; |
| 2381 | int port1, port2; |
| 2382 | struct protocol *proto; |
| 2383 | |
| 2384 | if (!*args[2]) { |
| 2385 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2386 | file, linenum, args[0]); |
| 2387 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2388 | goto out; |
| 2389 | } |
| 2390 | |
| 2391 | err = invalid_char(args[1]); |
| 2392 | if (err) { |
| 2393 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2394 | file, linenum, *err, args[1]); |
| 2395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2396 | goto out; |
| 2397 | } |
| 2398 | |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2399 | list_for_each_entry(newnameserver, &curr_resolvers->nameserver_list, list) { |
| 2400 | /* Error if two resolvers owns the same name */ |
| 2401 | if (strcmp(newnameserver->id, args[1]) == 0) { |
| 2402 | Alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
| 2403 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
| 2404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2405 | } |
| 2406 | } |
| 2407 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2408 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2409 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2410 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2411 | goto out; |
| 2412 | } |
| 2413 | |
| 2414 | /* the nameservers are linked backward first */ |
| 2415 | LIST_ADDQ(&curr_resolvers->nameserver_list, &newnameserver->list); |
| 2416 | curr_resolvers->count_nameservers++; |
| 2417 | newnameserver->resolvers = curr_resolvers; |
| 2418 | newnameserver->conf.file = strdup(file); |
| 2419 | newnameserver->conf.line = linenum; |
| 2420 | newnameserver->id = strdup(args[1]); |
| 2421 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2422 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2423 | if (!sk) { |
| 2424 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2426 | goto out; |
| 2427 | } |
| 2428 | |
| 2429 | proto = protocol_by_family(sk->ss_family); |
| 2430 | if (!proto || !proto->connect) { |
| 2431 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2432 | file, linenum, args[0], args[1]); |
| 2433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2434 | goto out; |
| 2435 | } |
| 2436 | |
| 2437 | if (port1 != port2) { |
| 2438 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2439 | file, linenum, args[0], args[1], args[2]); |
| 2440 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2441 | goto out; |
| 2442 | } |
| 2443 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2444 | if (!port1 && !port2) { |
| 2445 | Alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2446 | file, linenum, args[0], args[1]); |
| 2447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2448 | goto out; |
| 2449 | } |
| 2450 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2451 | newnameserver->addr = *sk; |
| 2452 | } |
| 2453 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2454 | const char *res; |
| 2455 | unsigned int time; |
| 2456 | |
| 2457 | if (!*args[2]) { |
| 2458 | Alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2459 | file, linenum, args[0]); |
| 2460 | Alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
| 2461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2462 | goto out; |
| 2463 | } |
| 2464 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2465 | if (res) { |
| 2466 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2467 | file, linenum, *res, args[0]); |
| 2468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2469 | goto out; |
| 2470 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2471 | if (strcmp(args[1], "nx") == 0) |
| 2472 | curr_resolvers->hold.nx = time; |
| 2473 | else if (strcmp(args[1], "other") == 0) |
| 2474 | curr_resolvers->hold.other = time; |
| 2475 | else if (strcmp(args[1], "refused") == 0) |
| 2476 | curr_resolvers->hold.refused = time; |
| 2477 | else if (strcmp(args[1], "timeout") == 0) |
| 2478 | curr_resolvers->hold.timeout = time; |
| 2479 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2480 | curr_resolvers->hold.valid = time; |
| 2481 | else { |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2482 | Alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', or 'other'.\n", |
| 2483 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2485 | goto out; |
| 2486 | } |
| 2487 | |
| 2488 | } |
| 2489 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2490 | if (!*args[1]) { |
| 2491 | Alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2492 | file, linenum, args[0]); |
| 2493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2494 | goto out; |
| 2495 | } |
| 2496 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2497 | } |
| 2498 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2499 | if (!*args[1]) { |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2500 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments.\n", |
| 2501 | file, linenum, args[0]); |
| 2502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2503 | goto out; |
| 2504 | } |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2505 | else if (strcmp(args[1], "retry") == 0) { |
| 2506 | const char *res; |
| 2507 | unsigned int timeout_retry; |
| 2508 | |
| 2509 | if (!*args[2]) { |
| 2510 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2511 | file, linenum, args[0], args[1]); |
| 2512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2513 | goto out; |
| 2514 | } |
| 2515 | res = parse_time_err(args[2], &timeout_retry, TIME_UNIT_MS); |
| 2516 | if (res) { |
| 2517 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2518 | file, linenum, *res, args[0], args[1]); |
| 2519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2520 | goto out; |
| 2521 | } |
| 2522 | curr_resolvers->timeout.retry = timeout_retry; |
| 2523 | } |
| 2524 | else { |
| 2525 | Alert("parsing [%s:%d] : '%s' expects 'retry' and <time> as arguments got '%s'.\n", |
| 2526 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2528 | goto out; |
| 2529 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2530 | } /* neither "nameserver" nor "resolvers" */ |
| 2531 | else if (*args[0] != 0) { |
| 2532 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2534 | goto out; |
| 2535 | } |
| 2536 | |
| 2537 | out: |
| 2538 | free(errmsg); |
| 2539 | return err_code; |
| 2540 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2541 | |
| 2542 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2543 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2544 | * Returns the error code, 0 if OK, or any combination of : |
| 2545 | * - ERR_ABORT: must abort ASAP |
| 2546 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2547 | * - ERR_WARN: a warning has been emitted |
| 2548 | * - ERR_ALERT: an alert has been emitted |
| 2549 | * Only the two first ones can stop processing, the two others are just |
| 2550 | * indicators. |
| 2551 | */ |
| 2552 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2553 | { |
| 2554 | static struct mailers *curmailers = NULL; |
| 2555 | struct mailer *newmailer = NULL; |
| 2556 | const char *err; |
| 2557 | int err_code = 0; |
| 2558 | char *errmsg = NULL; |
| 2559 | |
| 2560 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2561 | if (!*args[1]) { |
| 2562 | Alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
| 2563 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2564 | goto out; |
| 2565 | } |
| 2566 | |
| 2567 | err = invalid_char(args[1]); |
| 2568 | if (err) { |
| 2569 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2570 | file, linenum, *err, args[0], args[1]); |
| 2571 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2572 | goto out; |
| 2573 | } |
| 2574 | |
| 2575 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2576 | /* |
| 2577 | * If there are two proxies with the same name only following |
| 2578 | * combinations are allowed: |
| 2579 | */ |
| 2580 | if (strcmp(curmailers->id, args[1]) == 0) { |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2581 | 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] | 2582 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2587 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2588 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2589 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2590 | goto out; |
| 2591 | } |
| 2592 | |
| 2593 | curmailers->next = mailers; |
| 2594 | mailers = curmailers; |
| 2595 | curmailers->conf.file = strdup(file); |
| 2596 | curmailers->conf.line = linenum; |
| 2597 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2598 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2599 | * But need enough time so that timeouts don't occur |
| 2600 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2601 | } |
| 2602 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2603 | struct sockaddr_storage *sk; |
| 2604 | int port1, port2; |
| 2605 | struct protocol *proto; |
| 2606 | |
| 2607 | if (!*args[2]) { |
| 2608 | Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2609 | file, linenum, args[0]); |
| 2610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2611 | goto out; |
| 2612 | } |
| 2613 | |
| 2614 | err = invalid_char(args[1]); |
| 2615 | if (err) { |
| 2616 | Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2617 | file, linenum, *err, args[1]); |
| 2618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2619 | goto out; |
| 2620 | } |
| 2621 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2622 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2623 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 2624 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2625 | goto out; |
| 2626 | } |
| 2627 | |
| 2628 | /* the mailers are linked backwards first */ |
| 2629 | curmailers->count++; |
| 2630 | newmailer->next = curmailers->mailer_list; |
| 2631 | curmailers->mailer_list = newmailer; |
| 2632 | newmailer->mailers = curmailers; |
| 2633 | newmailer->conf.file = strdup(file); |
| 2634 | newmailer->conf.line = linenum; |
| 2635 | |
| 2636 | newmailer->id = strdup(args[1]); |
| 2637 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 2638 | sk = str2sa_range(args[2], &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2639 | if (!sk) { |
| 2640 | Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
| 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
| 2643 | } |
| 2644 | |
| 2645 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2646 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
| 2647 | 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] | 2648 | file, linenum, args[0], args[1]); |
| 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
| 2653 | if (port1 != port2) { |
| 2654 | Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2655 | file, linenum, args[0], args[1], args[2]); |
| 2656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2657 | goto out; |
| 2658 | } |
| 2659 | |
| 2660 | if (!port1) { |
| 2661 | Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2662 | file, linenum, args[0], args[1], args[2]); |
| 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | |
| 2667 | newmailer->addr = *sk; |
| 2668 | newmailer->proto = proto; |
| 2669 | newmailer->xprt = &raw_sock; |
| 2670 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2671 | } |
| 2672 | else if (strcmp(args[0], "timeout") == 0) { |
| 2673 | if (!*args[1]) { |
| 2674 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2675 | file, linenum, args[0]); |
| 2676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | else if (strcmp(args[1], "mail") == 0) { |
| 2680 | const char *res; |
| 2681 | unsigned int timeout_mail; |
| 2682 | if (!*args[2]) { |
| 2683 | Alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2684 | file, linenum, args[0], args[1]); |
| 2685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2686 | goto out; |
| 2687 | } |
| 2688 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2689 | if (res) { |
| 2690 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2691 | file, linenum, *res, args[0]); |
| 2692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2693 | goto out; |
| 2694 | } |
| 2695 | if (timeout_mail <= 0) { |
| 2696 | Alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
| 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | curmailers->timeout.mail = timeout_mail; |
| 2701 | } else { |
| 2702 | Alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
| 2703 | file, linenum, args[0], args[1]); |
| 2704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2705 | goto out; |
| 2706 | } |
| 2707 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2708 | else if (*args[0] != 0) { |
| 2709 | Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
| 2712 | } |
| 2713 | |
| 2714 | out: |
| 2715 | free(errmsg); |
| 2716 | return err_code; |
| 2717 | } |
| 2718 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2719 | static void free_email_alert(struct proxy *p) |
| 2720 | { |
| 2721 | free(p->email_alert.mailers.name); |
| 2722 | p->email_alert.mailers.name = NULL; |
| 2723 | free(p->email_alert.from); |
| 2724 | p->email_alert.from = NULL; |
| 2725 | free(p->email_alert.to); |
| 2726 | p->email_alert.to = NULL; |
| 2727 | free(p->email_alert.myhostname); |
| 2728 | p->email_alert.myhostname = NULL; |
| 2729 | } |
| 2730 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2731 | 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] | 2732 | { |
| 2733 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2734 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2735 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2736 | int rc; |
| 2737 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2738 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2739 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2740 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2741 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2742 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2743 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2744 | if (!strcmp(args[0], "listen")) |
| 2745 | rc = PR_CAP_LISTEN; |
| 2746 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2747 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2748 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2749 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2750 | else |
| 2751 | rc = PR_CAP_NONE; |
| 2752 | |
| 2753 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2754 | if (!*args[1]) { |
| 2755 | Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
Ian Miell | 71c432e | 2015-08-18 19:32:08 +0100 | [diff] [blame] | 2756 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2757 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2760 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2761 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2762 | err = invalid_char(args[1]); |
| 2763 | if (err) { |
| 2764 | Alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2765 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2769 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2770 | if (curproxy) { |
| 2771 | Alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2772 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2773 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2774 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2775 | } |
| 2776 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2777 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2778 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2779 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2781 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2782 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2783 | init_new_proxy(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2784 | curproxy->next = proxy; |
| 2785 | proxy = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2786 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2787 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2788 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2789 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2790 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2791 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2792 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2794 | if (curproxy->cap & PR_CAP_FE) |
| 2795 | Alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 2796 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2800 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2801 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2802 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2803 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2804 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2805 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2806 | curproxy->no_options = defproxy.no_options; |
| 2807 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2808 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2809 | curproxy->except_net = defproxy.except_net; |
| 2810 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2811 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2812 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2813 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2814 | if (defproxy.fwdfor_hdr_len) { |
| 2815 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2816 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2817 | } |
| 2818 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2819 | if (defproxy.orgto_hdr_len) { |
| 2820 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2821 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2822 | } |
| 2823 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2824 | if (defproxy.server_id_hdr_len) { |
| 2825 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2826 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2827 | } |
| 2828 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2829 | if (curproxy->cap & PR_CAP_FE) { |
| 2830 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2831 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2832 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2833 | |
| 2834 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2835 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2836 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2837 | |
| 2838 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2839 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2840 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2841 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2842 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2843 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2844 | curproxy->fullconn = defproxy.fullconn; |
| 2845 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2846 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2847 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2848 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2849 | if (defproxy.check_req) { |
| 2850 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2851 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2852 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2853 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2854 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2855 | if (defproxy.expect_str) { |
| 2856 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2857 | if (defproxy.expect_regex) { |
| 2858 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2859 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2860 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2864 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2865 | if (defproxy.cookie_name) |
| 2866 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2867 | curproxy->cookie_len = defproxy.cookie_len; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2868 | if (defproxy.cookie_domain) |
| 2869 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2870 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2871 | if (defproxy.cookie_maxidle) |
| 2872 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2873 | |
| 2874 | if (defproxy.cookie_maxlife) |
| 2875 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2876 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2877 | if (defproxy.rdp_cookie_name) |
| 2878 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2879 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2880 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2881 | if (defproxy.url_param_name) |
| 2882 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2883 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2884 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2885 | if (defproxy.hh_name) |
| 2886 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2887 | curproxy->hh_len = defproxy.hh_len; |
| 2888 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2889 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2890 | if (defproxy.conn_src.iface_name) |
| 2891 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2892 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2893 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2894 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2895 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2896 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2897 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2898 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2899 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2900 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2901 | if (defproxy.capture_name) |
| 2902 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2903 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2904 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2905 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2906 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2907 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2908 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2909 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2910 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2911 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2912 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2913 | curproxy->mon_net = defproxy.mon_net; |
| 2914 | curproxy->mon_mask = defproxy.mon_mask; |
| 2915 | if (defproxy.monitor_uri) |
| 2916 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2917 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2918 | if (defproxy.defbe.name) |
| 2919 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2920 | |
| 2921 | /* 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] | 2922 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2923 | if (curproxy->conf.logformat_string && |
| 2924 | curproxy->conf.logformat_string != default_http_log_format && |
| 2925 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2926 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2927 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2928 | |
| 2929 | if (defproxy.conf.lfs_file) { |
| 2930 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2931 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2932 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2933 | |
| 2934 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2935 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2936 | if (curproxy->conf.logformat_sd_string && |
| 2937 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2938 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2939 | |
| 2940 | if (defproxy.conf.lfsd_file) { |
| 2941 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2942 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2943 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2947 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2948 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2949 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2950 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2951 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2952 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2953 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2954 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2955 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2956 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2957 | } |
| 2958 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2959 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2960 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2961 | |
| 2962 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2963 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2964 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2965 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2966 | LIST_INIT(&node->list); |
| 2967 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2968 | } |
| 2969 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2970 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2971 | if (curproxy->conf.uniqueid_format_string) |
| 2972 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2973 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2974 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2975 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2976 | if (defproxy.conf.uif_file) { |
| 2977 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2978 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2979 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2980 | |
| 2981 | /* copy default header unique id */ |
| 2982 | if (defproxy.header_unique_id) |
| 2983 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2984 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2985 | /* default compression options */ |
| 2986 | if (defproxy.comp != NULL) { |
| 2987 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2988 | curproxy->comp->algos = defproxy.comp->algos; |
| 2989 | curproxy->comp->types = defproxy.comp->types; |
| 2990 | } |
| 2991 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2992 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2993 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2994 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2995 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 2996 | if (defproxy.check_path) |
| 2997 | curproxy->check_path = strdup(defproxy.check_path); |
| 2998 | if (defproxy.check_command) |
| 2999 | curproxy->check_command = strdup(defproxy.check_command); |
| 3000 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3001 | if (defproxy.email_alert.mailers.name) |
| 3002 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3003 | if (defproxy.email_alert.from) |
| 3004 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3005 | if (defproxy.email_alert.to) |
| 3006 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3007 | if (defproxy.email_alert.myhostname) |
| 3008 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3009 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3010 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3011 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3012 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3013 | } |
| 3014 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3015 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3016 | /* FIXME-20070101: we should do this too at the end of the |
| 3017 | * config parsing to free all default values. |
| 3018 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3019 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3020 | err_code |= ERR_ABORT; |
| 3021 | goto out; |
| 3022 | } |
| 3023 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3024 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3025 | free(defproxy.check_command); |
| 3026 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3027 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3028 | free(defproxy.rdp_cookie_name); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3029 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3030 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3031 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3032 | free(defproxy.capture_name); |
| 3033 | free(defproxy.monitor_uri); |
| 3034 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3035 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3036 | free(defproxy.fwdfor_hdr_name); |
| 3037 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3038 | free(defproxy.orgto_hdr_name); |
| 3039 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3040 | free(defproxy.server_id_hdr_name); |
| 3041 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3042 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3043 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3044 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3045 | free(defproxy.expect_regex); |
| 3046 | defproxy.expect_regex = NULL; |
| 3047 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3048 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3049 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3050 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3051 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3052 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3053 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3054 | free(defproxy.conf.uniqueid_format_string); |
| 3055 | free(defproxy.conf.lfs_file); |
| 3056 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3057 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3058 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3059 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3060 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3061 | free(defproxy.conf.logformat_sd_string); |
| 3062 | free(defproxy.conf.lfsd_file); |
| 3063 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3064 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3065 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3066 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3067 | /* we cannot free uri_auth because it might already be used */ |
| 3068 | init_default_instance(); |
| 3069 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3070 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3071 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3072 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3073 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3074 | } |
| 3075 | else if (curproxy == NULL) { |
| 3076 | Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3077 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3078 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3079 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3080 | |
| 3081 | /* update the current file and line being parsed */ |
| 3082 | curproxy->conf.args.file = curproxy->conf.file; |
| 3083 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3084 | |
| 3085 | /* Now let's parse the proxy-specific keywords */ |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3086 | if (!strcmp(args[0], "server") || !strcmp(args[0], "default-server")) { |
| 3087 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3088 | if (err_code & ERR_FATAL) |
| 3089 | goto out; |
| 3090 | } |
| 3091 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3092 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3093 | int cur_arg; |
| 3094 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3095 | if (curproxy == &defproxy) { |
| 3096 | 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] | 3097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3098 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3099 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3100 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3101 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3102 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3103 | if (!*(args[1])) { |
Willy Tarreau | d55c3fe | 2010-11-09 09:50:37 +0100 | [diff] [blame] | 3104 | 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] | 3105 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3106 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3108 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3109 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 3110 | bind_conf = bind_conf_alloc(&curproxy->conf.bind, file, linenum, args[1]); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 3111 | |
| 3112 | /* use default settings for unix sockets */ |
| 3113 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3114 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3115 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3116 | |
| 3117 | /* NOTE: the following line might create several listeners if there |
| 3118 | * are comma-separated IPs or port ranges. So all further processing |
| 3119 | * will have to be applied to all listeners created after last_listen. |
| 3120 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3121 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3122 | if (errmsg && *errmsg) { |
| 3123 | indent_msg(&errmsg, 2); |
| 3124 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 3125 | } |
| 3126 | else |
| 3127 | Alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3128 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3130 | goto out; |
| 3131 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3132 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3133 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3134 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3135 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3136 | } |
| 3137 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3138 | cur_arg = 2; |
| 3139 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3140 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3141 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3142 | char *err; |
| 3143 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3144 | kw = bind_find_kw(args[cur_arg]); |
| 3145 | if (kw) { |
| 3146 | char *err = NULL; |
| 3147 | int code; |
| 3148 | |
| 3149 | if (!kw->parse) { |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3150 | Alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3151 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3152 | cur_arg += 1 + kw->skip ; |
| 3153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3154 | goto out; |
| 3155 | } |
| 3156 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3157 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3158 | err_code |= code; |
| 3159 | |
| 3160 | if (code) { |
| 3161 | if (err && *err) { |
| 3162 | indent_msg(&err, 2); |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3163 | 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] | 3164 | } |
| 3165 | else |
Willy Tarreau | dda322d | 2012-09-18 16:34:09 +0200 | [diff] [blame] | 3166 | Alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3167 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3168 | if (code & ERR_FATAL) { |
| 3169 | free(err); |
| 3170 | cur_arg += 1 + kw->skip; |
| 3171 | goto out; |
| 3172 | } |
| 3173 | } |
| 3174 | free(err); |
| 3175 | cur_arg += 1 + kw->skip; |
| 3176 | continue; |
| 3177 | } |
| 3178 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3179 | err = NULL; |
| 3180 | if (!bind_dumped) { |
| 3181 | bind_dump_kws(&err); |
| 3182 | indent_msg(&err, 4); |
| 3183 | bind_dumped = 1; |
| 3184 | } |
| 3185 | |
| 3186 | Alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3187 | file, linenum, args[0], args[1], args[cur_arg], |
| 3188 | err ? " Registered keywords :" : "", err ? err : ""); |
| 3189 | free(err); |
| 3190 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3192 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3193 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3194 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3195 | } |
| 3196 | 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] | 3197 | 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] | 3198 | Alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3199 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3202 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3203 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3204 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3205 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3206 | /* flush useless bits */ |
| 3207 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3208 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3209 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3210 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3211 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3212 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3213 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3214 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3215 | goto out; |
| 3216 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3217 | if (!*args[1]) { |
| 3218 | Alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3219 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3221 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3222 | } |
| 3223 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3224 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3225 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3226 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3227 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3228 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3229 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3230 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3231 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3232 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3233 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3234 | goto out; |
| 3235 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3236 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3237 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3238 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3239 | else { |
| 3240 | 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] | 3241 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3242 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3243 | } |
| 3244 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3245 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3246 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3247 | |
| 3248 | if (curproxy == &defproxy) { |
| 3249 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3250 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3252 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3253 | } |
| 3254 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3255 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3256 | goto out; |
| 3257 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3258 | if (!*args[1]) { |
| 3259 | Alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3260 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3262 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3266 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3267 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3268 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3269 | if (curproxy->uuid <= 0) { |
| 3270 | Alert("parsing [%s:%d]: custom id has to be > 0.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3271 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3272 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3273 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3274 | } |
| 3275 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3276 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3277 | if (node) { |
| 3278 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 3279 | Alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3280 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3281 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 3282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3283 | goto out; |
| 3284 | } |
| 3285 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3286 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3287 | else if (!strcmp(args[0], "description")) { |
| 3288 | int i, len=0; |
| 3289 | char *d; |
| 3290 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3291 | if (curproxy == &defproxy) { |
| 3292 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 3293 | file, linenum, args[0]); |
| 3294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3295 | goto out; |
| 3296 | } |
| 3297 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3298 | if (!*args[1]) { |
| 3299 | Alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3300 | file, linenum, args[0]); |
| 3301 | return -1; |
| 3302 | } |
| 3303 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3304 | for (i = 1; *args[i]; i++) |
| 3305 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3306 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3307 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3308 | curproxy->desc = d; |
| 3309 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3310 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3311 | for (i = 2; *args[i]; i++) |
| 3312 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3313 | |
| 3314 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3315 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3316 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3317 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3318 | curproxy->state = PR_STSTOPPED; |
| 3319 | } |
| 3320 | 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] | 3321 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3322 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3323 | curproxy->state = PR_STNEW; |
| 3324 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3325 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3326 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3327 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3328 | |
| 3329 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3330 | unsigned int low, high; |
| 3331 | |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3332 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3333 | set = 0; |
| 3334 | break; |
| 3335 | } |
| 3336 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3337 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3338 | } |
| 3339 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3340 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3341 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 3342 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3343 | char *dash = strchr(args[cur_arg], '-'); |
| 3344 | |
| 3345 | low = high = str2uic(args[cur_arg]); |
| 3346 | if (dash) |
| 3347 | high = str2uic(dash + 1); |
| 3348 | |
| 3349 | if (high < low) { |
| 3350 | unsigned int swap = low; |
| 3351 | low = high; |
| 3352 | high = swap; |
| 3353 | } |
| 3354 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3355 | if (low < 1 || high > LONGBITS) { |
| 3356 | Alert("parsing [%s:%d]: %s supports process numbers from 1 to %d.\n", |
| 3357 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3358 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3359 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3360 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3361 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3362 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3363 | } |
| 3364 | else { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3365 | Alert("parsing [%s:%d]: %s expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 3366 | file, linenum, args[0], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3368 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3369 | } |
| 3370 | cur_arg++; |
| 3371 | } |
| 3372 | curproxy->bind_proc = set; |
| 3373 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3374 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3375 | if (curproxy == &defproxy) { |
| 3376 | 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] | 3377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3378 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3379 | } |
| 3380 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3381 | err = invalid_char(args[1]); |
| 3382 | if (err) { |
| 3383 | Alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3384 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3385 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3388 | 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] | 3389 | Alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3390 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3392 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3393 | } |
| 3394 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3395 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3396 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3397 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3398 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3399 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3400 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3401 | if (*(args[1]) == 0) { |
| 3402 | Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3403 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3405 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3406 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3407 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3408 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3409 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3410 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3411 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3412 | curproxy->cookie_name = strdup(args[1]); |
| 3413 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3414 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3415 | cur_arg = 2; |
| 3416 | while (*(args[cur_arg])) { |
| 3417 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3418 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3419 | } |
| 3420 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3421 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3422 | } |
| 3423 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3424 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3425 | } |
| 3426 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3427 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3428 | } |
| 3429 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3430 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3431 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3432 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3433 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3434 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3435 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3436 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3437 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3438 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3439 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3440 | } |
| 3441 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3442 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3443 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3444 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3445 | if (!*args[cur_arg + 1]) { |
| 3446 | Alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3447 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3448 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3449 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3450 | } |
| 3451 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3452 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3453 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3454 | Warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3455 | " dots nor does not start with a dot." |
| 3456 | " RFC forbids it, this configuration may not work properly.\n", |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3457 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3458 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3462 | if (err) { |
| 3463 | Alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3464 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3466 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3467 | } |
| 3468 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3469 | if (!curproxy->cookie_domain) { |
| 3470 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3471 | } else { |
| 3472 | /* one domain was already specified, add another one by |
| 3473 | * building the string which will be returned along with |
| 3474 | * the cookie. |
| 3475 | */ |
| 3476 | char *new_ptr; |
| 3477 | int new_len = strlen(curproxy->cookie_domain) + |
| 3478 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3479 | new_ptr = malloc(new_len); |
| 3480 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3481 | free(curproxy->cookie_domain); |
| 3482 | curproxy->cookie_domain = new_ptr; |
| 3483 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3484 | cur_arg++; |
| 3485 | } |
| 3486 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3487 | unsigned int maxidle; |
| 3488 | const char *res; |
| 3489 | |
| 3490 | if (!*args[cur_arg + 1]) { |
| 3491 | Alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3492 | file, linenum, args[cur_arg]); |
| 3493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3494 | goto out; |
| 3495 | } |
| 3496 | |
| 3497 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3498 | if (res) { |
| 3499 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3500 | file, linenum, *res, args[cur_arg]); |
| 3501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3502 | goto out; |
| 3503 | } |
| 3504 | curproxy->cookie_maxidle = maxidle; |
| 3505 | cur_arg++; |
| 3506 | } |
| 3507 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3508 | unsigned int maxlife; |
| 3509 | const char *res; |
| 3510 | |
| 3511 | if (!*args[cur_arg + 1]) { |
| 3512 | Alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3513 | file, linenum, args[cur_arg]); |
| 3514 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3515 | goto out; |
| 3516 | } |
| 3517 | |
| 3518 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3519 | if (res) { |
| 3520 | Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3521 | file, linenum, *res, args[cur_arg]); |
| 3522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3523 | goto out; |
| 3524 | } |
| 3525 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3526 | cur_arg++; |
| 3527 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3528 | else { |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3529 | 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] | 3530 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3532 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3533 | } |
| 3534 | cur_arg++; |
| 3535 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3536 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3537 | Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3538 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3539 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3540 | } |
| 3541 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3542 | 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] | 3543 | Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3544 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3545 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3546 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3547 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3548 | 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] | 3549 | Alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3550 | file, linenum); |
| 3551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3552 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3553 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3554 | else if (!strcmp(args[0], "email-alert")) { |
| 3555 | if (*(args[1]) == 0) { |
| 3556 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3557 | file, linenum, args[0]); |
| 3558 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3559 | goto out; |
| 3560 | } |
| 3561 | |
| 3562 | if (!strcmp(args[1], "from")) { |
| 3563 | if (*(args[1]) == 0) { |
| 3564 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3565 | file, linenum, args[1]); |
| 3566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3567 | goto out; |
| 3568 | } |
| 3569 | free(curproxy->email_alert.from); |
| 3570 | curproxy->email_alert.from = strdup(args[2]); |
| 3571 | } |
| 3572 | else if (!strcmp(args[1], "mailers")) { |
| 3573 | if (*(args[1]) == 0) { |
| 3574 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3575 | file, linenum, args[1]); |
| 3576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3577 | goto out; |
| 3578 | } |
| 3579 | free(curproxy->email_alert.mailers.name); |
| 3580 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3581 | } |
| 3582 | else if (!strcmp(args[1], "myhostname")) { |
| 3583 | if (*(args[1]) == 0) { |
| 3584 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3585 | file, linenum, args[1]); |
| 3586 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3587 | goto out; |
| 3588 | } |
| 3589 | free(curproxy->email_alert.myhostname); |
| 3590 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3591 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3592 | else if (!strcmp(args[1], "level")) { |
| 3593 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3594 | if (curproxy->email_alert.level < 0) { |
| 3595 | Alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3596 | file, linenum, args[1], args[2]); |
| 3597 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3598 | goto out; |
| 3599 | } |
| 3600 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3601 | else if (!strcmp(args[1], "to")) { |
| 3602 | if (*(args[1]) == 0) { |
| 3603 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3604 | file, linenum, args[1]); |
| 3605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3606 | goto out; |
| 3607 | } |
| 3608 | free(curproxy->email_alert.to); |
| 3609 | curproxy->email_alert.to = strdup(args[2]); |
| 3610 | } |
| 3611 | else { |
| 3612 | Alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3613 | file, linenum, args[1]); |
| 3614 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3615 | goto out; |
| 3616 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3617 | /* Indicate that the email_alert is at least partially configured */ |
| 3618 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3619 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3620 | else if (!strcmp(args[0], "external-check")) { |
| 3621 | if (*(args[1]) == 0) { |
| 3622 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3623 | file, linenum, args[0]); |
| 3624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3625 | goto out; |
| 3626 | } |
| 3627 | |
| 3628 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3629 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3630 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3631 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3632 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3633 | file, linenum, args[1]); |
| 3634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3635 | goto out; |
| 3636 | } |
| 3637 | free(curproxy->check_command); |
| 3638 | curproxy->check_command = strdup(args[2]); |
| 3639 | } |
| 3640 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3641 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3642 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3643 | if (*(args[2]) == 0) { |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3644 | Alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3645 | file, linenum, args[1]); |
| 3646 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3647 | goto out; |
| 3648 | } |
| 3649 | free(curproxy->check_path); |
| 3650 | curproxy->check_path = strdup(args[2]); |
| 3651 | } |
| 3652 | else { |
| 3653 | Alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3654 | file, linenum, args[1]); |
| 3655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3656 | goto out; |
| 3657 | } |
| 3658 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3659 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3660 | if (*(args[1]) == 0) { |
| 3661 | Alert("parsing [%s:%d] : missing persist method.\n", |
| 3662 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3664 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3668 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3669 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3670 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3671 | const char *beg, *end; |
| 3672 | |
| 3673 | beg = args[1] + 11; |
| 3674 | end = strchr(beg, ')'); |
| 3675 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3676 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3677 | goto out; |
| 3678 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3679 | if (!end || end == beg) { |
| 3680 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3681 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3683 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | free(curproxy->rdp_cookie_name); |
| 3687 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3688 | curproxy->rdp_cookie_len = end-beg; |
| 3689 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3690 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3691 | free(curproxy->rdp_cookie_name); |
| 3692 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3693 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3694 | } |
| 3695 | else { /* syntax */ |
| 3696 | Alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3697 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3699 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3700 | } |
| 3701 | } |
| 3702 | else { |
| 3703 | Alert("parsing [%s:%d] : unknown persist method.\n", |
| 3704 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3706 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3707 | } |
| 3708 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3709 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3710 | Alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
| 3711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3712 | goto out; |
| 3713 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3714 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3715 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3716 | err_code |= ERR_WARN; |
| 3717 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3718 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3719 | } |
| 3720 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3721 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3722 | } |
| 3723 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3724 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3725 | } |
| 3726 | else { |
| 3727 | Alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3728 | file, linenum, args[0], args[1]); |
| 3729 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3730 | goto out; |
| 3731 | } |
| 3732 | } |
| 3733 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3734 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3735 | err_code |= ERR_WARN; |
| 3736 | if (*(args[1]) == 0) { |
| 3737 | Alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3738 | file, linenum, args[0]); |
| 3739 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3740 | goto out; |
| 3741 | } |
| 3742 | else if (!strcmp(args[1], "use-backend-name")) |
| 3743 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3744 | else |
| 3745 | curproxy->server_state_file_name = strdup(args[1]); |
| 3746 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3747 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3748 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3749 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3750 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3751 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3752 | if (curproxy == &defproxy) { |
| 3753 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 3754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3755 | goto out; |
| 3756 | } |
| 3757 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3758 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3759 | goto out; |
| 3760 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3761 | if (*(args[4]) == 0) { |
| 3762 | Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3763 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3764 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3765 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3766 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3767 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3768 | curproxy->capture_name = strdup(args[2]); |
| 3769 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3770 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3771 | curproxy->to_log |= LW_COOKIE; |
| 3772 | } |
| 3773 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3774 | struct cap_hdr *hdr; |
| 3775 | |
| 3776 | if (curproxy == &defproxy) { |
| 3777 | 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] | 3778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3779 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3780 | } |
| 3781 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3782 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3783 | goto out; |
| 3784 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3785 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3786 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3787 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3789 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3790 | } |
| 3791 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3792 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3793 | hdr->next = curproxy->req_cap; |
| 3794 | hdr->name = strdup(args[3]); |
| 3795 | hdr->namelen = strlen(args[3]); |
| 3796 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3797 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3798 | hdr->index = curproxy->nb_req_cap++; |
| 3799 | curproxy->req_cap = hdr; |
| 3800 | curproxy->to_log |= LW_REQHDR; |
| 3801 | } |
| 3802 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3803 | struct cap_hdr *hdr; |
| 3804 | |
| 3805 | if (curproxy == &defproxy) { |
| 3806 | 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] | 3807 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3808 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3809 | } |
| 3810 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3811 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3812 | goto out; |
| 3813 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3814 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 3815 | Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3816 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3818 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3819 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3820 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3821 | hdr->next = curproxy->rsp_cap; |
| 3822 | hdr->name = strdup(args[3]); |
| 3823 | hdr->namelen = strlen(args[3]); |
| 3824 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3825 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3826 | hdr->index = curproxy->nb_rsp_cap++; |
| 3827 | curproxy->rsp_cap = hdr; |
| 3828 | curproxy->to_log |= LW_RSPHDR; |
| 3829 | } |
| 3830 | else { |
| 3831 | Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3832 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3835 | } |
| 3836 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3837 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3838 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3840 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3841 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3842 | goto out; |
| 3843 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3844 | if (*(args[1]) == 0) { |
| 3845 | Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3846 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3848 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3849 | } |
| 3850 | curproxy->conn_retries = atol(args[1]); |
| 3851 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3852 | 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] | 3853 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3854 | |
| 3855 | if (curproxy == &defproxy) { |
| 3856 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3858 | goto out; |
| 3859 | } |
| 3860 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3861 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3862 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3863 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3864 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3865 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3866 | 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] | 3867 | 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] | 3868 | file, linenum, args[0]); |
| 3869 | err_code |= ERR_WARN; |
| 3870 | } |
| 3871 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3872 | 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] | 3873 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3874 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3875 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3876 | goto out; |
| 3877 | } |
| 3878 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3879 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3880 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3881 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3882 | file, linenum); |
| 3883 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3884 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3885 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3886 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3887 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3888 | |
| 3889 | if (curproxy == &defproxy) { |
| 3890 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3892 | goto out; |
| 3893 | } |
| 3894 | |
| 3895 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3896 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3897 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3898 | 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] | 3899 | Warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3900 | file, linenum, args[0]); |
| 3901 | err_code |= ERR_WARN; |
| 3902 | } |
| 3903 | |
| 3904 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3905 | |
| 3906 | if (!rule) { |
| 3907 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3908 | goto out; |
| 3909 | } |
| 3910 | |
| 3911 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3912 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3913 | file, linenum); |
| 3914 | |
| 3915 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3916 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3917 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3918 | /* set the header name and length into the proxy structure */ |
| 3919 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3920 | err_code |= ERR_WARN; |
| 3921 | |
| 3922 | if (!*args[1]) { |
| 3923 | Alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3924 | file, linenum, args[0]); |
| 3925 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3926 | goto out; |
| 3927 | } |
| 3928 | |
| 3929 | /* set the desired header name */ |
| 3930 | free(curproxy->server_id_hdr_name); |
| 3931 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3932 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3933 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3934 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3935 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3936 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3937 | if (curproxy == &defproxy) { |
| 3938 | 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] | 3939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3940 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3941 | } |
| 3942 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3943 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3944 | * be processed before all http-request rules, we put them into their own list |
| 3945 | * and will insert them at the end. |
| 3946 | */ |
| 3947 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3948 | if (!rule) { |
| 3949 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3950 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3951 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3952 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3953 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3954 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3955 | file, linenum); |
| 3956 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3957 | |
| 3958 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
| 3959 | 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]); |
| 3960 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3961 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3962 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3963 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3964 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3965 | if (curproxy == &defproxy) { |
| 3966 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 3967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3968 | goto out; |
| 3969 | } |
| 3970 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3971 | 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] | 3972 | Alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3973 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3975 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3976 | } |
| 3977 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3978 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3979 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3980 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3981 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3982 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3983 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3984 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3985 | struct switching_rule *rule; |
| 3986 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3987 | if (curproxy == &defproxy) { |
| 3988 | 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] | 3989 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3990 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3991 | } |
| 3992 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3993 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3994 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3995 | |
| 3996 | if (*(args[1]) == 0) { |
| 3997 | 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] | 3998 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3999 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4000 | } |
| 4001 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4002 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 4003 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4004 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4005 | file, linenum, errmsg); |
| 4006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4007 | goto out; |
| 4008 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4009 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4010 | 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] | 4011 | } |
| 4012 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4013 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4014 | rule->cond = cond; |
| 4015 | rule->be.name = strdup(args[1]); |
| 4016 | LIST_INIT(&rule->list); |
| 4017 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4018 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4019 | else if (strcmp(args[0], "use-server") == 0) { |
| 4020 | struct server_rule *rule; |
| 4021 | |
| 4022 | if (curproxy == &defproxy) { |
| 4023 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4025 | goto out; |
| 4026 | } |
| 4027 | |
| 4028 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4029 | err_code |= ERR_WARN; |
| 4030 | |
| 4031 | if (*(args[1]) == 0) { |
| 4032 | Alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 4033 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4034 | goto out; |
| 4035 | } |
| 4036 | |
| 4037 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4038 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4039 | file, linenum, args[0]); |
| 4040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4041 | goto out; |
| 4042 | } |
| 4043 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4044 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4045 | Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4046 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4048 | goto out; |
| 4049 | } |
| 4050 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4051 | 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] | 4052 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4053 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4054 | rule->cond = cond; |
| 4055 | rule->srv.name = strdup(args[1]); |
| 4056 | LIST_INIT(&rule->list); |
| 4057 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4058 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4059 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4060 | else if ((!strcmp(args[0], "force-persist")) || |
| 4061 | (!strcmp(args[0], "ignore-persist"))) { |
| 4062 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4063 | |
| 4064 | if (curproxy == &defproxy) { |
| 4065 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4067 | goto out; |
| 4068 | } |
| 4069 | |
| 4070 | if (warnifnotcap(curproxy, PR_CAP_FE|PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4071 | err_code |= ERR_WARN; |
| 4072 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4073 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4074 | Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4075 | file, linenum, args[0]); |
| 4076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4077 | goto out; |
| 4078 | } |
| 4079 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4080 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 4081 | Alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4082 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4084 | goto out; |
| 4085 | } |
| 4086 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4087 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4088 | * where force-persist is applied. |
| 4089 | */ |
| 4090 | 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] | 4091 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4092 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4093 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4094 | if (!strcmp(args[0], "force-persist")) { |
| 4095 | rule->type = PERSIST_TYPE_FORCE; |
| 4096 | } else { |
| 4097 | rule->type = PERSIST_TYPE_IGNORE; |
| 4098 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4099 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4100 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4101 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4102 | else if (!strcmp(args[0], "stick-table")) { |
| 4103 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4104 | struct proxy *other; |
| 4105 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4106 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4107 | if (other) { |
| 4108 | Alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4109 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
| 4110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4111 | goto out; |
| 4112 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4113 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4114 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4115 | curproxy->table.type = (unsigned int)-1; |
| 4116 | while (*args[myidx]) { |
| 4117 | const char *err; |
| 4118 | |
| 4119 | if (strcmp(args[myidx], "size") == 0) { |
| 4120 | myidx++; |
| 4121 | if (!*(args[myidx])) { |
| 4122 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4123 | file, linenum, args[myidx-1]); |
| 4124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4125 | goto out; |
| 4126 | } |
| 4127 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
| 4128 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4129 | file, linenum, *err, args[myidx-1]); |
| 4130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4131 | goto out; |
| 4132 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4133 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4134 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4135 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4136 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4137 | if (!*(args[myidx])) { |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4138 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4139 | file, linenum, args[myidx-1]); |
| 4140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4141 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4142 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4143 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4144 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4145 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4146 | myidx++; |
| 4147 | if (!*(args[myidx])) { |
| 4148 | Alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4149 | file, linenum, args[myidx-1]); |
| 4150 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4151 | goto out; |
| 4152 | } |
| 4153 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4154 | if (err) { |
| 4155 | Alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4156 | file, linenum, *err, args[myidx-1]); |
| 4157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4158 | goto out; |
| 4159 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4160 | if (val > INT_MAX) { |
| 4161 | Alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4162 | file, linenum, val); |
| 4163 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4164 | goto out; |
| 4165 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4166 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4167 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4168 | } |
| 4169 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4170 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4171 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4172 | } |
| 4173 | else if (strcmp(args[myidx], "type") == 0) { |
| 4174 | myidx++; |
| 4175 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
| 4176 | Alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4177 | file, linenum, args[myidx]); |
| 4178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4179 | goto out; |
| 4180 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4181 | /* myidx already points to next arg */ |
| 4182 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4183 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4184 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4185 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4186 | |
| 4187 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4188 | nw = args[myidx]; |
| 4189 | while (*nw) { |
| 4190 | /* the "store" keyword supports a comma-separated list */ |
| 4191 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4192 | sa = NULL; /* store arg */ |
| 4193 | while (*nw && *nw != ',') { |
| 4194 | if (*nw == '(') { |
| 4195 | *nw = 0; |
| 4196 | sa = ++nw; |
| 4197 | while (*nw != ')') { |
| 4198 | if (!*nw) { |
| 4199 | Alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4200 | file, linenum, args[0], cw); |
| 4201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4202 | goto out; |
| 4203 | } |
| 4204 | nw++; |
| 4205 | } |
| 4206 | *nw = '\0'; |
| 4207 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4208 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4209 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4210 | if (*nw) |
| 4211 | *nw++ = '\0'; |
| 4212 | type = stktable_get_data_type(cw); |
| 4213 | if (type < 0) { |
| 4214 | Alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4215 | file, linenum, args[0], cw); |
| 4216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4217 | goto out; |
| 4218 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4219 | |
| 4220 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4221 | switch (err) { |
| 4222 | case PE_NONE: break; |
| 4223 | case PE_EXIST: |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4224 | Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4225 | file, linenum, args[0], cw); |
| 4226 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4227 | break; |
| 4228 | |
| 4229 | case PE_ARG_MISSING: |
| 4230 | Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4231 | file, linenum, args[0], cw); |
| 4232 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4233 | goto out; |
| 4234 | |
| 4235 | case PE_ARG_NOT_USED: |
| 4236 | Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4237 | file, linenum, args[0], cw); |
| 4238 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4239 | goto out; |
| 4240 | |
| 4241 | default: |
| 4242 | Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4243 | file, linenum, args[0], cw); |
| 4244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4245 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4246 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4247 | } |
| 4248 | myidx++; |
| 4249 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4250 | else { |
| 4251 | Alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4252 | file, linenum, args[myidx]); |
| 4253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4254 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4255 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | if (!curproxy->table.size) { |
| 4259 | Alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4260 | file, linenum); |
| 4261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4262 | goto out; |
| 4263 | } |
| 4264 | |
| 4265 | if (curproxy->table.type == (unsigned int)-1) { |
| 4266 | Alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4267 | file, linenum); |
| 4268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4269 | goto out; |
| 4270 | } |
| 4271 | } |
| 4272 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4273 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4274 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4275 | int myidx = 0; |
| 4276 | const char *name = NULL; |
| 4277 | int flags; |
| 4278 | |
| 4279 | if (curproxy == &defproxy) { |
| 4280 | Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4281 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4282 | goto out; |
| 4283 | } |
| 4284 | |
| 4285 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4286 | err_code |= ERR_WARN; |
| 4287 | goto out; |
| 4288 | } |
| 4289 | |
| 4290 | myidx++; |
| 4291 | if ((strcmp(args[myidx], "store") == 0) || |
| 4292 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4293 | myidx++; |
| 4294 | flags = STK_IS_STORE; |
| 4295 | } |
| 4296 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4297 | myidx++; |
| 4298 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4299 | } |
| 4300 | else if (strcmp(args[myidx], "match") == 0) { |
| 4301 | myidx++; |
| 4302 | flags = STK_IS_MATCH; |
| 4303 | } |
| 4304 | else if (strcmp(args[myidx], "on") == 0) { |
| 4305 | myidx++; |
| 4306 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4307 | } |
| 4308 | else { |
| 4309 | Alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
| 4312 | } |
| 4313 | |
| 4314 | if (*(args[myidx]) == 0) { |
| 4315 | Alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 4316 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4317 | goto out; |
| 4318 | } |
| 4319 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4320 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4321 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4322 | if (!expr) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 4323 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4325 | goto out; |
| 4326 | } |
| 4327 | |
| 4328 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4329 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 4330 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4331 | 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] | 4332 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4333 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4334 | goto out; |
| 4335 | } |
| 4336 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4337 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 4338 | Alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4339 | 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] | 4340 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4341 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4342 | goto out; |
| 4343 | } |
| 4344 | } |
| 4345 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4346 | /* 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] | 4347 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4348 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4349 | if (strcmp(args[myidx], "table") == 0) { |
| 4350 | myidx++; |
| 4351 | name = args[myidx++]; |
| 4352 | } |
| 4353 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4354 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4355 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 4356 | Alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4357 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4358 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4359 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4360 | goto out; |
| 4361 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4362 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4363 | else if (*(args[myidx])) { |
| 4364 | Alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4365 | file, linenum, args[0], args[myidx]); |
| 4366 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4367 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4368 | goto out; |
| 4369 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4370 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4371 | 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] | 4372 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4373 | 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] | 4374 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4375 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4376 | rule->cond = cond; |
| 4377 | rule->expr = expr; |
| 4378 | rule->flags = flags; |
| 4379 | rule->table.name = name ? strdup(name) : NULL; |
| 4380 | LIST_INIT(&rule->list); |
| 4381 | if (flags & STK_ON_RSP) |
| 4382 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4383 | else |
| 4384 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4385 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4386 | else if (!strcmp(args[0], "stats")) { |
| 4387 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4388 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4389 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4390 | if (!*args[1]) { |
| 4391 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4392 | } else if (!strcmp(args[1], "admin")) { |
| 4393 | struct stats_admin_rule *rule; |
| 4394 | |
| 4395 | if (curproxy == &defproxy) { |
| 4396 | Alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 4397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4398 | goto out; |
| 4399 | } |
| 4400 | |
| 4401 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4402 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4403 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4404 | goto out; |
| 4405 | } |
| 4406 | |
| 4407 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 4408 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4409 | file, linenum, args[0], args[1]); |
| 4410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4411 | goto out; |
| 4412 | } |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 4413 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 4414 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4415 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4417 | goto out; |
| 4418 | } |
| 4419 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4420 | err_code |= warnif_cond_conflicts(cond, |
| 4421 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4422 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4423 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4424 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4425 | rule->cond = cond; |
| 4426 | LIST_INIT(&rule->list); |
| 4427 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4428 | } else if (!strcmp(args[1], "uri")) { |
| 4429 | if (*(args[2]) == 0) { |
| 4430 | Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4431 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4432 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4433 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 4434 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4435 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4436 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4437 | } |
| 4438 | } else if (!strcmp(args[1], "realm")) { |
| 4439 | if (*(args[2]) == 0) { |
| 4440 | Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4442 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4443 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 4444 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4445 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4446 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4447 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4448 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4449 | unsigned interval; |
| 4450 | |
| 4451 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4452 | if (err) { |
| 4453 | Alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4454 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4456 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4457 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 4458 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4459 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4460 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4461 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4462 | } 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] | 4463 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4464 | |
| 4465 | if (curproxy == &defproxy) { |
| 4466 | Alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 4467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4468 | goto out; |
| 4469 | } |
| 4470 | |
| 4471 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4472 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4473 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4474 | goto out; |
| 4475 | } |
| 4476 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4477 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4478 | !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] | 4479 | Warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4480 | file, linenum, args[0]); |
| 4481 | err_code |= ERR_WARN; |
| 4482 | } |
| 4483 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4484 | 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] | 4485 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4486 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4487 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4488 | goto out; |
| 4489 | } |
| 4490 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4491 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4492 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4493 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4494 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4495 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4496 | } else if (!strcmp(args[1], "auth")) { |
| 4497 | if (*(args[2]) == 0) { |
| 4498 | 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] | 4499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4500 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4501 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 4502 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4503 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4504 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4505 | } |
| 4506 | } else if (!strcmp(args[1], "scope")) { |
| 4507 | if (*(args[2]) == 0) { |
| 4508 | Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4510 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4511 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 4512 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4513 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4514 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4515 | } |
| 4516 | } else if (!strcmp(args[1], "enable")) { |
| 4517 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 4518 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4519 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4521 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4522 | } else if (!strcmp(args[1], "hide-version")) { |
| 4523 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
| 4524 | Alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4525 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4526 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4527 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4528 | } else if (!strcmp(args[1], "show-legends")) { |
| 4529 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
| 4530 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4531 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4532 | goto out; |
| 4533 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4534 | } else if (!strcmp(args[1], "show-node")) { |
| 4535 | |
| 4536 | if (*args[2]) { |
| 4537 | int i; |
| 4538 | char c; |
| 4539 | |
| 4540 | for (i=0; args[2][i]; i++) { |
| 4541 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4542 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4543 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4544 | break; |
| 4545 | } |
| 4546 | |
| 4547 | if (!i || args[2][i]) { |
| 4548 | Alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4549 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4550 | file, linenum, args[0], args[1]); |
| 4551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4552 | goto out; |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 4557 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4558 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4559 | goto out; |
| 4560 | } |
| 4561 | } else if (!strcmp(args[1], "show-desc")) { |
| 4562 | char *desc = NULL; |
| 4563 | |
| 4564 | if (*args[2]) { |
| 4565 | int i, len=0; |
| 4566 | char *d; |
| 4567 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4568 | for (i = 2; *args[i]; i++) |
| 4569 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4570 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4571 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4572 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4573 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4574 | for (i = 3; *args[i]; i++) |
| 4575 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | if (!*args[2] && !global.desc) |
| 4579 | Warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4580 | file, linenum, args[1]); |
| 4581 | else { |
| 4582 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4583 | free(desc); |
| 4584 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 4585 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4586 | goto out; |
| 4587 | } |
| 4588 | free(desc); |
| 4589 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4590 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4591 | stats_error_parsing: |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4592 | 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] | 4593 | 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] | 4594 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4595 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4596 | } |
| 4597 | } |
| 4598 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4599 | int optnum; |
| 4600 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4601 | if (*(args[1]) == '\0') { |
| 4602 | Alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4603 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4605 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4606 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4607 | |
| 4608 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4609 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4610 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 4611 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4612 | file, linenum, cfg_opts[optnum].name); |
| 4613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4614 | goto out; |
| 4615 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4616 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4617 | goto out; |
| 4618 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4619 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4620 | err_code |= ERR_WARN; |
| 4621 | goto out; |
| 4622 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4623 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4624 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4625 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4626 | |
| 4627 | switch (kwm) { |
| 4628 | case KWM_STD: |
| 4629 | curproxy->options |= cfg_opts[optnum].val; |
| 4630 | break; |
| 4631 | case KWM_NO: |
| 4632 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4633 | break; |
| 4634 | case KWM_DEF: /* already cleared */ |
| 4635 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4636 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4637 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4638 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4642 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4643 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4644 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 4645 | Alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4646 | file, linenum, cfg_opts2[optnum].name); |
| 4647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4648 | goto out; |
| 4649 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4650 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4651 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4652 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4653 | err_code |= ERR_WARN; |
| 4654 | goto out; |
| 4655 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4656 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4657 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4658 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4659 | |
| 4660 | switch (kwm) { |
| 4661 | case KWM_STD: |
| 4662 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4663 | break; |
| 4664 | case KWM_NO: |
| 4665 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4666 | break; |
| 4667 | case KWM_DEF: /* already cleared */ |
| 4668 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4669 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4670 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4671 | } |
| 4672 | } |
| 4673 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4674 | /* HTTP options override each other. They can be cancelled using |
| 4675 | * "no option xxx" which only switches to default mode if the mode |
| 4676 | * was this one (useful for cancelling options set in defaults |
| 4677 | * sections). |
| 4678 | */ |
| 4679 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4680 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4681 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4682 | if (kwm == KWM_STD) { |
| 4683 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4684 | curproxy->options |= PR_O_HTTP_PCL; |
| 4685 | goto out; |
| 4686 | } |
| 4687 | else if (kwm == KWM_NO) { |
| 4688 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4689 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4690 | goto out; |
| 4691 | } |
| 4692 | } |
| 4693 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4694 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4695 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4696 | if (kwm == KWM_STD) { |
| 4697 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4698 | curproxy->options |= PR_O_HTTP_FCL; |
| 4699 | goto out; |
| 4700 | } |
| 4701 | else if (kwm == KWM_NO) { |
| 4702 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4703 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4704 | goto out; |
| 4705 | } |
| 4706 | } |
| 4707 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4708 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4709 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4710 | if (kwm == KWM_STD) { |
| 4711 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4712 | curproxy->options |= PR_O_HTTP_SCL; |
| 4713 | goto out; |
| 4714 | } |
| 4715 | else if (kwm == KWM_NO) { |
| 4716 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4717 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4718 | goto out; |
| 4719 | } |
| 4720 | } |
| 4721 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4722 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4723 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4724 | if (kwm == KWM_STD) { |
| 4725 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4726 | curproxy->options |= PR_O_HTTP_KAL; |
| 4727 | goto out; |
| 4728 | } |
| 4729 | else if (kwm == KWM_NO) { |
| 4730 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4731 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4732 | goto out; |
| 4733 | } |
| 4734 | } |
| 4735 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4736 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4737 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4738 | if (kwm == KWM_STD) { |
| 4739 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4740 | curproxy->options |= PR_O_HTTP_TUN; |
| 4741 | goto out; |
| 4742 | } |
| 4743 | else if (kwm == KWM_NO) { |
| 4744 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4745 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4746 | goto out; |
| 4747 | } |
| 4748 | } |
| 4749 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4750 | /* Redispatch can take an integer argument that control when the |
| 4751 | * resispatch occurs. All values are relative to the retries option. |
| 4752 | * This can be cancelled using "no option xxx". |
| 4753 | */ |
| 4754 | if (strcmp(args[1], "redispatch") == 0) { |
| 4755 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4756 | err_code |= ERR_WARN; |
| 4757 | goto out; |
| 4758 | } |
| 4759 | |
| 4760 | curproxy->no_options &= ~PR_O_REDISP; |
| 4761 | curproxy->options &= ~PR_O_REDISP; |
| 4762 | |
| 4763 | switch (kwm) { |
| 4764 | case KWM_STD: |
| 4765 | curproxy->options |= PR_O_REDISP; |
| 4766 | curproxy->redispatch_after = -1; |
| 4767 | if(*args[2]) { |
| 4768 | curproxy->redispatch_after = atol(args[2]); |
| 4769 | } |
| 4770 | break; |
| 4771 | case KWM_NO: |
| 4772 | curproxy->no_options |= PR_O_REDISP; |
| 4773 | curproxy->redispatch_after = 0; |
| 4774 | break; |
| 4775 | case KWM_DEF: /* already cleared */ |
| 4776 | break; |
| 4777 | } |
| 4778 | goto out; |
| 4779 | } |
| 4780 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4781 | if (kwm != KWM_STD) { |
| 4782 | 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] | 4783 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4785 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4786 | } |
| 4787 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4788 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4789 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4790 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4791 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4792 | if (*(args[2]) != '\0') { |
| 4793 | if (!strcmp(args[2], "clf")) { |
| 4794 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4795 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4796 | } else { |
William Lallemand | 77063bc | 2015-05-28 18:02:48 +0200 | [diff] [blame] | 4797 | 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] | 4798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4799 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4800 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4801 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4802 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4803 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4804 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4805 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4806 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4807 | free(curproxy->conf.logformat_string); |
| 4808 | curproxy->conf.logformat_string = logformat; |
| 4809 | |
| 4810 | free(curproxy->conf.lfs_file); |
| 4811 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4812 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4813 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4814 | else if (!strcmp(args[1], "tcplog")) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4815 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4816 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4817 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4818 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4819 | free(curproxy->conf.logformat_string); |
| 4820 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4821 | |
| 4822 | free(curproxy->conf.lfs_file); |
| 4823 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4824 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4825 | |
| 4826 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4827 | goto out; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4828 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4829 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4830 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4831 | 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] | 4832 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4833 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4834 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4835 | goto out; |
| 4836 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4837 | if (curproxy->cap & PR_CAP_FE) |
| 4838 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4839 | if (curproxy->cap & PR_CAP_BE) |
| 4840 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4841 | } |
| 4842 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4843 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4844 | err_code |= ERR_WARN; |
| 4845 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4846 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4847 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4848 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4849 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4850 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4851 | if (!*args[2]) { /* no argument */ |
| 4852 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4853 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4854 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4855 | 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] | 4856 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4857 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4858 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4859 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4860 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4861 | if (*args[4]) |
| 4862 | reqlen += strlen(args[4]); |
| 4863 | else |
| 4864 | reqlen += strlen("HTTP/1.0"); |
| 4865 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4866 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4867 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4868 | "%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] | 4869 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4870 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4871 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4872 | } |
| 4873 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4874 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4875 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4876 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4877 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4878 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4879 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4880 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4881 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4882 | |
| 4883 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4884 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4885 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4886 | else if (!strcmp(args[1], "smtpchk")) { |
| 4887 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4888 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4889 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4890 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4891 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4892 | |
| 4893 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4894 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4895 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4896 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4897 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4898 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4899 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4900 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4901 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4902 | } else { |
| 4903 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4904 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4905 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4906 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4907 | } |
| 4908 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4909 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4910 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4911 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4912 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4913 | /* use PostgreSQL request to check servers' health */ |
| 4914 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4915 | err_code |= ERR_WARN; |
| 4916 | |
| 4917 | free(curproxy->check_req); |
| 4918 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4919 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4920 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4921 | |
| 4922 | if (*(args[2])) { |
| 4923 | int cur_arg = 2; |
| 4924 | |
| 4925 | while (*(args[cur_arg])) { |
| 4926 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4927 | char * packet; |
| 4928 | uint32_t packet_len; |
| 4929 | uint32_t pv; |
| 4930 | |
| 4931 | /* suboption header - needs additional argument for it */ |
| 4932 | if (*(args[cur_arg+1]) == 0) { |
| 4933 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4934 | file, linenum, args[0], args[1], args[cur_arg]); |
| 4935 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4936 | goto out; |
| 4937 | } |
| 4938 | |
| 4939 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4940 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4941 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4942 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4943 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4944 | |
| 4945 | memcpy(packet + 4, &pv, 4); |
| 4946 | |
| 4947 | /* copy "user" */ |
| 4948 | memcpy(packet + 8, "user", 4); |
| 4949 | |
| 4950 | /* copy username */ |
| 4951 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 4952 | |
| 4953 | free(curproxy->check_req); |
| 4954 | curproxy->check_req = packet; |
| 4955 | curproxy->check_len = packet_len; |
| 4956 | |
| 4957 | packet_len = htonl(packet_len); |
| 4958 | memcpy(packet, &packet_len, 4); |
| 4959 | cur_arg += 2; |
| 4960 | } else { |
| 4961 | /* unknown suboption - catchall */ |
| 4962 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 4963 | file, linenum, args[0], args[1]); |
| 4964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4965 | goto out; |
| 4966 | } |
| 4967 | } /* end while loop */ |
| 4968 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4969 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4970 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4973 | else if (!strcmp(args[1], "redis-check")) { |
| 4974 | /* use REDIS PING request to check servers' health */ |
| 4975 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4976 | err_code |= ERR_WARN; |
| 4977 | |
| 4978 | free(curproxy->check_req); |
| 4979 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4980 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4981 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 4982 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4983 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4984 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 4985 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4986 | |
| 4987 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4988 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 4989 | } |
| 4990 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4991 | else if (!strcmp(args[1], "mysql-check")) { |
| 4992 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 4993 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4994 | err_code |= ERR_WARN; |
| 4995 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4996 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4997 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4998 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 4999 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5000 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5001 | /* 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] | 5002 | * const char mysql40_client_auth_pkt[] = { |
| 5003 | * "\x0e\x00\x00" // packet length |
| 5004 | * "\x01" // packet number |
| 5005 | * "\x00\x00" // client capabilities |
| 5006 | * "\x00\x00\x01" // max packet |
| 5007 | * "haproxy\x00" // username (null terminated string) |
| 5008 | * "\x00" // filler (always 0x00) |
| 5009 | * "\x01\x00\x00" // packet length |
| 5010 | * "\x00" // packet number |
| 5011 | * "\x01" // COM_QUIT command |
| 5012 | * }; |
| 5013 | */ |
| 5014 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5015 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5016 | * const char mysql41_client_auth_pkt[] = { |
| 5017 | * "\x0e\x00\x00\" // packet length |
| 5018 | * "\x01" // packet number |
| 5019 | * "\x00\x00\x00\x00" // client capabilities |
| 5020 | * "\x00\x00\x00\x01" // max packet |
| 5021 | * "\x21" // character set (UTF-8) |
| 5022 | * char[23] // All zeroes |
| 5023 | * "haproxy\x00" // username (null terminated string) |
| 5024 | * "\x00" // filler (always 0x00) |
| 5025 | * "\x01\x00\x00" // packet length |
| 5026 | * "\x00" // packet number |
| 5027 | * "\x01" // COM_QUIT command |
| 5028 | * }; |
| 5029 | */ |
| 5030 | |
| 5031 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5032 | if (*(args[2])) { |
| 5033 | int cur_arg = 2; |
| 5034 | |
| 5035 | while (*(args[cur_arg])) { |
| 5036 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5037 | char *mysqluser; |
| 5038 | int packetlen, reqlen, userlen; |
| 5039 | |
| 5040 | /* suboption header - needs additional argument for it */ |
| 5041 | if (*(args[cur_arg+1]) == 0) { |
| 5042 | Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5043 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5045 | goto out; |
| 5046 | } |
| 5047 | mysqluser = args[cur_arg + 1]; |
| 5048 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5049 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5050 | if (*(args[cur_arg+2])) { |
| 5051 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5052 | packetlen = userlen + 7 + 27; |
| 5053 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5054 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5055 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5056 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5057 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5058 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5059 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5060 | ((unsigned char) packetlen & 0xff), |
| 5061 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5062 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5063 | |
| 5064 | curproxy->check_req[3] = 1; |
| 5065 | curproxy->check_req[5] = 130; |
| 5066 | curproxy->check_req[11] = 1; |
| 5067 | curproxy->check_req[12] = 33; |
| 5068 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5069 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5070 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5071 | cur_arg += 3; |
| 5072 | } else { |
| 5073 | Alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
| 5074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5075 | goto out; |
| 5076 | } |
| 5077 | } else { |
| 5078 | packetlen = userlen + 7; |
| 5079 | reqlen = packetlen + 9; |
| 5080 | |
| 5081 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5082 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5083 | curproxy->check_len = reqlen; |
| 5084 | |
| 5085 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5086 | ((unsigned char) packetlen & 0xff), |
| 5087 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5088 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5089 | |
| 5090 | curproxy->check_req[3] = 1; |
| 5091 | curproxy->check_req[5] = 128; |
| 5092 | curproxy->check_req[8] = 1; |
| 5093 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5094 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5095 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5096 | cur_arg += 2; |
| 5097 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5098 | } else { |
| 5099 | /* unknown suboption - catchall */ |
| 5100 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5101 | file, linenum, args[0], args[1]); |
| 5102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5103 | goto out; |
| 5104 | } |
| 5105 | } /* end while loop */ |
| 5106 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5107 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5108 | else if (!strcmp(args[1], "ldap-check")) { |
| 5109 | /* use LDAP request to check servers' health */ |
| 5110 | free(curproxy->check_req); |
| 5111 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5112 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5113 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5114 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5115 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5116 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5117 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5118 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5119 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5120 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5121 | else if (!strcmp(args[1], "spop-check")) { |
| 5122 | if (curproxy == &defproxy) { |
| 5123 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5124 | file, linenum, args[0], args[1]); |
| 5125 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5126 | goto out; |
| 5127 | } |
| 5128 | if (curproxy->cap & PR_CAP_FE) { |
| 5129 | Alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5130 | file, linenum, args[0], args[1]); |
| 5131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5132 | goto out; |
| 5133 | } |
| 5134 | |
| 5135 | /* use SPOE request to check servers' health */ |
| 5136 | free(curproxy->check_req); |
| 5137 | curproxy->check_req = NULL; |
| 5138 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5139 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5140 | |
| 5141 | if (prepare_spoe_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
| 5142 | Alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
| 5143 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5144 | goto out; |
| 5145 | } |
| 5146 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5147 | goto out; |
| 5148 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5149 | else if (!strcmp(args[1], "tcp-check")) { |
| 5150 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5151 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5152 | err_code |= ERR_WARN; |
| 5153 | |
| 5154 | free(curproxy->check_req); |
| 5155 | curproxy->check_req = NULL; |
| 5156 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5157 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5158 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5159 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5160 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5161 | else if (!strcmp(args[1], "external-check")) { |
| 5162 | /* excute an external command to check servers' health */ |
| 5163 | free(curproxy->check_req); |
| 5164 | curproxy->check_req = NULL; |
| 5165 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5166 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5167 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5168 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5169 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5170 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5171 | int cur_arg; |
| 5172 | |
| 5173 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5174 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5175 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5176 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5177 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5178 | |
| 5179 | free(curproxy->fwdfor_hdr_name); |
| 5180 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5181 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5182 | |
| 5183 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5184 | cur_arg = 2; |
| 5185 | while (*(args[cur_arg])) { |
| 5186 | if (!strcmp(args[cur_arg], "except")) { |
| 5187 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5188 | 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] | 5189 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5190 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5192 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5193 | } |
| 5194 | /* flush useless bits */ |
| 5195 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5196 | cur_arg += 2; |
| 5197 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5198 | /* suboption header - needs additional argument for it */ |
| 5199 | if (*(args[cur_arg+1]) == 0) { |
| 5200 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5201 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5202 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5203 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5204 | } |
| 5205 | free(curproxy->fwdfor_hdr_name); |
| 5206 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5207 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5208 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5209 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5210 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5211 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5212 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5213 | /* unknown suboption - catchall */ |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5214 | 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] | 5215 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5217 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5218 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5219 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5220 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5221 | else if (!strcmp(args[1], "originalto")) { |
| 5222 | int cur_arg; |
| 5223 | |
| 5224 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5225 | * set default options (ie: bitfield, header name, etc) |
| 5226 | */ |
| 5227 | |
| 5228 | curproxy->options |= PR_O_ORGTO; |
| 5229 | |
| 5230 | free(curproxy->orgto_hdr_name); |
| 5231 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5232 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5233 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5234 | /* 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] | 5235 | cur_arg = 2; |
| 5236 | while (*(args[cur_arg])) { |
| 5237 | if (!strcmp(args[cur_arg], "except")) { |
| 5238 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5239 | 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] | 5240 | Alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5241 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5243 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5244 | } |
| 5245 | /* flush useless bits */ |
| 5246 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5247 | cur_arg += 2; |
| 5248 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5249 | /* suboption header - needs additional argument for it */ |
| 5250 | if (*(args[cur_arg+1]) == 0) { |
| 5251 | Alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5252 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5254 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5255 | } |
| 5256 | free(curproxy->orgto_hdr_name); |
| 5257 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5258 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5259 | cur_arg += 2; |
| 5260 | } else { |
| 5261 | /* unknown suboption - catchall */ |
| 5262 | Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5263 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5265 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5266 | } |
| 5267 | } /* end while loop */ |
| 5268 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5269 | else { |
| 5270 | Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5272 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5273 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5274 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5275 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5276 | else if (!strcmp(args[0], "default_backend")) { |
| 5277 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5278 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5279 | |
| 5280 | if (*(args[1]) == 0) { |
| 5281 | 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] | 5282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5283 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5284 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5285 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5286 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5287 | |
| 5288 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5289 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5290 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5291 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5292 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5293 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5294 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5295 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
| 5296 | 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] | 5297 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5298 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5299 | /* enable reconnections to dispatch */ |
| 5300 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5301 | |
| 5302 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5303 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5304 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5305 | else if (!strcmp(args[0], "http-reuse")) { |
| 5306 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5307 | err_code |= ERR_WARN; |
| 5308 | |
| 5309 | if (strcmp(args[1], "never") == 0) { |
| 5310 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5311 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5312 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5313 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5314 | goto out; |
| 5315 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5316 | else if (strcmp(args[1], "safe") == 0) { |
| 5317 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5318 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5319 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5320 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5321 | goto out; |
| 5322 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5323 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5324 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5325 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5326 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5327 | goto out; |
| 5328 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5329 | else if (strcmp(args[1], "always") == 0) { |
| 5330 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5331 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5332 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5333 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5334 | goto out; |
| 5335 | } |
| 5336 | else { |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5337 | 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] | 5338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5339 | goto out; |
| 5340 | } |
| 5341 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5342 | else if (!strcmp(args[0], "http-check")) { |
| 5343 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5344 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5345 | |
| 5346 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5347 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5348 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5349 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5350 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5351 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5352 | else if (strcmp(args[1], "send-state") == 0) { |
| 5353 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5354 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5355 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5356 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5357 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5358 | else if (strcmp(args[1], "expect") == 0) { |
| 5359 | const char *ptr_arg; |
| 5360 | int cur_arg; |
| 5361 | |
| 5362 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5363 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5364 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5365 | goto out; |
| 5366 | } |
| 5367 | |
| 5368 | cur_arg = 2; |
| 5369 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5370 | while (*(ptr_arg = args[cur_arg])) { |
| 5371 | while (*ptr_arg == '!') { |
| 5372 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5373 | ptr_arg++; |
| 5374 | } |
| 5375 | if (*ptr_arg) |
| 5376 | break; |
| 5377 | cur_arg++; |
| 5378 | } |
| 5379 | /* now ptr_arg points to the beginning of a word past any possible |
| 5380 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5381 | */ |
| 5382 | if (strcmp(ptr_arg, "status") == 0) { |
| 5383 | if (!*(args[cur_arg + 1])) { |
| 5384 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5385 | file, linenum, args[0], args[1], ptr_arg); |
| 5386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5387 | goto out; |
| 5388 | } |
| 5389 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5390 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5391 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5392 | } |
| 5393 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5394 | if (!*(args[cur_arg + 1])) { |
| 5395 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5396 | file, linenum, args[0], args[1], ptr_arg); |
| 5397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5398 | goto out; |
| 5399 | } |
| 5400 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5401 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5402 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5403 | } |
| 5404 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5405 | if (!*(args[cur_arg + 1])) { |
| 5406 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5407 | file, linenum, args[0], args[1], ptr_arg); |
| 5408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5409 | goto out; |
| 5410 | } |
| 5411 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5412 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5413 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5414 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5415 | free(curproxy->expect_regex); |
| 5416 | curproxy->expect_regex = NULL; |
| 5417 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5418 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5419 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5420 | error = NULL; |
| 5421 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5422 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5423 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5424 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5426 | goto out; |
| 5427 | } |
| 5428 | } |
| 5429 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5430 | if (!*(args[cur_arg + 1])) { |
| 5431 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5432 | file, linenum, args[0], args[1], ptr_arg); |
| 5433 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5434 | goto out; |
| 5435 | } |
| 5436 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5437 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5438 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5439 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5440 | free(curproxy->expect_regex); |
| 5441 | curproxy->expect_regex = NULL; |
| 5442 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5443 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5444 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5445 | error = NULL; |
| 5446 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
| 5447 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5448 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5449 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5451 | goto out; |
| 5452 | } |
| 5453 | } |
| 5454 | else { |
| 5455 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5456 | file, linenum, args[0], args[1], ptr_arg); |
| 5457 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5458 | goto out; |
| 5459 | } |
| 5460 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5461 | else { |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5462 | 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] | 5463 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5464 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5465 | } |
| 5466 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5467 | else if (!strcmp(args[0], "tcp-check")) { |
| 5468 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5469 | err_code |= ERR_WARN; |
| 5470 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5471 | if (strcmp(args[1], "comment") == 0) { |
| 5472 | int cur_arg; |
| 5473 | struct tcpcheck_rule *tcpcheck; |
| 5474 | |
| 5475 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5476 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5477 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5478 | |
| 5479 | if (!*args[cur_arg + 1]) { |
| 5480 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5481 | file, linenum, args[cur_arg]); |
| 5482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5483 | goto out; |
| 5484 | } |
| 5485 | |
| 5486 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5487 | |
| 5488 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5489 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5490 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5491 | } |
| 5492 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5493 | const char *ptr_arg; |
| 5494 | int cur_arg; |
| 5495 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5496 | |
| 5497 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5498 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5499 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5500 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5501 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5502 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5503 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5504 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5505 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
| 5506 | Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5507 | file, linenum); |
| 5508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5509 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5513 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5514 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5515 | |
| 5516 | /* parsing each parameters to fill up the rule */ |
| 5517 | while (*(ptr_arg = args[cur_arg])) { |
| 5518 | /* tcp port */ |
| 5519 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5520 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5521 | (atol(args[cur_arg + 1]) < 1) ){ |
| 5522 | Alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5523 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
| 5524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5525 | goto out; |
| 5526 | } |
| 5527 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5528 | cur_arg += 2; |
| 5529 | } |
| 5530 | /* send proxy protocol */ |
| 5531 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5532 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5533 | cur_arg++; |
| 5534 | } |
| 5535 | #ifdef USE_OPENSSL |
| 5536 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5537 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5538 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5539 | cur_arg++; |
| 5540 | } |
| 5541 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5542 | /* comment for this tcpcheck line */ |
| 5543 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5544 | if (!*args[cur_arg + 1]) { |
| 5545 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5546 | file, linenum, args[cur_arg]); |
| 5547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5548 | goto out; |
| 5549 | } |
| 5550 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5551 | cur_arg += 2; |
| 5552 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5553 | else { |
| 5554 | #ifdef USE_OPENSSL |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5555 | 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] | 5556 | #else /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5557 | 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] | 5558 | #endif /* USE_OPENSSL */ |
| 5559 | file, linenum, args[0], args[1], args[cur_arg]); |
| 5560 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5561 | goto out; |
| 5562 | } |
| 5563 | |
| 5564 | } |
| 5565 | |
| 5566 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5567 | } |
| 5568 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5569 | if (! *(args[2]) ) { |
| 5570 | /* SEND string expected */ |
| 5571 | Alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5572 | file, linenum, args[0], args[1], args[2]); |
| 5573 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5574 | goto out; |
| 5575 | } else { |
| 5576 | struct tcpcheck_rule *tcpcheck; |
| 5577 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5578 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5579 | |
| 5580 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5581 | tcpcheck->string_len = strlen(args[2]); |
| 5582 | tcpcheck->string = strdup(args[2]); |
| 5583 | tcpcheck->expect_regex = NULL; |
| 5584 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5585 | /* comment for this tcpcheck line */ |
| 5586 | if (strcmp(args[3], "comment") == 0) { |
| 5587 | if (!*args[4]) { |
| 5588 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5589 | file, linenum, args[3]); |
| 5590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5591 | goto out; |
| 5592 | } |
| 5593 | tcpcheck->comment = strdup(args[4]); |
| 5594 | } |
| 5595 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5596 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5597 | } |
| 5598 | } |
| 5599 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5600 | if (! *(args[2]) ) { |
| 5601 | /* SEND binary string expected */ |
| 5602 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5603 | file, linenum, args[0], args[1], args[2]); |
| 5604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5605 | goto out; |
| 5606 | } else { |
| 5607 | struct tcpcheck_rule *tcpcheck; |
| 5608 | char *err = NULL; |
| 5609 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5610 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5611 | |
| 5612 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5613 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5614 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5615 | file, linenum, args[0], args[1], args[2], err); |
| 5616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5617 | goto out; |
| 5618 | } |
| 5619 | tcpcheck->expect_regex = NULL; |
| 5620 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5621 | /* comment for this tcpcheck line */ |
| 5622 | if (strcmp(args[3], "comment") == 0) { |
| 5623 | if (!*args[4]) { |
| 5624 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5625 | file, linenum, args[3]); |
| 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
| 5628 | } |
| 5629 | tcpcheck->comment = strdup(args[4]); |
| 5630 | } |
| 5631 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5632 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5633 | } |
| 5634 | } |
| 5635 | else if (strcmp(args[1], "expect") == 0) { |
| 5636 | const char *ptr_arg; |
| 5637 | int cur_arg; |
| 5638 | int inverse = 0; |
| 5639 | |
| 5640 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
| 5641 | Alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
| 5642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5643 | goto out; |
| 5644 | } |
| 5645 | |
| 5646 | cur_arg = 2; |
| 5647 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5648 | while (*(ptr_arg = args[cur_arg])) { |
| 5649 | while (*ptr_arg == '!') { |
| 5650 | inverse = !inverse; |
| 5651 | ptr_arg++; |
| 5652 | } |
| 5653 | if (*ptr_arg) |
| 5654 | break; |
| 5655 | cur_arg++; |
| 5656 | } |
| 5657 | /* now ptr_arg points to the beginning of a word past any possible |
| 5658 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5659 | */ |
| 5660 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5661 | struct tcpcheck_rule *tcpcheck; |
| 5662 | char *err = NULL; |
| 5663 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5664 | if (!*(args[cur_arg + 1])) { |
| 5665 | Alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5666 | file, linenum, args[0], args[1], ptr_arg); |
| 5667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5668 | goto out; |
| 5669 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5670 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5671 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5672 | |
| 5673 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5674 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
| 5675 | Alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5676 | file, linenum, args[0], args[1], args[2], err); |
| 5677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5678 | goto out; |
| 5679 | } |
| 5680 | tcpcheck->expect_regex = NULL; |
| 5681 | tcpcheck->inverse = inverse; |
| 5682 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5683 | /* tcpcheck comment */ |
| 5684 | cur_arg += 2; |
| 5685 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5686 | if (!*args[cur_arg + 1]) { |
| 5687 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5688 | file, linenum, args[cur_arg + 1]); |
| 5689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5690 | goto out; |
| 5691 | } |
| 5692 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5693 | } |
| 5694 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5695 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5696 | } |
| 5697 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5698 | struct tcpcheck_rule *tcpcheck; |
| 5699 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5700 | if (!*(args[cur_arg + 1])) { |
| 5701 | Alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5702 | file, linenum, args[0], args[1], ptr_arg); |
| 5703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5704 | goto out; |
| 5705 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5706 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5707 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5708 | |
| 5709 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5710 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5711 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5712 | tcpcheck->expect_regex = NULL; |
| 5713 | tcpcheck->inverse = inverse; |
| 5714 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5715 | /* tcpcheck comment */ |
| 5716 | cur_arg += 2; |
| 5717 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5718 | if (!*args[cur_arg + 1]) { |
| 5719 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5720 | file, linenum, args[cur_arg + 1]); |
| 5721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5722 | goto out; |
| 5723 | } |
| 5724 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5725 | } |
| 5726 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5727 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5728 | } |
| 5729 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5730 | struct tcpcheck_rule *tcpcheck; |
| 5731 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5732 | if (!*(args[cur_arg + 1])) { |
| 5733 | Alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5734 | file, linenum, args[0], args[1], ptr_arg); |
| 5735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5736 | goto out; |
| 5737 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5738 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5739 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5740 | |
| 5741 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5742 | tcpcheck->string_len = 0; |
| 5743 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5744 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5745 | error = NULL; |
| 5746 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
| 5747 | Alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5748 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
| 5749 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5751 | goto out; |
| 5752 | } |
| 5753 | tcpcheck->inverse = inverse; |
| 5754 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5755 | /* tcpcheck comment */ |
| 5756 | cur_arg += 2; |
| 5757 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5758 | if (!*args[cur_arg + 1]) { |
| 5759 | Alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5760 | file, linenum, args[cur_arg + 1]); |
| 5761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5762 | goto out; |
| 5763 | } |
| 5764 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5765 | } |
| 5766 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5767 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5768 | } |
| 5769 | else { |
| 5770 | Alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5771 | file, linenum, args[0], args[1], ptr_arg); |
| 5772 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5773 | goto out; |
| 5774 | } |
| 5775 | } |
| 5776 | else { |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5777 | 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] | 5778 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5779 | goto out; |
| 5780 | } |
| 5781 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5782 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5783 | if (curproxy == &defproxy) { |
| 5784 | 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] | 5785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5786 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5787 | } |
| 5788 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5789 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5790 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5791 | |
| 5792 | if (strcmp(args[1], "fail") == 0) { |
| 5793 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5794 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5795 | Alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5796 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5797 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5798 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5799 | } |
| 5800 | |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 5801 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 5802 | Alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5803 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5804 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5805 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5806 | } |
| 5807 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5808 | } |
| 5809 | else { |
| 5810 | 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] | 5811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5812 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5813 | } |
| 5814 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5815 | #ifdef TPROXY |
| 5816 | else if (!strcmp(args[0], "transparent")) { |
| 5817 | /* enable transparent proxy connections */ |
| 5818 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5819 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5820 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5821 | } |
| 5822 | #endif |
| 5823 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5824 | 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] | 5825 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5826 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5827 | if (*(args[1]) == 0) { |
| 5828 | 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] | 5829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5830 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5831 | } |
| 5832 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5833 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5834 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5835 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5836 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5837 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5838 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5839 | |
| 5840 | if (*(args[1]) == 0) { |
| 5841 | 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] | 5842 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5843 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5844 | } |
| 5845 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5846 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5847 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5848 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5849 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5850 | 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] | 5851 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5852 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5853 | if (*(args[1]) == 0) { |
| 5854 | 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] | 5855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5856 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5857 | } |
| 5858 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5859 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5860 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5862 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5863 | if (*(args[1]) == 0) { |
| 5864 | 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] | 5865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5866 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5867 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5868 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5869 | if (err) { |
| 5870 | Alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5871 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5872 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5873 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5874 | } |
| 5875 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5876 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5877 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5878 | } |
| 5879 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5880 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5881 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5882 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5883 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5884 | if (curproxy == &defproxy) { |
| 5885 | 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] | 5886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5887 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5888 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5889 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5890 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5891 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 5892 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5893 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 5894 | Alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5895 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5896 | goto out; |
| 5897 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5898 | |
| 5899 | proto = protocol_by_family(sk->ss_family); |
| 5900 | if (!proto || !proto->connect) { |
| 5901 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5902 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5903 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5904 | goto out; |
| 5905 | } |
| 5906 | |
| 5907 | if (port1 != port2) { |
| 5908 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5909 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5911 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5912 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5913 | |
| 5914 | if (!port1) { |
| 5915 | Alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5916 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5918 | goto out; |
| 5919 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5920 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5921 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5922 | goto out; |
| 5923 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5924 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5925 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5926 | } |
| 5927 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5928 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5929 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5930 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5931 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 5932 | Alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5933 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5934 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5935 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5936 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5937 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5938 | /** |
| 5939 | * The syntax for hash-type config element is |
| 5940 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5941 | * |
| 5942 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5943 | */ |
| 5944 | 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] | 5945 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5946 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5947 | err_code |= ERR_WARN; |
| 5948 | |
| 5949 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5950 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 5951 | } |
| 5952 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5953 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 5954 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5955 | else if (strcmp(args[1], "avalanche") == 0) { |
| 5956 | 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]); |
| 5957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5958 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 5959 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5960 | else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5961 | 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] | 5962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5963 | goto out; |
| 5964 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5965 | |
| 5966 | /* set the hash function to use */ |
| 5967 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5968 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5969 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5970 | |
| 5971 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 5972 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 5973 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 5974 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5975 | /* set the hash function */ |
| 5976 | if (!strcmp(args[2], "sdbm")) { |
| 5977 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 5978 | } |
| 5979 | else if (!strcmp(args[2], "djb2")) { |
| 5980 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5981 | } |
| 5982 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 5983 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5984 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5985 | else if (!strcmp(args[2], "crc32")) { |
| 5986 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 5987 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5988 | else { |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 5989 | 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] | 5990 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5991 | goto out; |
| 5992 | } |
| 5993 | |
| 5994 | /* set the hash modifier */ |
| 5995 | if (!strcmp(args[3], "avalanche")) { |
| 5996 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 5997 | } |
| 5998 | else if (*args[3]) { |
| 5999 | Alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 6000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6001 | goto out; |
| 6002 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 6003 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6004 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6005 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 6006 | if (*(args[1]) == 0) { |
| 6007 | Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 6008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6009 | goto out; |
| 6010 | } |
| 6011 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 6012 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
| 6013 | Alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 6014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6015 | goto out; |
| 6016 | } |
| 6017 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6018 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 6019 | if (!*(args[1])) { |
| 6020 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6022 | goto out; |
| 6023 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6024 | if (*(args[2])) { |
| 6025 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6027 | goto out; |
| 6028 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6029 | free(curproxy->conf.uniqueid_format_string); |
| 6030 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6031 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6032 | free(curproxy->conf.uif_file); |
| 6033 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6034 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6035 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6036 | |
| 6037 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6038 | if (!*(args[1])) { |
| 6039 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6041 | goto out; |
| 6042 | } |
| 6043 | free(curproxy->header_unique_id); |
| 6044 | curproxy->header_unique_id = strdup(args[1]); |
| 6045 | } |
| 6046 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6047 | else if (strcmp(args[0], "log-format") == 0) { |
| 6048 | if (!*(args[1])) { |
| 6049 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6051 | goto out; |
| 6052 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6053 | if (*(args[2])) { |
| 6054 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6056 | goto out; |
| 6057 | } |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6058 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6059 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6060 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6061 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6062 | free(curproxy->conf.logformat_string); |
| 6063 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6064 | |
| 6065 | free(curproxy->conf.lfs_file); |
| 6066 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6067 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6068 | |
| 6069 | /* get a chance to improve log-format error reporting by |
| 6070 | * reporting the correct line-number when possible. |
| 6071 | */ |
| 6072 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6073 | Warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6074 | file, linenum, curproxy->id); |
| 6075 | err_code |= ERR_WARN; |
| 6076 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6077 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6078 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6079 | if (!*(args[1])) { |
| 6080 | Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 6081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6082 | goto out; |
| 6083 | } |
| 6084 | if (*(args[2])) { |
| 6085 | Alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 6086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6087 | goto out; |
| 6088 | } |
| 6089 | |
| 6090 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6091 | free(curproxy->conf.logformat_sd_string); |
| 6092 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6093 | |
| 6094 | free(curproxy->conf.lfsd_file); |
| 6095 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6096 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6097 | |
| 6098 | /* get a chance to improve log-format-sd error reporting by |
| 6099 | * reporting the correct line-number when possible. |
| 6100 | */ |
| 6101 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 6102 | Warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6103 | file, linenum, curproxy->id); |
| 6104 | err_code |= ERR_WARN; |
| 6105 | } |
| 6106 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6107 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6108 | if (*(args[1]) == 0) { |
| 6109 | Alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 6110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6111 | goto out; |
| 6112 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6113 | chunk_destroy(&curproxy->log_tag); |
| 6114 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6115 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6116 | else if (!strcmp(args[0], "log") && kwm == KWM_NO) { |
| 6117 | /* delete previous herited or defined syslog servers */ |
| 6118 | struct logsrv *back; |
| 6119 | |
| 6120 | if (*(args[1]) != 0) { |
| 6121 | Alert("parsing [%s:%d]:%s : 'no log' does not expect arguments.\n", file, linenum, args[1]); |
| 6122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6123 | goto out; |
| 6124 | } |
| 6125 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6126 | list_for_each_entry_safe(tmplogsrv, back, &curproxy->logsrvs, list) { |
| 6127 | LIST_DEL(&tmplogsrv->list); |
| 6128 | free(tmplogsrv); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6129 | } |
| 6130 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6131 | else if (!strcmp(args[0], "log")) { /* syslog server address */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6132 | struct logsrv *logsrv; |
| 6133 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6134 | if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6135 | /* copy global.logrsvs linked list to the end of curproxy->logsrvs */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6136 | list_for_each_entry(tmplogsrv, &global.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6137 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6138 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6139 | LIST_INIT(&node->list); |
| 6140 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 6141 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6142 | } |
| 6143 | else if (*(args[1]) && *(args[2])) { |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6144 | struct sockaddr_storage *sk; |
| 6145 | int port1, port2; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6146 | int arg = 0; |
| 6147 | int len = 0; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6148 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6149 | logsrv = calloc(1, sizeof(*logsrv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6150 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6151 | /* just after the address, a length may be specified */ |
| 6152 | if (strcmp(args[arg+2], "len") == 0) { |
| 6153 | len = atoi(args[arg+3]); |
| 6154 | if (len < 80 || len > 65535) { |
| 6155 | Alert("parsing [%s:%d] : invalid log length '%s', must be between 80 and 65535.\n", |
| 6156 | file, linenum, args[arg+3]); |
| 6157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6158 | goto out; |
| 6159 | } |
| 6160 | logsrv->maxlen = len; |
| 6161 | |
| 6162 | /* skip these two args */ |
| 6163 | arg += 2; |
| 6164 | } |
| 6165 | else |
| 6166 | logsrv->maxlen = MAX_SYSLOG_LEN; |
| 6167 | |
| 6168 | if (logsrv->maxlen > global.max_syslog_len) { |
| 6169 | global.max_syslog_len = logsrv->maxlen; |
Hubert Verstraete | 831962e | 2016-06-28 22:44:26 +0200 | [diff] [blame] | 6170 | logheader = my_realloc2(logheader, global.max_syslog_len + 1); |
| 6171 | logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1); |
| 6172 | logline = my_realloc2(logline, global.max_syslog_len + 1); |
| 6173 | logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1); |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6174 | } |
| 6175 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 6176 | /* after the length, a format may be specified */ |
| 6177 | if (strcmp(args[arg+2], "format") == 0) { |
| 6178 | logsrv->format = get_log_format(args[arg+3]); |
| 6179 | if (logsrv->format < 0) { |
| 6180 | Alert("parsing [%s:%d] : unknown log format '%s'\n", file, linenum, args[arg+3]); |
| 6181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6182 | goto out; |
| 6183 | } |
| 6184 | |
| 6185 | /* skip these two args */ |
| 6186 | arg += 2; |
| 6187 | } |
| 6188 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 6189 | if (alertif_too_many_args_idx(3, arg + 1, file, linenum, args, &err_code)) |
| 6190 | goto out; |
| 6191 | |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6192 | logsrv->facility = get_log_facility(args[arg+2]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6193 | if (logsrv->facility < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6194 | 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] | 6195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6196 | goto out; |
| 6197 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6198 | } |
| 6199 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6200 | logsrv->level = 7; /* max syslog level = debug */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6201 | if (*(args[arg+3])) { |
| 6202 | logsrv->level = get_log_level(args[arg+3]); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6203 | if (logsrv->level < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6204 | 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] | 6205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6206 | goto out; |
| 6207 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6208 | } |
| 6209 | } |
| 6210 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6211 | logsrv->minlvl = 0; /* limit syslog level to this level (emerg) */ |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6212 | if (*(args[arg+4])) { |
| 6213 | logsrv->minlvl = get_log_level(args[arg+4]); |
Willy Tarreau | f7f057b | 2013-01-24 00:31:24 +0100 | [diff] [blame] | 6214 | if (logsrv->minlvl < 0) { |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 6215 | 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] | 6216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6217 | goto out; |
| 6218 | |
Willy Tarreau | f7edefa | 2009-05-10 17:20:05 +0200 | [diff] [blame] | 6219 | } |
| 6220 | } |
| 6221 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6222 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6223 | if (!sk) { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6224 | Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6225 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6226 | goto out; |
| 6227 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6228 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6229 | logsrv->addr = *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6230 | |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 6231 | if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6232 | if (port1 != port2) { |
| 6233 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6234 | file, linenum, args[0], args[1]); |
| 6235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6236 | goto out; |
| 6237 | } |
| 6238 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6239 | if (!port1) |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6240 | set_host_port(&logsrv->addr, SYSLOG_PORT); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6241 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 6242 | |
| 6243 | LIST_ADDQ(&curproxy->logsrvs, &logsrv->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6244 | } |
| 6245 | else { |
| 6246 | Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n", |
| 6247 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6249 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6250 | } |
| 6251 | } |
| 6252 | 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] | 6253 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6254 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6255 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6256 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6257 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6258 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6259 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6260 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6261 | if (!*args[1]) { |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6262 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6263 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6265 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6266 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6267 | |
| 6268 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6269 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6270 | free(curproxy->conn_src.iface_name); |
| 6271 | curproxy->conn_src.iface_name = NULL; |
| 6272 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6273 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6274 | sk = str2sa_range(args[1], &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6275 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6276 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6277 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6278 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6279 | goto out; |
| 6280 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6281 | |
| 6282 | proto = protocol_by_family(sk->ss_family); |
| 6283 | if (!proto || !proto->connect) { |
| 6284 | 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] | 6285 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6287 | goto out; |
| 6288 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6289 | |
| 6290 | if (port1 != port2) { |
| 6291 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6292 | file, linenum, args[0], args[1]); |
| 6293 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6294 | goto out; |
| 6295 | } |
| 6296 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6297 | curproxy->conn_src.source_addr = *sk; |
| 6298 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6299 | |
| 6300 | cur_arg = 2; |
| 6301 | while (*(args[cur_arg])) { |
| 6302 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6303 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6304 | if (!*args[cur_arg + 1]) { |
| 6305 | Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6306 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6308 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6312 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6313 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6314 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6315 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6316 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6317 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6318 | char *name, *end; |
| 6319 | |
| 6320 | name = args[cur_arg+1] + 7; |
| 6321 | while (isspace(*name)) |
| 6322 | name++; |
| 6323 | |
| 6324 | end = name; |
| 6325 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6326 | end++; |
| 6327 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6328 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6329 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6330 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6331 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6332 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6333 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6334 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6335 | |
| 6336 | /* now look for an occurrence number */ |
| 6337 | while (isspace(*end)) |
| 6338 | end++; |
| 6339 | if (*end == ',') { |
| 6340 | end++; |
| 6341 | name = end; |
| 6342 | if (*end == '-') |
| 6343 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6344 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6345 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6346 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6347 | } |
| 6348 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6349 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6350 | Alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6351 | " occurrences values smaller than %d.\n", |
| 6352 | file, linenum, MAX_HDR_HISTORY); |
| 6353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6354 | goto out; |
| 6355 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6356 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6357 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6358 | |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 6359 | 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] | 6360 | if (!sk) { |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6361 | Alert("parsing [%s:%d] : '%s %s' : %s\n", |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6362 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6363 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6364 | goto out; |
| 6365 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6366 | |
| 6367 | proto = protocol_by_family(sk->ss_family); |
| 6368 | if (!proto || !proto->connect) { |
| 6369 | Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6370 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6371 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6372 | goto out; |
| 6373 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6374 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6375 | if (port1 != port2) { |
| 6376 | Alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6377 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6379 | goto out; |
| 6380 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6381 | curproxy->conn_src.tproxy_addr = *sk; |
| 6382 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6383 | } |
| 6384 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6385 | #else /* no TPROXY support */ |
| 6386 | 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] | 6387 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6389 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6390 | #endif |
| 6391 | cur_arg += 2; |
| 6392 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6393 | } |
| 6394 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6395 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6396 | #ifdef SO_BINDTODEVICE |
| 6397 | if (!*args[cur_arg + 1]) { |
| 6398 | Alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6399 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6400 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6401 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6402 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6403 | free(curproxy->conn_src.iface_name); |
| 6404 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6405 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6406 | global.last_checks |= LSTCHK_NETADM; |
| 6407 | #else |
| 6408 | Alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6409 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6411 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6412 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6413 | cur_arg += 2; |
| 6414 | continue; |
| 6415 | } |
| 6416 | 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] | 6417 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6418 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6419 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6420 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6421 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6422 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
| 6423 | Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6424 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6426 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6427 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6428 | 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] | 6429 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6430 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6431 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6433 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6434 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6435 | |
| 6436 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6437 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6438 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6439 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6440 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6441 | } |
| 6442 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6443 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6444 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6445 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6446 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6447 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6448 | } |
| 6449 | 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] | 6450 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6451 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6452 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6453 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6454 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6455 | } |
| 6456 | 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] | 6457 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6458 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6459 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6460 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6461 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6462 | } |
| 6463 | 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] | 6464 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6465 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6466 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6467 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6469 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6470 | 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] | 6471 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6472 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6473 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6474 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6475 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6476 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6477 | 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] | 6478 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6479 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6480 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6482 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6483 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6484 | |
| 6485 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6486 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6487 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6488 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6489 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6490 | } |
| 6491 | 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] | 6492 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6493 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6494 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6495 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6496 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6497 | } |
| 6498 | else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6499 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6500 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6501 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6502 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6503 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6504 | } |
| 6505 | else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6506 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6507 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6508 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6509 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6510 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6511 | } |
| 6512 | else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6513 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6514 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6515 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6516 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6517 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6518 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6519 | 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] | 6520 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6521 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6522 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6523 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6524 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6525 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6526 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6527 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6528 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6529 | if (curproxy == &defproxy) { |
| 6530 | 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] | 6531 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6532 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6533 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6534 | 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] | 6535 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6536 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6537 | if (*(args[1]) == 0) { |
| 6538 | 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] | 6539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6540 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6541 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6542 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6543 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6544 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6545 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6546 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6547 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6548 | goto out; |
| 6549 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6550 | err_code |= warnif_cond_conflicts(cond, |
| 6551 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6552 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6553 | } |
| 6554 | else if (*args[2]) { |
| 6555 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6556 | file, linenum, args[0], args[2]); |
| 6557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6558 | goto out; |
| 6559 | } |
| 6560 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6561 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6562 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6563 | wl->s = strdup(args[1]); |
| 6564 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6565 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6566 | } |
| 6567 | 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] | 6568 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6569 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6570 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6571 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6572 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6573 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6574 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6575 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6576 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6577 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6578 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6579 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6580 | } |
| 6581 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6582 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6583 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6584 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6585 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6586 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6587 | } |
| 6588 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6589 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6590 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6591 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6592 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6593 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6594 | } |
| 6595 | 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] | 6596 | if (*(args[2]) == 0) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6597 | Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6598 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6600 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6601 | } |
| 6602 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6603 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6604 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6605 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6606 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6607 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6608 | } |
| 6609 | 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] | 6610 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6611 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6612 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6613 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6614 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6615 | } |
| 6616 | 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] | 6617 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6618 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6619 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6620 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6621 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6622 | } |
| 6623 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6624 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6625 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6626 | if (curproxy == &defproxy) { |
| 6627 | 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] | 6628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6629 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6630 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6631 | 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] | 6632 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6633 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6634 | if (*(args[1]) == 0) { |
| 6635 | 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] | 6636 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6637 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6638 | } |
| 6639 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6640 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 6641 | if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
| 6642 | Alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6643 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6645 | goto out; |
| 6646 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6647 | err_code |= warnif_cond_conflicts(cond, |
| 6648 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6649 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6650 | } |
| 6651 | else if (*args[2]) { |
| 6652 | Alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6653 | file, linenum, args[0], args[2]); |
| 6654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6655 | goto out; |
| 6656 | } |
| 6657 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6658 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6659 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6660 | wl->s = strdup(args[1]); |
| 6661 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6662 | } |
| 6663 | else if (!strcmp(args[0], "errorloc") || |
| 6664 | !strcmp(args[0], "errorloc302") || |
| 6665 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6666 | int errnum, errlen; |
| 6667 | char *err; |
| 6668 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6669 | 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] | 6670 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6671 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6672 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6673 | 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] | 6674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6675 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6676 | } |
| 6677 | |
| 6678 | errnum = atol(args[1]); |
| 6679 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6680 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6681 | err = malloc(errlen); |
| 6682 | 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] | 6683 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6684 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6685 | err = malloc(errlen); |
| 6686 | 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] | 6687 | } |
| 6688 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6689 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6690 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6691 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6692 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6693 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6694 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6695 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6696 | |
| 6697 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6698 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6699 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6700 | free(err); |
| 6701 | } |
| 6702 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6703 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6704 | int errnum, errlen, fd; |
| 6705 | char *err; |
| 6706 | struct stat stat; |
| 6707 | |
| 6708 | 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] | 6709 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6710 | |
| 6711 | if (*(args[2]) == 0) { |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6712 | 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] | 6713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6714 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | fd = open(args[2], O_RDONLY); |
| 6718 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
| 6719 | Alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6720 | file, linenum, args[2], args[1]); |
| 6721 | if (fd >= 0) |
| 6722 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6724 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6725 | } |
| 6726 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6727 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6728 | errlen = stat.st_size; |
| 6729 | } else { |
| 6730 | 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] | 6731 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6732 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6733 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6737 | errnum = read(fd, err, errlen); |
| 6738 | if (errnum != errlen) { |
| 6739 | Alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6740 | file, linenum, args[2], args[1]); |
| 6741 | close(fd); |
| 6742 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6744 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6745 | } |
| 6746 | close(fd); |
| 6747 | |
| 6748 | errnum = atol(args[1]); |
| 6749 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6750 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6751 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6752 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6753 | break; |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | if (rc >= HTTP_ERR_SIZE) { |
Willy Tarreau | bb3c09a | 2015-09-27 15:13:30 +0200 | [diff] [blame] | 6758 | Warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6759 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6760 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6761 | free(err); |
| 6762 | } |
| 6763 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6764 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6765 | struct cfg_kw_list *kwl; |
| 6766 | int index; |
| 6767 | |
| 6768 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6769 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6770 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6771 | continue; |
| 6772 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6773 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6774 | 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] | 6775 | if (rc < 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6776 | Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6778 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6779 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6780 | else if (rc > 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 6781 | Warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6782 | err_code |= ERR_WARN; |
| 6783 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6784 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6785 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6786 | } |
| 6787 | } |
| 6788 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6789 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 6790 | 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] | 6791 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6792 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6793 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6794 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6795 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6796 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6797 | } |
| 6798 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6799 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6800 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6801 | { |
| 6802 | #ifdef CONFIG_HAP_NS |
| 6803 | const char *err; |
| 6804 | const char *item = args[0]; |
| 6805 | |
| 6806 | if (!strcmp(item, "namespace_list")) { |
| 6807 | return 0; |
| 6808 | } |
| 6809 | else if (!strcmp(item, "namespace")) { |
| 6810 | size_t idx = 1; |
| 6811 | const char *current; |
| 6812 | while (*(current = args[idx++])) { |
| 6813 | err = invalid_char(current); |
| 6814 | if (err) { |
| 6815 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6816 | file, linenum, *err, item, current); |
| 6817 | return ERR_ALERT | ERR_FATAL; |
| 6818 | } |
| 6819 | |
| 6820 | if (netns_store_lookup(current, strlen(current))) { |
| 6821 | Alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6822 | file, linenum, current); |
| 6823 | return ERR_ALERT | ERR_FATAL; |
| 6824 | } |
| 6825 | if (!netns_store_insert(current)) { |
| 6826 | Alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6827 | file, linenum, current); |
| 6828 | return ERR_ALERT | ERR_FATAL; |
| 6829 | } |
| 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | return 0; |
| 6834 | #else |
| 6835 | Alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6836 | file, linenum); |
| 6837 | return ERR_ALERT | ERR_FATAL; |
| 6838 | #endif |
| 6839 | } |
| 6840 | |
| 6841 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6842 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6843 | { |
| 6844 | |
| 6845 | int err_code = 0; |
| 6846 | const char *err; |
| 6847 | |
| 6848 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6849 | struct userlist *newul; |
| 6850 | |
| 6851 | if (!*args[1]) { |
| 6852 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6853 | file, linenum, args[0]); |
| 6854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6855 | goto out; |
| 6856 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6857 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6858 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6859 | |
| 6860 | err = invalid_char(args[1]); |
| 6861 | if (err) { |
| 6862 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6863 | file, linenum, *err, args[0], args[1]); |
| 6864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6865 | goto out; |
| 6866 | } |
| 6867 | |
| 6868 | for (newul = userlist; newul; newul = newul->next) |
| 6869 | if (!strcmp(newul->name, args[1])) { |
| 6870 | Warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6871 | file, linenum, args[1]); |
| 6872 | err_code |= ERR_WARN; |
| 6873 | goto out; |
| 6874 | } |
| 6875 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6876 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6877 | if (!newul) { |
| 6878 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6879 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6880 | goto out; |
| 6881 | } |
| 6882 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6883 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6884 | if (!newul->name) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6885 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6886 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6887 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6888 | goto out; |
| 6889 | } |
| 6890 | |
| 6891 | newul->next = userlist; |
| 6892 | userlist = newul; |
| 6893 | |
| 6894 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6895 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6896 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6897 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6898 | |
| 6899 | if (!*args[1]) { |
| 6900 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6901 | file, linenum, args[0]); |
| 6902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6903 | goto out; |
| 6904 | } |
| 6905 | |
| 6906 | err = invalid_char(args[1]); |
| 6907 | if (err) { |
| 6908 | Alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6909 | file, linenum, *err, args[0], args[1]); |
| 6910 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6911 | goto out; |
| 6912 | } |
| 6913 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6914 | if (!userlist) |
| 6915 | goto out; |
| 6916 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6917 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6918 | if (!strcmp(ag->name, args[1])) { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6919 | Warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6920 | file, linenum, args[1], userlist->name); |
| 6921 | err_code |= ERR_ALERT; |
| 6922 | goto out; |
| 6923 | } |
| 6924 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6925 | ag = calloc(1, sizeof(*ag)); |
| 6926 | if (!ag) { |
| 6927 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6928 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6929 | goto out; |
| 6930 | } |
| 6931 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6932 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6933 | if (!ag->name) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6934 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6935 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6936 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6937 | goto out; |
| 6938 | } |
| 6939 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6940 | cur_arg = 2; |
| 6941 | |
| 6942 | while (*args[cur_arg]) { |
| 6943 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6944 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6945 | cur_arg += 2; |
| 6946 | continue; |
| 6947 | } else { |
| 6948 | Alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6949 | file, linenum, args[0]); |
| 6950 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6951 | free(ag->groupusers); |
| 6952 | free(ag->name); |
| 6953 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6954 | goto out; |
| 6955 | } |
| 6956 | } |
| 6957 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6958 | ag->next = userlist->groups; |
| 6959 | userlist->groups = ag; |
| 6960 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6961 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6962 | struct auth_users *newuser; |
| 6963 | int cur_arg; |
| 6964 | |
| 6965 | if (!*args[1]) { |
| 6966 | Alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6967 | file, linenum, args[0]); |
| 6968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6969 | goto out; |
| 6970 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6971 | if (!userlist) |
| 6972 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6973 | |
| 6974 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6975 | if (!strcmp(newuser->user, args[1])) { |
| 6976 | Warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6977 | file, linenum, args[1], userlist->name); |
| 6978 | err_code |= ERR_ALERT; |
| 6979 | goto out; |
| 6980 | } |
| 6981 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6982 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6983 | if (!newuser) { |
| 6984 | Alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 6985 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6986 | goto out; |
| 6987 | } |
| 6988 | |
| 6989 | newuser->user = strdup(args[1]); |
| 6990 | |
| 6991 | newuser->next = userlist->users; |
| 6992 | userlist->users = newuser; |
| 6993 | |
| 6994 | cur_arg = 2; |
| 6995 | |
| 6996 | while (*args[cur_arg]) { |
| 6997 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6998 | #ifdef CONFIG_HAP_CRYPT |
| 6999 | if (!crypt("", args[cur_arg + 1])) { |
| 7000 | Alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 7001 | file, linenum, newuser->user); |
| 7002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7003 | goto out; |
| 7004 | } |
| 7005 | #else |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7006 | Warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 7007 | file, linenum); |
| 7008 | err_code |= ERR_ALERT; |
| 7009 | #endif |
| 7010 | newuser->pass = strdup(args[cur_arg + 1]); |
| 7011 | cur_arg += 2; |
| 7012 | continue; |
| 7013 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 7014 | newuser->pass = strdup(args[cur_arg + 1]); |
| 7015 | newuser->flags |= AU_O_INSECURE; |
| 7016 | cur_arg += 2; |
| 7017 | continue; |
| 7018 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7019 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7020 | cur_arg += 2; |
| 7021 | continue; |
| 7022 | } else { |
| 7023 | Alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 7024 | file, linenum, args[0]); |
| 7025 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7026 | goto out; |
| 7027 | } |
| 7028 | } |
| 7029 | } else { |
| 7030 | Alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
| 7031 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7032 | } |
| 7033 | |
| 7034 | out: |
| 7035 | return err_code; |
| 7036 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7037 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7038 | int |
| 7039 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 7040 | { |
| 7041 | char *beg, *end, *scope = NULL; |
| 7042 | int err_code = 0; |
| 7043 | const char *err; |
| 7044 | |
| 7045 | beg = line + 1; |
| 7046 | end = strchr(beg, ']'); |
| 7047 | |
| 7048 | /* Detect end of scope declaration */ |
| 7049 | if (!end || end == beg) { |
| 7050 | Alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 7051 | file, linenum); |
| 7052 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7053 | goto out; |
| 7054 | } |
| 7055 | |
| 7056 | /* Get scope name and check its validity */ |
| 7057 | scope = my_strndup(beg, end-beg); |
| 7058 | err = invalid_char(scope); |
| 7059 | if (err) { |
| 7060 | Alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 7061 | file, linenum, *err); |
| 7062 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7063 | goto out; |
| 7064 | } |
| 7065 | |
| 7066 | /* Be sure to have a scope declaration alone on its line */ |
| 7067 | line = end+1; |
| 7068 | while (isspace((unsigned char)*line)) |
| 7069 | line++; |
| 7070 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
| 7071 | Alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 7072 | file, linenum, *line); |
| 7073 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7074 | goto out; |
| 7075 | } |
| 7076 | |
| 7077 | /* We have a valid scope declaration, save it */ |
| 7078 | free(cfg_scope); |
| 7079 | cfg_scope = scope; |
| 7080 | scope = NULL; |
| 7081 | |
| 7082 | out: |
| 7083 | free(scope); |
| 7084 | return err_code; |
| 7085 | } |
| 7086 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7087 | /* |
| 7088 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7089 | * Returns the error code, 0 if OK, or any combination of : |
| 7090 | * - ERR_ABORT: must abort ASAP |
| 7091 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7092 | * - ERR_WARN: a warning has been emitted |
| 7093 | * - ERR_ALERT: an alert has been emitted |
| 7094 | * Only the two first ones can stop processing, the two others are just |
| 7095 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7096 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7097 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7098 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7099 | char *thisline; |
| 7100 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7101 | FILE *f; |
| 7102 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7103 | int err_code = 0; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7104 | struct cfg_section *cs = NULL; |
| 7105 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7106 | int readbytes = 0; |
| 7107 | |
| 7108 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7109 | Alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7110 | return -1; |
| 7111 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7112 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7113 | if ((f=fopen(file,"r")) == NULL) { |
| 7114 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7115 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7116 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7117 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7118 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7119 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7120 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7121 | char *end; |
| 7122 | char *args[MAX_LINE_ARGS + 1]; |
| 7123 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7124 | int dquote = 0; /* double quote */ |
| 7125 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7126 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7127 | linenum++; |
| 7128 | |
| 7129 | end = line + strlen(line); |
| 7130 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7131 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7132 | /* Check if we reached the limit and the last char is not \n. |
| 7133 | * Watch out for the last line without the terminating '\n'! |
| 7134 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7135 | char *newline; |
| 7136 | int newlinesize = linesize * 2; |
| 7137 | |
| 7138 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7139 | if (newline == NULL) { |
| 7140 | Alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7141 | file, linenum); |
| 7142 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7143 | continue; |
| 7144 | } |
| 7145 | |
| 7146 | readbytes = linesize - 1; |
| 7147 | linesize = newlinesize; |
| 7148 | thisline = newline; |
| 7149 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7150 | } |
| 7151 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7152 | readbytes = 0; |
| 7153 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7154 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7155 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7156 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7157 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7158 | |
| 7159 | if (*line == '[') {/* This is the begining if a scope */ |
| 7160 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7161 | goto next_line; |
| 7162 | } |
| 7163 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7164 | arg = 0; |
| 7165 | args[arg] = line; |
| 7166 | |
| 7167 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7168 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7169 | if (dquote) |
| 7170 | dquote = 0; |
| 7171 | else |
| 7172 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7173 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7174 | end--; |
| 7175 | } |
| 7176 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7177 | if (squote) |
| 7178 | squote = 0; |
| 7179 | else |
| 7180 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7181 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7182 | end--; |
| 7183 | } |
| 7184 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7185 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7186 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7187 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7188 | int skip = 0; |
| 7189 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7190 | *line = line[1]; |
| 7191 | skip = 1; |
| 7192 | } |
| 7193 | else if (line[1] == 'r') { |
| 7194 | *line = '\r'; |
| 7195 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7196 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7197 | else if (line[1] == 'n') { |
| 7198 | *line = '\n'; |
| 7199 | skip = 1; |
| 7200 | } |
| 7201 | else if (line[1] == 't') { |
| 7202 | *line = '\t'; |
| 7203 | skip = 1; |
| 7204 | } |
| 7205 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7206 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7207 | unsigned char hex1, hex2; |
| 7208 | hex1 = toupper(line[2]) - '0'; |
| 7209 | hex2 = toupper(line[3]) - '0'; |
| 7210 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7211 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7212 | *line = (hex1<<4) + hex2; |
| 7213 | skip = 3; |
| 7214 | } |
| 7215 | else { |
| 7216 | 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] | 7217 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7218 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7219 | } else if (line[1] == '"') { |
| 7220 | *line = '"'; |
| 7221 | skip = 1; |
| 7222 | } else if (line[1] == '\'') { |
| 7223 | *line = '\''; |
| 7224 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7225 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7226 | *line = '$'; |
| 7227 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7228 | } |
| 7229 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7230 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7231 | end -= skip; |
| 7232 | } |
| 7233 | line++; |
| 7234 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7235 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7236 | /* end of string, end of loop */ |
| 7237 | *line = 0; |
| 7238 | break; |
| 7239 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7240 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7241 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7242 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7243 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7244 | line++; |
| 7245 | args[++arg] = line; |
| 7246 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7247 | else if (dquote && *line == '$') { |
| 7248 | /* environment variables are evaluated inside double quotes */ |
| 7249 | char *var_beg; |
| 7250 | char *var_end; |
| 7251 | char save_char; |
| 7252 | char *value; |
| 7253 | int val_len; |
| 7254 | int newlinesize; |
| 7255 | int braces = 0; |
| 7256 | |
| 7257 | var_beg = line + 1; |
| 7258 | var_end = var_beg; |
| 7259 | |
| 7260 | if (*var_beg == '{') { |
| 7261 | var_beg++; |
| 7262 | var_end++; |
| 7263 | braces = 1; |
| 7264 | } |
| 7265 | |
| 7266 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
| 7267 | Alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
| 7268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7269 | goto next_line; /* skip current line */ |
| 7270 | } |
| 7271 | |
| 7272 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7273 | var_end++; |
| 7274 | |
| 7275 | save_char = *var_end; |
| 7276 | *var_end = '\0'; |
| 7277 | value = getenv(var_beg); |
| 7278 | *var_end = save_char; |
| 7279 | val_len = value ? strlen(value) : 0; |
| 7280 | |
| 7281 | if (braces) { |
| 7282 | if (*var_end == '}') { |
| 7283 | var_end++; |
| 7284 | braces = 0; |
| 7285 | } else { |
| 7286 | Alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
| 7287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7288 | goto next_line; /* skip current line */ |
| 7289 | } |
| 7290 | } |
| 7291 | |
| 7292 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7293 | |
| 7294 | /* if not enough space in thisline */ |
| 7295 | if (newlinesize > linesize) { |
| 7296 | char *newline; |
| 7297 | |
| 7298 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7299 | if (newline == NULL) { |
| 7300 | Alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
| 7301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7302 | goto next_line; /* slip current line */ |
| 7303 | } |
| 7304 | /* recompute pointers if realloc returns a new pointer */ |
| 7305 | if (newline != thisline) { |
| 7306 | int i; |
| 7307 | int diff; |
| 7308 | |
| 7309 | for (i = 0; i <= arg; i++) { |
| 7310 | diff = args[i] - thisline; |
| 7311 | args[i] = newline + diff; |
| 7312 | } |
| 7313 | |
| 7314 | diff = var_end - thisline; |
| 7315 | var_end = newline + diff; |
| 7316 | diff = end - thisline; |
| 7317 | end = newline + diff; |
| 7318 | diff = line - thisline; |
| 7319 | line = newline + diff; |
| 7320 | thisline = newline; |
| 7321 | } |
| 7322 | linesize = newlinesize; |
| 7323 | } |
| 7324 | |
| 7325 | /* insert value inside the line */ |
| 7326 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7327 | memcpy(line, value, val_len); |
| 7328 | end += val_len - (var_end - line); |
| 7329 | line += val_len; |
| 7330 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7331 | else { |
| 7332 | line++; |
| 7333 | } |
| 7334 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7335 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7336 | if (dquote) { |
| 7337 | Alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
| 7338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7339 | } |
| 7340 | |
| 7341 | if (squote) { |
| 7342 | Alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
| 7343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7344 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7345 | |
| 7346 | /* empty line */ |
| 7347 | if (!**args) |
| 7348 | continue; |
| 7349 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7350 | if (*line) { |
| 7351 | /* we had to stop due to too many args. |
| 7352 | * Let's terminate the string, print the offending part then cut the |
| 7353 | * last arg. |
| 7354 | */ |
| 7355 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7356 | line++; |
| 7357 | *line = '\0'; |
| 7358 | |
Krzysztof Piotr Oledzki | 500b8f0 | 2009-12-15 22:34:51 +0100 | [diff] [blame] | 7359 | 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] | 7360 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7362 | args[arg] = line; |
| 7363 | } |
| 7364 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7365 | /* zero out remaining args and ensure that at least one entry |
| 7366 | * is zeroed out. |
| 7367 | */ |
| 7368 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7369 | args[arg] = line; |
| 7370 | } |
| 7371 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7372 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7373 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7374 | char *tmp; |
| 7375 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7376 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7377 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7378 | for (arg=0; *args[arg+1]; arg++) |
| 7379 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7380 | *tmp = '\0'; // fix the next arg to \0 |
| 7381 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7382 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7383 | else if (!strcmp(args[0], "default")) { |
| 7384 | kwm = KWM_DEF; |
| 7385 | for (arg=0; *args[arg+1]; arg++) |
| 7386 | args[arg] = args[arg+1]; // shift args after inversion |
| 7387 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7388 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7389 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7390 | strcmp(args[0], "log") != 0) { |
| 7391 | 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] | 7392 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7393 | } |
| 7394 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7395 | /* detect section start */ |
| 7396 | list_for_each_entry(ics, §ions, list) { |
| 7397 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7398 | cursection = ics->section_name; |
| 7399 | cs = ics; |
| 7400 | break; |
| 7401 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7402 | } |
| 7403 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7404 | /* else it's a section keyword */ |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7405 | if (cs) |
| 7406 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7407 | else { |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 7408 | 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] | 7409 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7410 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7411 | |
| 7412 | if (err_code & ERR_ABORT) |
| 7413 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7414 | } |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7415 | free(cfg_scope); |
| 7416 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7417 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7418 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7419 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7420 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7421 | } |
| 7422 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7423 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7424 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7425 | * bound to all of its processes. After that, if the target is a "listen" |
| 7426 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7427 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7428 | * checked first to ensure that <to> is already bound to all processes of |
| 7429 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7430 | * path to the destination. |
| 7431 | * |
| 7432 | * It is possible to set <to> to NULL for the first call so that the function |
| 7433 | * takes care of visiting the initial frontend in <from>. |
| 7434 | * |
| 7435 | * It is important to note that the function relies on the fact that all names |
| 7436 | * have already been resolved. |
| 7437 | */ |
| 7438 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7439 | { |
| 7440 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7441 | |
| 7442 | if (to) { |
| 7443 | /* check whether we need to go down */ |
| 7444 | if (from->bind_proc && |
| 7445 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7446 | return; |
| 7447 | |
| 7448 | if (!from->bind_proc && !to->bind_proc) |
| 7449 | return; |
| 7450 | |
| 7451 | to->bind_proc = from->bind_proc ? |
| 7452 | (to->bind_proc | from->bind_proc) : 0; |
| 7453 | |
| 7454 | /* now propagate down */ |
| 7455 | from = to; |
| 7456 | } |
| 7457 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7458 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7459 | return; |
| 7460 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7461 | if (from->state == PR_STSTOPPED) |
| 7462 | return; |
| 7463 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7464 | /* default_backend */ |
| 7465 | if (from->defbe.be) |
| 7466 | propagate_processes(from, from->defbe.be); |
| 7467 | |
| 7468 | /* use_backend */ |
| 7469 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7470 | if (rule->dynamic) |
| 7471 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7472 | to = rule->be.backend; |
| 7473 | propagate_processes(from, to); |
| 7474 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7475 | } |
| 7476 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7477 | /* |
| 7478 | * Returns the error code, 0 if OK, or any combination of : |
| 7479 | * - ERR_ABORT: must abort ASAP |
| 7480 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7481 | * - ERR_WARN: a warning has been emitted |
| 7482 | * - ERR_ALERT: an alert has been emitted |
| 7483 | * Only the two first ones can stop processing, the two others are just |
| 7484 | * indicators. |
| 7485 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7486 | int check_config_validity() |
| 7487 | { |
| 7488 | int cfgerr = 0; |
| 7489 | struct proxy *curproxy = NULL; |
| 7490 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7491 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7492 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7493 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7494 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7495 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7496 | /* |
| 7497 | * Now, check for the integrity of all that we have collected. |
| 7498 | */ |
| 7499 | |
| 7500 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7501 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7502 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7503 | if (!global.tune.max_http_hdr) |
| 7504 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7505 | |
| 7506 | if (!global.tune.cookie_len) |
| 7507 | global.tune.cookie_len = CAPTURE_LEN; |
| 7508 | |
| 7509 | pool2_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
| 7510 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7511 | /* Post initialisation of the users and groups lists. */ |
| 7512 | err_code = userlist_postinit(); |
| 7513 | if (err_code != ERR_NONE) |
| 7514 | goto out; |
| 7515 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7516 | /* first, we will invert the proxy list order */ |
| 7517 | curproxy = NULL; |
| 7518 | while (proxy) { |
| 7519 | struct proxy *next; |
| 7520 | |
| 7521 | next = proxy->next; |
| 7522 | proxy->next = curproxy; |
| 7523 | curproxy = proxy; |
| 7524 | if (!next) |
| 7525 | break; |
| 7526 | proxy = next; |
| 7527 | } |
| 7528 | |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 7529 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7530 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7531 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7532 | struct sticking_rule *mrule; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 7533 | struct act_rule *trule; |
| 7534 | struct act_rule *hrqrule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7535 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7536 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7537 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7538 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7539 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7540 | /* proxy ID not set, use automatic numbering with first |
| 7541 | * spare entry starting with next_pxid. |
| 7542 | */ |
| 7543 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7544 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7545 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7546 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7547 | next_pxid++; |
| 7548 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7549 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7550 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7551 | /* ensure we don't keep listeners uselessly bound */ |
| 7552 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7553 | free((void *)curproxy->table.peers.name); |
| 7554 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7555 | continue; |
| 7556 | } |
| 7557 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7558 | /* Check multi-process mode compatibility for the current proxy */ |
| 7559 | |
| 7560 | if (curproxy->bind_proc) { |
| 7561 | /* an explicit bind-process was specified, let's check how many |
| 7562 | * processes remain. |
| 7563 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7564 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7565 | |
| 7566 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7567 | if (!curproxy->bind_proc && nbproc == 1) { |
| 7568 | 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); |
| 7569 | curproxy->bind_proc = 1; |
| 7570 | } |
| 7571 | else if (!curproxy->bind_proc && nbproc > 1) { |
| 7572 | 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); |
| 7573 | curproxy->bind_proc = 0; |
| 7574 | } |
| 7575 | } |
| 7576 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7577 | /* check and reduce the bind-proc of each listener */ |
| 7578 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7579 | unsigned long mask; |
| 7580 | |
| 7581 | if (!bind_conf->bind_proc) |
| 7582 | continue; |
| 7583 | |
| 7584 | mask = nbits(global.nbproc); |
| 7585 | if (curproxy->bind_proc) |
| 7586 | mask &= curproxy->bind_proc; |
| 7587 | /* mask cannot be null here thanks to the previous checks */ |
| 7588 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7589 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7590 | bind_conf->bind_proc &= mask; |
| 7591 | |
| 7592 | if (!bind_conf->bind_proc && nbproc == 1) { |
| 7593 | 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", |
| 7594 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7595 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7596 | } |
| 7597 | else if (!bind_conf->bind_proc && nbproc > 1) { |
| 7598 | 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", |
| 7599 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 7600 | bind_conf->bind_proc = 0; |
| 7601 | } |
| 7602 | } |
| 7603 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7604 | switch (curproxy->mode) { |
| 7605 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7606 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7607 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7608 | Alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7609 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7610 | cfgerr++; |
| 7611 | } |
| 7612 | |
| 7613 | if (curproxy->srv != NULL) |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7614 | Warning("config : servers will be ignored for %s '%s'.\n", |
| 7615 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7616 | break; |
| 7617 | |
| 7618 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7619 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7620 | break; |
| 7621 | |
| 7622 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7623 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7624 | break; |
| 7625 | } |
| 7626 | |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7627 | if ((curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
| 7628 | Warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7629 | proxy_type_str(curproxy), curproxy->id); |
| 7630 | err_code |= ERR_WARN; |
| 7631 | } |
| 7632 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7633 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7634 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7635 | if (curproxy->options & PR_O_TRANSP) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7636 | Alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7637 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7638 | cfgerr++; |
| 7639 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7640 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7641 | else if (curproxy->srv == NULL) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7642 | Alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7643 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7644 | cfgerr++; |
| 7645 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7646 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7647 | else if (curproxy->options & PR_O_DISPATCH) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7648 | Warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7649 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7650 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7651 | } |
| 7652 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7653 | 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] | 7654 | /* If no LB algo is set in a backend, and we're not in |
| 7655 | * transparent mode, dispatch mode nor proxy mode, we |
| 7656 | * want to use balance roundrobin by default. |
| 7657 | */ |
| 7658 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7659 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7660 | } |
| 7661 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7662 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7663 | if (curproxy->options & PR_O_DISPATCH) |
| 7664 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7665 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7666 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7667 | else if (curproxy->options & PR_O_TRANSP) |
| 7668 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7669 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7670 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7671 | if (curproxy->options & PR_O_DISABLE404) { |
| 7672 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7673 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
| 7674 | err_code |= ERR_WARN; |
| 7675 | curproxy->options &= ~PR_O_DISABLE404; |
| 7676 | } |
| 7677 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
| 7678 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7679 | "send-state", proxy_type_str(curproxy), curproxy->id); |
| 7680 | err_code |= ERR_WARN; |
| 7681 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7682 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7683 | } |
| 7684 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7685 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7686 | if (!global.external_check) { |
| 7687 | Alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7688 | curproxy->id, "option external-check"); |
| 7689 | cfgerr++; |
| 7690 | } |
| 7691 | if (!curproxy->check_command) { |
| 7692 | Alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7693 | curproxy->id, "option external-check"); |
| 7694 | cfgerr++; |
| 7695 | } |
| 7696 | } |
| 7697 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7698 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7699 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
| 7700 | 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] | 7701 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7702 | "'email-alert myhostname', or 'email-alert to' " |
| 7703 | "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] | 7704 | "to be present).\n", |
| 7705 | proxy_type_str(curproxy), curproxy->id); |
| 7706 | err_code |= ERR_WARN; |
| 7707 | free_email_alert(curproxy); |
| 7708 | } |
| 7709 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7710 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7711 | } |
| 7712 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7713 | if (curproxy->check_command) { |
| 7714 | int clear = 0; |
| 7715 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7716 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7717 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
| 7718 | err_code |= ERR_WARN; |
| 7719 | clear = 1; |
| 7720 | } |
| 7721 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 7722 | 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] | 7723 | curproxy->id, "external-check command"); |
| 7724 | cfgerr++; |
| 7725 | } |
| 7726 | if (clear) { |
| 7727 | free(curproxy->check_command); |
| 7728 | curproxy->check_command = NULL; |
| 7729 | } |
| 7730 | } |
| 7731 | |
| 7732 | if (curproxy->check_path) { |
| 7733 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
| 7734 | Warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7735 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
| 7736 | err_code |= ERR_WARN; |
| 7737 | free(curproxy->check_path); |
| 7738 | curproxy->check_path = NULL; |
| 7739 | } |
| 7740 | } |
| 7741 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7742 | /* if a default backend was specified, let's find it */ |
| 7743 | if (curproxy->defbe.name) { |
| 7744 | struct proxy *target; |
| 7745 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7746 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7747 | if (!target) { |
| 7748 | Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7749 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7750 | cfgerr++; |
| 7751 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7752 | Alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7753 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7754 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7755 | } else if (target->mode != curproxy->mode && |
| 7756 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7757 | |
| 7758 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7759 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7760 | curproxy->conf.file, curproxy->conf.line, |
| 7761 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7762 | target->conf.file, target->conf.line); |
| 7763 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7764 | } else { |
| 7765 | free(curproxy->defbe.name); |
| 7766 | curproxy->defbe.be = target; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7767 | |
| 7768 | /* Emit a warning if this proxy also has some servers */ |
| 7769 | if (curproxy->srv) { |
| 7770 | Warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7771 | curproxy->id); |
| 7772 | err_code |= ERR_WARN; |
| 7773 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7774 | } |
| 7775 | } |
| 7776 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7777 | /* find the target proxy for 'use_backend' rules */ |
| 7778 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7779 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7780 | struct logformat_node *node; |
| 7781 | char *pxname; |
| 7782 | |
| 7783 | /* Try to parse the string as a log format expression. If the result |
| 7784 | * of the parsing is only one entry containing a simple string, then |
| 7785 | * it's a standard string corresponding to a static rule, thus the |
| 7786 | * parsing is cancelled and be.name is restored to be resolved. |
| 7787 | */ |
| 7788 | pxname = rule->be.name; |
| 7789 | LIST_INIT(&rule->be.expr); |
| 7790 | parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, |
| 7791 | curproxy->conf.args.file, curproxy->conf.args.line); |
| 7792 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7793 | |
| 7794 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7795 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7796 | rule->dynamic = 1; |
| 7797 | free(pxname); |
| 7798 | continue; |
| 7799 | } |
| 7800 | /* simple string: free the expression and fall back to static rule */ |
| 7801 | free(node->arg); |
| 7802 | free(node); |
| 7803 | } |
| 7804 | |
| 7805 | rule->dynamic = 0; |
| 7806 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7807 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7808 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7809 | if (!target) { |
| 7810 | Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7811 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7812 | cfgerr++; |
| 7813 | } else if (target == curproxy) { |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7814 | Alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7815 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7816 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7817 | } else if (target->mode != curproxy->mode && |
| 7818 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7819 | |
| 7820 | Alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7821 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7822 | curproxy->conf.file, curproxy->conf.line, |
| 7823 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7824 | target->conf.file, target->conf.line); |
| 7825 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7826 | } else { |
| 7827 | free((void *)rule->be.name); |
| 7828 | rule->be.backend = target; |
| 7829 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7830 | } |
| 7831 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7832 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7833 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7834 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7835 | |
| 7836 | if (!target) { |
| 7837 | Alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7838 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
| 7839 | cfgerr++; |
| 7840 | continue; |
| 7841 | } |
| 7842 | free((void *)srule->srv.name); |
| 7843 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7844 | } |
| 7845 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7846 | /* find the target table for 'stick' rules */ |
| 7847 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7848 | struct proxy *target; |
| 7849 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7850 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7851 | if (mrule->flags & STK_IS_STORE) |
| 7852 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7853 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7854 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7855 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7856 | else |
| 7857 | target = curproxy; |
| 7858 | |
| 7859 | if (!target) { |
| 7860 | Alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7861 | curproxy->id, mrule->table.name); |
| 7862 | cfgerr++; |
| 7863 | } |
| 7864 | else if (target->table.size == 0) { |
| 7865 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7866 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7867 | cfgerr++; |
| 7868 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7869 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7870 | 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] | 7871 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7872 | cfgerr++; |
| 7873 | } |
| 7874 | else { |
| 7875 | free((void *)mrule->table.name); |
| 7876 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7877 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7878 | } |
| 7879 | } |
| 7880 | |
| 7881 | /* find the target table for 'store response' rules */ |
| 7882 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7883 | struct proxy *target; |
| 7884 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7885 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7886 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7887 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7888 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7889 | else |
| 7890 | target = curproxy; |
| 7891 | |
| 7892 | if (!target) { |
| 7893 | Alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7894 | curproxy->id, mrule->table.name); |
| 7895 | cfgerr++; |
| 7896 | } |
| 7897 | else if (target->table.size == 0) { |
| 7898 | Alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7899 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7900 | cfgerr++; |
| 7901 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7902 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
| 7903 | 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] | 7904 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
| 7905 | cfgerr++; |
| 7906 | } |
| 7907 | else { |
| 7908 | free((void *)mrule->table.name); |
| 7909 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7910 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7911 | } |
| 7912 | } |
| 7913 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7914 | /* find the target table for 'tcp-request' layer 4 rules */ |
| 7915 | list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) { |
| 7916 | struct proxy *target; |
| 7917 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7918 | 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] | 7919 | continue; |
| 7920 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7921 | if (trule->arg.trk_ctr.table.n) |
| 7922 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7923 | else |
| 7924 | target = curproxy; |
| 7925 | |
| 7926 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7927 | 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] | 7928 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 7929 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7930 | cfgerr++; |
| 7931 | } |
| 7932 | else if (target->table.size == 0) { |
| 7933 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7934 | 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] | 7935 | cfgerr++; |
| 7936 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7937 | 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] | 7938 | 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] | 7939 | 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] | 7940 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7941 | cfgerr++; |
| 7942 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 7943 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7944 | free(trule->arg.trk_ctr.table.n); |
| 7945 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 7946 | /* 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] | 7947 | * to pass a list of counters to track and allocate them right here using |
| 7948 | * stktable_alloc_data_type(). |
| 7949 | */ |
| 7950 | } |
| 7951 | } |
| 7952 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 7953 | /* find the target table for 'tcp-request' layer 5 rules */ |
| 7954 | list_for_each_entry(trule, &curproxy->tcp_req.l5_rules, list) { |
| 7955 | struct proxy *target; |
| 7956 | |
| 7957 | if (trule->action < ACT_ACTION_TRK_SC0 || trule->action > ACT_ACTION_TRK_SCMAX) |
| 7958 | continue; |
| 7959 | |
| 7960 | if (trule->arg.trk_ctr.table.n) |
| 7961 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
| 7962 | else |
| 7963 | target = curproxy; |
| 7964 | |
| 7965 | if (!target) { |
| 7966 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 7967 | curproxy->id, trule->arg.trk_ctr.table.n, |
| 7968 | tcp_trk_idx(trule->action)); |
| 7969 | cfgerr++; |
| 7970 | } |
| 7971 | else if (target->table.size == 0) { |
| 7972 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 7973 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id); |
| 7974 | cfgerr++; |
| 7975 | } |
| 7976 | else if (!stktable_compatible_sample(trule->arg.trk_ctr.expr, target->table.type)) { |
| 7977 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 7978 | curproxy->id, trule->arg.trk_ctr.table.n ? trule->arg.trk_ctr.table.n : curproxy->id, |
| 7979 | tcp_trk_idx(trule->action)); |
| 7980 | cfgerr++; |
| 7981 | } |
| 7982 | else { |
| 7983 | free(trule->arg.trk_ctr.table.n); |
| 7984 | trule->arg.trk_ctr.table.t = &target->table; |
| 7985 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 7986 | * to pass a list of counters to track and allocate them right here using |
| 7987 | * stktable_alloc_data_type(). |
| 7988 | */ |
| 7989 | } |
| 7990 | } |
| 7991 | |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7992 | /* find the target table for 'tcp-request' layer 6 rules */ |
| 7993 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
| 7994 | struct proxy *target; |
| 7995 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 7996 | 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] | 7997 | continue; |
| 7998 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 7999 | if (trule->arg.trk_ctr.table.n) |
| 8000 | target = proxy_tbl_by_name(trule->arg.trk_ctr.table.n); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8001 | else |
| 8002 | target = curproxy; |
| 8003 | |
| 8004 | if (!target) { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 8005 | 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] | 8006 | curproxy->id, trule->arg.trk_ctr.table.n, |
Willy Tarreau | 34c2fb6 | 2013-12-02 23:29:05 +0100 | [diff] [blame] | 8007 | tcp_trk_idx(trule->action)); |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8008 | cfgerr++; |
| 8009 | } |
| 8010 | else if (target->table.size == 0) { |
| 8011 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8012 | 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] | 8013 | cfgerr++; |
| 8014 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8015 | 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] | 8016 | 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] | 8017 | 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] | 8018 | tcp_trk_idx(trule->action)); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 8019 | cfgerr++; |
| 8020 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8021 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8022 | free(trule->arg.trk_ctr.table.n); |
| 8023 | trule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 8024 | /* 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] | 8025 | * to pass a list of counters to track and allocate them right here using |
| 8026 | * stktable_alloc_data_type(). |
| 8027 | */ |
| 8028 | } |
| 8029 | } |
| 8030 | |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8031 | /* parse http-request capture rules to ensure id really exists */ |
| 8032 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 8033 | if (hrqrule->action != ACT_CUSTOM || |
| 8034 | hrqrule->action_ptr != http_action_req_capture_by_id) |
| 8035 | continue; |
| 8036 | |
| 8037 | if (hrqrule->arg.capid.idx >= curproxy->nb_req_cap) { |
| 8038 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-request capture rule.\n", |
| 8039 | curproxy->id, hrqrule->arg.capid.idx); |
| 8040 | cfgerr++; |
| 8041 | } |
| 8042 | } |
| 8043 | |
| 8044 | /* parse http-response capture rules to ensure id really exists */ |
| 8045 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8046 | if (hrqrule->action != ACT_CUSTOM || |
| 8047 | hrqrule->action_ptr != http_action_res_capture_by_id) |
| 8048 | continue; |
| 8049 | |
| 8050 | if (hrqrule->arg.capid.idx >= curproxy->nb_rsp_cap) { |
| 8051 | Alert("Proxy '%s': unable to find capture id '%d' referenced by http-response capture rule.\n", |
| 8052 | curproxy->id, hrqrule->arg.capid.idx); |
| 8053 | cfgerr++; |
| 8054 | } |
| 8055 | } |
| 8056 | |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8057 | /* find the target table for 'http-request' layer 7 rules */ |
| 8058 | list_for_each_entry(hrqrule, &curproxy->http_req_rules, list) { |
| 8059 | struct proxy *target; |
| 8060 | |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8061 | 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] | 8062 | continue; |
| 8063 | |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8064 | if (hrqrule->arg.trk_ctr.table.n) |
| 8065 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8066 | else |
| 8067 | target = curproxy; |
| 8068 | |
| 8069 | if (!target) { |
| 8070 | 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] | 8071 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8072 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8073 | cfgerr++; |
| 8074 | } |
| 8075 | else if (target->table.size == 0) { |
| 8076 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8077 | 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] | 8078 | cfgerr++; |
| 8079 | } |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8080 | 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] | 8081 | 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] | 8082 | 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] | 8083 | http_trk_idx(hrqrule->action)); |
| 8084 | cfgerr++; |
| 8085 | } |
| 8086 | else { |
| 8087 | free(hrqrule->arg.trk_ctr.table.n); |
| 8088 | hrqrule->arg.trk_ctr.table.t = &target->table; |
| 8089 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8090 | * to pass a list of counters to track and allocate them right here using |
| 8091 | * stktable_alloc_data_type(). |
| 8092 | */ |
| 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | /* find the target table for 'http-response' layer 7 rules */ |
| 8097 | list_for_each_entry(hrqrule, &curproxy->http_res_rules, list) { |
| 8098 | struct proxy *target; |
| 8099 | |
| 8100 | if (hrqrule->action < ACT_ACTION_TRK_SC0 || hrqrule->action > ACT_ACTION_TRK_SCMAX) |
| 8101 | continue; |
| 8102 | |
| 8103 | if (hrqrule->arg.trk_ctr.table.n) |
| 8104 | target = proxy_tbl_by_name(hrqrule->arg.trk_ctr.table.n); |
| 8105 | else |
| 8106 | target = curproxy; |
| 8107 | |
| 8108 | if (!target) { |
| 8109 | Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n", |
| 8110 | curproxy->id, hrqrule->arg.trk_ctr.table.n, |
| 8111 | http_trk_idx(hrqrule->action)); |
| 8112 | cfgerr++; |
| 8113 | } |
| 8114 | else if (target->table.size == 0) { |
| 8115 | Alert("Proxy '%s': table '%s' used but not configured.\n", |
| 8116 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id); |
| 8117 | cfgerr++; |
| 8118 | } |
| 8119 | else if (!stktable_compatible_sample(hrqrule->arg.trk_ctr.expr, target->table.type)) { |
| 8120 | Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n", |
| 8121 | curproxy->id, hrqrule->arg.trk_ctr.table.n ? hrqrule->arg.trk_ctr.table.n : curproxy->id, |
| 8122 | http_trk_idx(hrqrule->action)); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8123 | cfgerr++; |
| 8124 | } |
| 8125 | else { |
Thierry FOURNIER | 5ec63e0 | 2015-08-04 09:09:48 +0200 | [diff] [blame] | 8126 | free(hrqrule->arg.trk_ctr.table.n); |
| 8127 | hrqrule->arg.trk_ctr.table.t = &target->table; |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8128 | /* Note: if we decide to enhance the track-sc syntax, we may be able |
| 8129 | * to pass a list of counters to track and allocate them right here using |
| 8130 | * stktable_alloc_data_type(). |
| 8131 | */ |
| 8132 | } |
| 8133 | } |
| 8134 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8135 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8136 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8137 | /* insert block_rules into http_req_rules at the beginning */ |
| 8138 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8139 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8140 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8141 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8142 | LIST_INIT(&curproxy->block_rules); |
| 8143 | } |
| 8144 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8145 | if (curproxy->table.peers.name) { |
| 8146 | struct peers *curpeers = peers; |
| 8147 | |
| 8148 | for (curpeers = peers; curpeers; curpeers = curpeers->next) { |
| 8149 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8150 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8151 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8152 | break; |
| 8153 | } |
| 8154 | } |
| 8155 | |
| 8156 | if (!curpeers) { |
| 8157 | Alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8158 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8159 | free((void *)curproxy->table.peers.name); |
| 8160 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8161 | cfgerr++; |
| 8162 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8163 | else if (curpeers->state == PR_STSTOPPED) { |
| 8164 | /* silently disable this peers section */ |
| 8165 | curproxy->table.peers.p = NULL; |
| 8166 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8167 | else if (!curpeers->peers_fe) { |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8168 | Alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8169 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8170 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8171 | cfgerr++; |
| 8172 | } |
| 8173 | } |
| 8174 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8175 | |
| 8176 | if (curproxy->email_alert.mailers.name) { |
| 8177 | struct mailers *curmailers = mailers; |
| 8178 | |
| 8179 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
| 8180 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) { |
| 8181 | free(curproxy->email_alert.mailers.name); |
| 8182 | curproxy->email_alert.mailers.m = curmailers; |
| 8183 | curmailers->users++; |
| 8184 | break; |
| 8185 | } |
| 8186 | } |
| 8187 | |
| 8188 | if (!curmailers) { |
| 8189 | Alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8190 | curproxy->id, curproxy->email_alert.mailers.name); |
| 8191 | free_email_alert(curproxy); |
| 8192 | cfgerr++; |
| 8193 | } |
| 8194 | } |
| 8195 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8196 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8197 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8198 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
| 8199 | Alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8200 | "proxy", curproxy->id); |
| 8201 | cfgerr++; |
| 8202 | goto out_uri_auth_compat; |
| 8203 | } |
| 8204 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8205 | 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] | 8206 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8207 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8208 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8209 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8210 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8211 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8212 | |
| 8213 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8214 | uri_auth_compat_req[i++] = "realm"; |
| 8215 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8216 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8217 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8218 | uri_auth_compat_req[i++] = "unless"; |
| 8219 | uri_auth_compat_req[i++] = "{"; |
| 8220 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8221 | uri_auth_compat_req[i++] = "}"; |
| 8222 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8223 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8224 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8225 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8226 | cfgerr++; |
| 8227 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8228 | } |
| 8229 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8230 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8231 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8232 | if (curproxy->uri_auth->auth_realm) { |
| 8233 | free(curproxy->uri_auth->auth_realm); |
| 8234 | curproxy->uri_auth->auth_realm = NULL; |
| 8235 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8236 | |
| 8237 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8238 | } |
| 8239 | out_uri_auth_compat: |
| 8240 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8241 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8242 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8243 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8244 | if (!curproxy->conf.logformat_sd_string) { |
| 8245 | /* set the default logformat_sd_string */ |
| 8246 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8247 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8248 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8249 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8250 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8251 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8252 | /* compile the log format */ |
| 8253 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8254 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8255 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8256 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8257 | free(curproxy->conf.logformat_string); |
| 8258 | curproxy->conf.logformat_string = NULL; |
| 8259 | free(curproxy->conf.lfs_file); |
| 8260 | curproxy->conf.lfs_file = NULL; |
| 8261 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8262 | |
| 8263 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8264 | free(curproxy->conf.logformat_sd_string); |
| 8265 | curproxy->conf.logformat_sd_string = NULL; |
| 8266 | free(curproxy->conf.lfsd_file); |
| 8267 | curproxy->conf.lfsd_file = NULL; |
| 8268 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8269 | } |
| 8270 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8271 | if (curproxy->conf.logformat_string) { |
| 8272 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8273 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8274 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
| 8275 | 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] | 8276 | 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] | 8277 | curproxy->conf.args.file = NULL; |
| 8278 | curproxy->conf.args.line = 0; |
| 8279 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8280 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8281 | if (curproxy->conf.logformat_sd_string) { |
| 8282 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8283 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8284 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
| 8285 | parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
| 8286 | SMP_VAL_FE_LOG_END, curproxy->conf.lfsd_file, curproxy->conf.lfsd_line); |
| 8287 | add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd); |
| 8288 | curproxy->conf.args.file = NULL; |
| 8289 | curproxy->conf.args.line = 0; |
| 8290 | } |
| 8291 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8292 | if (curproxy->conf.uniqueid_format_string) { |
| 8293 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8294 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8295 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 8296 | 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] | 8297 | (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] | 8298 | curproxy->conf.uif_file, curproxy->conf.uif_line); |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8299 | curproxy->conf.args.file = NULL; |
| 8300 | curproxy->conf.args.line = 0; |
| 8301 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8302 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8303 | /* only now we can check if some args remain unresolved. |
| 8304 | * This must be done after the users and groups resolution. |
| 8305 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8306 | cfgerr += smp_resolve_args(curproxy); |
| 8307 | if (!cfgerr) |
| 8308 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8309 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8310 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8311 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8312 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8313 | (!curproxy->timeout.connect || |
| 8314 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8315 | Warning("config : missing timeouts for %s '%s'.\n" |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8316 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8317 | " | 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] | 8318 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8319 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8320 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8321 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8322 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8323 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8324 | * We must still support older configurations, so let's find out whether those |
| 8325 | * parameters have been set or must be copied from contimeouts. |
| 8326 | */ |
| 8327 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8328 | if (!curproxy->timeout.tarpit || |
| 8329 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8330 | /* tarpit timeout not set. We search in the following order: |
| 8331 | * default.tarpit, curr.connect, default.connect. |
| 8332 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8333 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8334 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8335 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8336 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8337 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8338 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8339 | } |
| 8340 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8341 | (!curproxy->timeout.queue || |
| 8342 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8343 | /* queue timeout not set. We search in the following order: |
| 8344 | * default.queue, curr.connect, default.connect. |
| 8345 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8346 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8347 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8348 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8349 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8350 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8351 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8352 | } |
| 8353 | } |
| 8354 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8355 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8356 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8357 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8358 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8359 | } |
| 8360 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8361 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8362 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
| 8363 | Warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8364 | proxy_type_str(curproxy), curproxy->id); |
| 8365 | err_code |= ERR_WARN; |
| 8366 | } |
| 8367 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8368 | /* ensure that cookie capture length is not too large */ |
| 8369 | if (curproxy->capture_len >= global.tune.cookie_len) { |
| 8370 | Warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8371 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
| 8372 | err_code |= ERR_WARN; |
| 8373 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8374 | } |
| 8375 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8376 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8377 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8378 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8379 | curproxy->nb_req_cap * sizeof(char *), |
| 8380 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8381 | } |
| 8382 | |
| 8383 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8384 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8385 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8386 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8387 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8388 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8389 | switch (curproxy->load_server_state_from_file) { |
| 8390 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8391 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8392 | break; |
| 8393 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8394 | if (!global.server_state_file) { |
| 8395 | 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", |
| 8396 | curproxy->id); |
| 8397 | err_code |= ERR_WARN; |
| 8398 | } |
| 8399 | break; |
| 8400 | } |
| 8401 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8402 | /* first, we will invert the servers list order */ |
| 8403 | newsrv = NULL; |
| 8404 | while (curproxy->srv) { |
| 8405 | struct server *next; |
| 8406 | |
| 8407 | next = curproxy->srv->next; |
| 8408 | curproxy->srv->next = newsrv; |
| 8409 | newsrv = curproxy->srv; |
| 8410 | if (!next) |
| 8411 | break; |
| 8412 | curproxy->srv = next; |
| 8413 | } |
| 8414 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8415 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8416 | * We only emit a warning for the first conflict affecting each server, |
| 8417 | * in order to avoid combinatory explosion if all servers have the same |
| 8418 | * name. We do that only for servers which do not have an explicit ID, |
| 8419 | * because these IDs were made also for distinguishing them and we don't |
| 8420 | * want to annoy people who correctly manage them. |
| 8421 | */ |
| 8422 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8423 | struct server *other_srv; |
| 8424 | |
| 8425 | if (newsrv->puid) |
| 8426 | continue; |
| 8427 | |
| 8428 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8429 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
| 8430 | Warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8431 | newsrv->conf.file, newsrv->conf.line, |
| 8432 | proxy_type_str(curproxy), curproxy->id, |
| 8433 | newsrv->id, other_srv->conf.line); |
| 8434 | break; |
| 8435 | } |
| 8436 | } |
| 8437 | } |
| 8438 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8439 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8440 | next_id = 1; |
| 8441 | newsrv = curproxy->srv; |
| 8442 | while (newsrv != NULL) { |
| 8443 | if (!newsrv->puid) { |
| 8444 | /* server ID not set, use automatic numbering with first |
| 8445 | * spare entry starting with next_svid. |
| 8446 | */ |
| 8447 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8448 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8449 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8450 | } |
| 8451 | next_id++; |
| 8452 | newsrv = newsrv->next; |
| 8453 | } |
| 8454 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8455 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8456 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8457 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8458 | /* |
| 8459 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8460 | * tasks to fill the emptied slots when a connection leaves. |
| 8461 | * Also, resolve deferred tracking dependency if needed. |
| 8462 | */ |
| 8463 | newsrv = curproxy->srv; |
| 8464 | while (newsrv != NULL) { |
| 8465 | if (newsrv->minconn > newsrv->maxconn) { |
| 8466 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8467 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8468 | * this will avoid further useless expensive computations. |
| 8469 | */ |
| 8470 | newsrv->maxconn = newsrv->minconn; |
| 8471 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8472 | /* minconn was not specified, so we set it to maxconn */ |
| 8473 | newsrv->minconn = newsrv->maxconn; |
| 8474 | } |
| 8475 | |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8476 | #ifdef USE_OPENSSL |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8477 | if (newsrv->use_ssl || newsrv->check.use_ssl) |
| 8478 | cfgerr += ssl_sock_prepare_srv_ctx(newsrv, curproxy); |
Emeric Brun | 01f8e2f | 2012-05-18 16:02:00 +0200 | [diff] [blame] | 8479 | #endif /* USE_OPENSSL */ |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8480 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8481 | /* set the check type on the server */ |
| 8482 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8483 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8484 | if (newsrv->trackit) { |
| 8485 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8486 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8487 | char *pname, *sname; |
| 8488 | |
| 8489 | pname = newsrv->trackit; |
| 8490 | sname = strrchr(pname, '/'); |
| 8491 | |
| 8492 | if (sname) |
| 8493 | *sname++ = '\0'; |
| 8494 | else { |
| 8495 | sname = pname; |
| 8496 | pname = NULL; |
| 8497 | } |
| 8498 | |
| 8499 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8500 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8501 | if (!px) { |
| 8502 | Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8503 | proxy_type_str(curproxy), curproxy->id, |
| 8504 | newsrv->id, pname); |
| 8505 | cfgerr++; |
| 8506 | goto next_srv; |
| 8507 | } |
| 8508 | } else |
| 8509 | px = curproxy; |
| 8510 | |
| 8511 | srv = findserver(px, sname); |
| 8512 | if (!srv) { |
| 8513 | Alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8514 | proxy_type_str(curproxy), curproxy->id, |
| 8515 | newsrv->id, sname); |
| 8516 | cfgerr++; |
| 8517 | goto next_srv; |
| 8518 | } |
| 8519 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8520 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8521 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8522 | !srv->track && !srv->trackit) { |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8523 | Alert("config : %s '%s', server '%s': unable to use %s/%s for " |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8524 | "tracking as it does not have any check nor agent enabled.\n", |
| 8525 | proxy_type_str(curproxy), curproxy->id, |
| 8526 | newsrv->id, px->id, srv->id); |
| 8527 | cfgerr++; |
| 8528 | goto next_srv; |
| 8529 | } |
| 8530 | |
| 8531 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8532 | |
| 8533 | if (loop) { |
| 8534 | Alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8535 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8536 | proxy_type_str(curproxy), curproxy->id, |
| 8537 | newsrv->id, px->id, srv->id, px->id, loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8538 | cfgerr++; |
| 8539 | goto next_srv; |
| 8540 | } |
| 8541 | |
| 8542 | if (curproxy != px && |
| 8543 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
| 8544 | Alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8545 | "tracking: disable-on-404 option inconsistency.\n", |
| 8546 | proxy_type_str(curproxy), curproxy->id, |
| 8547 | newsrv->id, px->id, srv->id); |
| 8548 | cfgerr++; |
| 8549 | goto next_srv; |
| 8550 | } |
| 8551 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8552 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8553 | newsrv->tracknext = srv->trackers; |
| 8554 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8555 | |
| 8556 | free(newsrv->trackit); |
| 8557 | newsrv->trackit = NULL; |
| 8558 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8559 | |
| 8560 | /* |
| 8561 | * resolve server's resolvers name and update the resolvers pointer |
| 8562 | * accordingly |
| 8563 | */ |
| 8564 | if (newsrv->resolvers_id) { |
| 8565 | struct dns_resolvers *curr_resolvers; |
| 8566 | int found; |
| 8567 | |
| 8568 | found = 0; |
| 8569 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 8570 | if (!strcmp(curr_resolvers->id, newsrv->resolvers_id)) { |
| 8571 | found = 1; |
| 8572 | break; |
| 8573 | } |
| 8574 | } |
| 8575 | |
| 8576 | if (!found) { |
| 8577 | Alert("config : %s '%s', server '%s': unable to find required resolvers '%s'\n", |
| 8578 | proxy_type_str(curproxy), curproxy->id, |
| 8579 | newsrv->id, newsrv->resolvers_id); |
| 8580 | cfgerr++; |
| 8581 | } else { |
| 8582 | free(newsrv->resolvers_id); |
| 8583 | newsrv->resolvers_id = NULL; |
| 8584 | if (newsrv->resolution) |
| 8585 | newsrv->resolution->resolvers = curr_resolvers; |
| 8586 | } |
| 8587 | } |
| 8588 | else { |
| 8589 | /* if no resolvers section associated to this server |
| 8590 | * we can clean up the associated resolution structure |
| 8591 | */ |
| 8592 | if (newsrv->resolution) { |
| 8593 | free(newsrv->resolution->hostname_dn); |
| 8594 | newsrv->resolution->hostname_dn = NULL; |
| 8595 | free(newsrv->resolution); |
| 8596 | newsrv->resolution = NULL; |
| 8597 | } |
| 8598 | } |
| 8599 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8600 | next_srv: |
| 8601 | newsrv = newsrv->next; |
| 8602 | } |
| 8603 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8604 | /* We have to initialize the server lookup mechanism depending |
| 8605 | * on what LB algorithm was choosen. |
| 8606 | */ |
| 8607 | |
| 8608 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8609 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8610 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8611 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8612 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8613 | init_server_map(curproxy); |
| 8614 | } else { |
| 8615 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8616 | fwrr_init_server_groups(curproxy); |
| 8617 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8618 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8619 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8620 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8621 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8622 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8623 | fwlc_init_server_tree(curproxy); |
| 8624 | } else { |
| 8625 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8626 | fas_init_server_tree(curproxy); |
| 8627 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8628 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8629 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8630 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8631 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8632 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8633 | chash_init_server_tree(curproxy); |
| 8634 | } else { |
| 8635 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8636 | init_server_map(curproxy); |
| 8637 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8638 | break; |
| 8639 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8640 | |
| 8641 | if (curproxy->options & PR_O_LOGASAP) |
| 8642 | curproxy->to_log &= ~LW_BYTES; |
| 8643 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8644 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8645 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8646 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8647 | Warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8648 | proxy_type_str(curproxy), curproxy->id); |
| 8649 | err_code |= ERR_WARN; |
| 8650 | } |
| 8651 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8652 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8653 | int optnum; |
| 8654 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8655 | if (curproxy->uri_auth) { |
| 8656 | Warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8657 | proxy_type_str(curproxy), curproxy->id); |
| 8658 | err_code |= ERR_WARN; |
| 8659 | curproxy->uri_auth = NULL; |
| 8660 | } |
| 8661 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8662 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8663 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8664 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
| 8665 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8666 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | if (curproxy->options & PR_O_ORGTO) { |
| 8670 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8671 | "originalto", proxy_type_str(curproxy), curproxy->id); |
| 8672 | err_code |= ERR_WARN; |
| 8673 | curproxy->options &= ~PR_O_ORGTO; |
| 8674 | } |
| 8675 | |
| 8676 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8677 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8678 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8679 | (curproxy->options & cfg_opts[optnum].val)) { |
| 8680 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8681 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8682 | err_code |= ERR_WARN; |
| 8683 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8684 | } |
| 8685 | } |
| 8686 | |
| 8687 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8688 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8689 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8690 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
| 8691 | Warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8692 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
| 8693 | err_code |= ERR_WARN; |
| 8694 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8695 | } |
| 8696 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8697 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8698 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8699 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8700 | curproxy->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8701 | 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] | 8702 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8703 | err_code |= ERR_WARN; |
| 8704 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8705 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8706 | } |
| 8707 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8708 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8709 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8710 | */ |
| 8711 | newsrv = curproxy->srv; |
| 8712 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8713 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 8714 | Alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8715 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8716 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8717 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8718 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8719 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
| 8720 | Warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8721 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8722 | err_code |= ERR_WARN; |
| 8723 | } |
| 8724 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8725 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8726 | Warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8727 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
| 8728 | err_code |= ERR_WARN; |
| 8729 | } |
| 8730 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8731 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8732 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8733 | newsrv->conn_src.bind_hdr_occ = 0; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8734 | 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] | 8735 | 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] | 8736 | err_code |= ERR_WARN; |
| 8737 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8738 | #endif |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8739 | newsrv = newsrv->next; |
| 8740 | } |
| 8741 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8742 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8743 | * with no inspect-delay |
| 8744 | */ |
| 8745 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
| 8746 | list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) { |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8747 | if (trule->action == ACT_TCP_CAPTURE && |
Thierry FOURNIER | d0d65ae | 2015-08-04 08:21:12 +0200 | [diff] [blame] | 8748 | !(trule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8749 | break; |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 8750 | 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] | 8751 | !(trule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8752 | break; |
| 8753 | } |
| 8754 | |
| 8755 | if (&trule->list != &curproxy->tcp_req.inspect_rules) { |
| 8756 | Warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8757 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8758 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8759 | " setting the tcp-request inspect-delay.\n", |
| 8760 | proxy_type_str(curproxy), curproxy->id); |
| 8761 | err_code |= ERR_WARN; |
| 8762 | } |
| 8763 | } |
| 8764 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8765 | /* Check filter configuration, if any */ |
| 8766 | cfgerr += flt_check(curproxy); |
| 8767 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8768 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8769 | if (!curproxy->accept) |
| 8770 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8771 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8772 | if (curproxy->tcp_req.inspect_delay || |
| 8773 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8774 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8775 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8776 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8777 | 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] | 8778 | 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] | 8779 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8780 | |
| 8781 | /* both TCP and HTTP must check switching rules */ |
| 8782 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8783 | |
| 8784 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8785 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8786 | curproxy->fe_req_ana |= AN_FLT_ALL_FE; |
| 8787 | curproxy->fe_rsp_ana |= AN_FLT_ALL_FE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8788 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8789 | curproxy->fe_req_ana |= AN_FLT_HTTP_HDRS; |
| 8790 | curproxy->fe_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8791 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8792 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8793 | } |
| 8794 | |
| 8795 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8796 | if (curproxy->tcp_req.inspect_delay || |
| 8797 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8798 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8799 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8800 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8801 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8802 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8803 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8804 | 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] | 8805 | 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] | 8806 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8807 | |
| 8808 | /* If the backend does requires RDP cookie persistence, we have to |
| 8809 | * enable the corresponding analyser. |
| 8810 | */ |
| 8811 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8812 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8813 | |
| 8814 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8815 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8816 | curproxy->be_req_ana |= AN_FLT_ALL_BE; |
| 8817 | curproxy->be_rsp_ana |= AN_FLT_ALL_BE; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8818 | if (curproxy->mode == PR_MODE_HTTP) { |
| 8819 | curproxy->be_req_ana |= AN_FLT_HTTP_HDRS; |
| 8820 | curproxy->be_rsp_ana |= AN_FLT_HTTP_HDRS; |
| 8821 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8822 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8823 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8824 | } |
| 8825 | |
| 8826 | /***********************************************************/ |
| 8827 | /* At this point, target names have already been resolved. */ |
| 8828 | /***********************************************************/ |
| 8829 | |
| 8830 | /* Check multi-process mode compatibility */ |
| 8831 | |
| 8832 | if (global.nbproc > 1 && global.stats_fe) { |
| 8833 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8834 | unsigned long mask; |
| 8835 | |
| 8836 | mask = nbits(global.nbproc); |
| 8837 | if (global.stats_fe->bind_proc) |
| 8838 | mask &= global.stats_fe->bind_proc; |
| 8839 | |
| 8840 | if (bind_conf->bind_proc) |
| 8841 | mask &= bind_conf->bind_proc; |
| 8842 | |
| 8843 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8844 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8845 | break; |
| 8846 | } |
| 8847 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
| 8848 | 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"); |
| 8849 | } |
| 8850 | } |
| 8851 | |
| 8852 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
| 8853 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8854 | if (curproxy->bind_proc) |
| 8855 | continue; |
| 8856 | |
| 8857 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8858 | unsigned long mask; |
| 8859 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8860 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8861 | curproxy->bind_proc |= mask; |
| 8862 | } |
| 8863 | |
| 8864 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8865 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8866 | } |
| 8867 | |
| 8868 | if (global.stats_fe) { |
| 8869 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8870 | unsigned long mask; |
| 8871 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8872 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8873 | global.stats_fe->bind_proc |= mask; |
| 8874 | } |
| 8875 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8876 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8877 | } |
| 8878 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8879 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8880 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8881 | */ |
| 8882 | if (!cfgerr) { |
| 8883 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8884 | if (curproxy->cap & PR_CAP_FE) |
| 8885 | propagate_processes(curproxy, NULL); |
| 8886 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8887 | } |
| 8888 | |
| 8889 | /* Bind each unbound backend to all processes when not specified. */ |
| 8890 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8891 | if (curproxy->bind_proc) |
| 8892 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8893 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8894 | } |
| 8895 | |
| 8896 | /*******************************************************/ |
| 8897 | /* At this step, all proxies have a non-null bind_proc */ |
| 8898 | /*******************************************************/ |
| 8899 | |
| 8900 | /* perform the final checks before creating tasks */ |
| 8901 | |
| 8902 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 8903 | struct listener *listener; |
| 8904 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8905 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8906 | #ifdef USE_OPENSSL |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8907 | /* Configure SSL for each bind line. |
| 8908 | * Note: if configuration fails at some point, the ->ctx member |
| 8909 | * remains NULL so that listeners can later detach. |
| 8910 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8911 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8912 | int alloc_ctx; |
| 8913 | |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8914 | if (!bind_conf->is_ssl) { |
| 8915 | if (bind_conf->default_ctx) { |
| 8916 | Warning("Proxy '%s': A certificate was specified but SSL was not enabled on bind '%s' at [%s:%d] (use 'ssl').\n", |
| 8917 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8918 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8919 | continue; |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8920 | } |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8921 | if (!bind_conf->default_ctx) { |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8922 | 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] | 8923 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8924 | cfgerr++; |
| 8925 | continue; |
| 8926 | } |
| 8927 | |
Emeric Brun | 8dc6039 | 2014-05-09 13:52:00 +0200 | [diff] [blame] | 8928 | 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] | 8929 | if (alloc_ctx < 0) { |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8930 | if (alloc_ctx == SHCTX_E_INIT_LOCK) |
| 8931 | 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"); |
| 8932 | else |
Emeric Brun | caa19cc | 2014-05-07 16:10:18 +0200 | [diff] [blame] | 8933 | Alert("Unable to allocate SSL session cache.\n"); |
Emeric Brun | 93ee249 | 2014-05-09 14:01:48 +0200 | [diff] [blame] | 8934 | cfgerr++; |
| 8935 | continue; |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8936 | } |
| 8937 | |
Emeric Brun | fc0421f | 2012-09-07 17:30:07 +0200 | [diff] [blame] | 8938 | /* initialize all certificate contexts */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8939 | cfgerr += ssl_sock_prepare_all_ctx(bind_conf, curproxy); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 8940 | |
| 8941 | /* initialize CA variables if the certificates generation is enabled */ |
| 8942 | cfgerr += ssl_sock_load_ca(bind_conf, curproxy); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8943 | } |
Emeric Brun | c52962f | 2012-11-15 18:28:02 +0100 | [diff] [blame] | 8944 | #endif /* USE_OPENSSL */ |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8945 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8946 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8947 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8948 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8949 | int nbproc; |
| 8950 | |
| 8951 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8952 | (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] | 8953 | nbits(global.nbproc)); |
| 8954 | |
| 8955 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8956 | nbproc = 1; |
| 8957 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8958 | if (!listener->luid) { |
| 8959 | /* listener ID not set, use automatic numbering with first |
| 8960 | * spare entry starting with next_luid. |
| 8961 | */ |
| 8962 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8963 | listener->conf.id.key = listener->luid = next_id; |
| 8964 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8965 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8966 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8967 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8968 | /* enable separate counters */ |
| 8969 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8970 | listener->counters = calloc(1, sizeof(struct licounters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8971 | if (!listener->name) |
| 8972 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8973 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8974 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8975 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8976 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8977 | if (!listener->maxconn) |
| 8978 | listener->maxconn = curproxy->maxconn; |
| 8979 | if (!listener->backlog) |
| 8980 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8981 | if (!listener->maxaccept) |
| 8982 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8983 | |
| 8984 | /* we want to have an optimal behaviour on single process mode to |
| 8985 | * maximize the work at once, but in multi-process we want to keep |
| 8986 | * some fairness between processes, so we target half of the max |
| 8987 | * number of events to be balanced over all the processes the proxy |
| 8988 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8989 | * used to disable the limit. |
| 8990 | */ |
| 8991 | if (listener->maxaccept > 0) { |
| 8992 | if (nbproc > 1) |
| 8993 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8994 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8995 | } |
| 8996 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8997 | listener->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 8998 | listener->handler = process_stream; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8999 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 9000 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 9001 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9002 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 9003 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 9004 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 9005 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 9006 | listener->options |= LI_O_TCP_L5_RULES; |
| 9007 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 9008 | if (curproxy->mon_mask.s_addr) |
| 9009 | listener->options |= LI_O_CHK_MONNET; |
| 9010 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9011 | /* smart accept mode is automatic in HTTP mode */ |
| 9012 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9013 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 9014 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 9015 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 9016 | } |
| 9017 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9018 | /* Release unused SSL configs */ |
| 9019 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 9020 | if (bind_conf->is_ssl) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9021 | continue; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9022 | #ifdef USE_OPENSSL |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9023 | ssl_sock_free_ca(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9024 | ssl_sock_free_all_ctx(bind_conf); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 9025 | free(bind_conf->ca_file); |
Christopher Faulet | 31af49d | 2015-06-09 17:29:50 +0200 | [diff] [blame] | 9026 | free(bind_conf->ca_sign_file); |
| 9027 | free(bind_conf->ca_sign_pass); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9028 | free(bind_conf->ciphers); |
Emeric Brun | 2b58d04 | 2012-09-20 17:10:03 +0200 | [diff] [blame] | 9029 | free(bind_conf->ecdhe); |
Emeric Brun | fb510ea | 2012-10-05 12:00:26 +0200 | [diff] [blame] | 9030 | free(bind_conf->crl_file); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 9031 | if(bind_conf->keys_ref) { |
| 9032 | free(bind_conf->keys_ref->filename); |
| 9033 | free(bind_conf->keys_ref->tlskeys); |
William Lallemand | 7bba4cc | 2016-05-20 17:28:07 +0200 | [diff] [blame] | 9034 | LIST_DEL(&bind_conf->keys_ref->list); |
Nenad Merdanovic | 146defa | 2015-05-09 08:46:00 +0200 | [diff] [blame] | 9035 | free(bind_conf->keys_ref); |
| 9036 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9037 | #endif /* USE_OPENSSL */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 9038 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 9039 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 9040 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9041 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9042 | int count, maxproc = 0; |
| 9043 | |
| 9044 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9045 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9046 | if (count > maxproc) |
| 9047 | maxproc = count; |
| 9048 | } |
| 9049 | /* backends have 0, frontends have 1 or more */ |
| 9050 | if (maxproc != 1) |
| 9051 | Warning("Proxy '%s': in multi-process mode, stats will be" |
| 9052 | " limited to process assigned to the current request.\n", |
| 9053 | curproxy->id); |
| 9054 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9055 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
| 9056 | Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 9057 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9058 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9059 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9060 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
| 9061 | Warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 9062 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9063 | } |
| 9064 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9065 | |
| 9066 | /* create the task associated with the proxy */ |
| 9067 | curproxy->task = task_new(); |
| 9068 | if (curproxy->task) { |
| 9069 | curproxy->task->context = curproxy; |
| 9070 | curproxy->task->process = manage_proxy; |
| 9071 | /* no need to queue, it will be done automatically if some |
| 9072 | * listener gets limited. |
| 9073 | */ |
| 9074 | curproxy->task->expire = TICK_ETERNITY; |
| 9075 | } else { |
| 9076 | Alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 9077 | curproxy->id); |
| 9078 | cfgerr++; |
| 9079 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 9080 | } |
| 9081 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9082 | /* automatically compute fullconn if not set. We must not do it in the |
| 9083 | * loop above because cross-references are not yet fully resolved. |
| 9084 | */ |
| 9085 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9086 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9087 | * the possible incoming frontend's maxconns. |
| 9088 | */ |
| 9089 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 9090 | struct proxy *fe; |
| 9091 | int total = 0; |
| 9092 | |
| 9093 | /* sum up the number of maxconns of frontends which |
| 9094 | * reference this backend at least once or which are |
| 9095 | * the same one ('listen'). |
| 9096 | */ |
| 9097 | for (fe = proxy; fe; fe = fe->next) { |
| 9098 | struct switching_rule *rule; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9099 | int found = 0; |
| 9100 | |
| 9101 | if (!(fe->cap & PR_CAP_FE)) |
| 9102 | continue; |
| 9103 | |
| 9104 | if (fe == curproxy) /* we're on a "listen" instance */ |
| 9105 | found = 1; |
| 9106 | |
| 9107 | if (fe->defbe.be == curproxy) /* "default_backend" */ |
| 9108 | found = 1; |
| 9109 | |
| 9110 | /* check if a "use_backend" rule matches */ |
| 9111 | if (!found) { |
| 9112 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 9113 | if (!rule->dynamic && rule->be.backend == curproxy) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9114 | found = 1; |
| 9115 | break; |
| 9116 | } |
| 9117 | } |
| 9118 | } |
| 9119 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9120 | /* now we've checked all possible ways to reference a backend |
| 9121 | * from a frontend. |
| 9122 | */ |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9123 | if (!found) |
| 9124 | continue; |
| 9125 | total += fe->maxconn; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9126 | } |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9127 | /* we have the sum of the maxconns in <total>. We only |
| 9128 | * keep 10% of that sum to set the default fullconn, with |
| 9129 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9130 | */ |
| 9131 | curproxy->fullconn = (total + 9) / 10; |
| 9132 | if (!curproxy->fullconn) |
| 9133 | curproxy->fullconn = 1; |
| 9134 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9135 | } |
| 9136 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9137 | /* |
| 9138 | * Recount currently required checks. |
| 9139 | */ |
| 9140 | |
| 9141 | for (curproxy=proxy; curproxy; curproxy=curproxy->next) { |
| 9142 | int optnum; |
| 9143 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9144 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9145 | if (curproxy->options & cfg_opts[optnum].val) |
| 9146 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9147 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9148 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9149 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9150 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9151 | } |
| 9152 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9153 | /* compute the required process bindings for the peers */ |
| 9154 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) |
| 9155 | if (curproxy->table.peers.p) |
| 9156 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9157 | |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9158 | if (peers) { |
| 9159 | struct peers *curpeers = peers, **last; |
| 9160 | struct peer *p, *pb; |
| 9161 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9162 | /* Remove all peers sections which don't have a valid listener, |
| 9163 | * which are not used by any table, or which are bound to more |
| 9164 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9165 | */ |
| 9166 | last = &peers; |
| 9167 | while (*last) { |
| 9168 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9169 | |
| 9170 | if (curpeers->state == PR_STSTOPPED) { |
| 9171 | /* the "disabled" keyword was present */ |
| 9172 | if (curpeers->peers_fe) |
| 9173 | stop_proxy(curpeers->peers_fe); |
| 9174 | curpeers->peers_fe = NULL; |
| 9175 | } |
| 9176 | else if (!curpeers->peers_fe) { |
| 9177 | Warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9178 | curpeers->id, localpeer); |
| 9179 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9180 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9181 | /* either it's totally stopped or too much used */ |
| 9182 | if (curpeers->peers_fe->bind_proc) { |
| 9183 | Alert("Peers section '%s': peers referenced by sections " |
Willy Tarreau | 64c5722 | 2015-05-04 21:48:51 +0200 | [diff] [blame] | 9184 | "running in different processes (%d different ones). " |
| 9185 | "Check global.nbproc and all tables' bind-process " |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9186 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9187 | cfgerr++; |
| 9188 | } |
| 9189 | stop_proxy(curpeers->peers_fe); |
| 9190 | curpeers->peers_fe = NULL; |
| 9191 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9192 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9193 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9194 | last = &curpeers->next; |
| 9195 | continue; |
| 9196 | } |
| 9197 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9198 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9199 | p = curpeers->remote; |
| 9200 | while (p) { |
| 9201 | pb = p->next; |
| 9202 | free(p->id); |
| 9203 | free(p); |
| 9204 | p = pb; |
| 9205 | } |
| 9206 | |
| 9207 | /* Destroy and unlink this curpeers section. |
| 9208 | * Note: curpeers is backed up into *last. |
| 9209 | */ |
| 9210 | free(curpeers->id); |
| 9211 | curpeers = curpeers->next; |
| 9212 | free(*last); |
| 9213 | *last = curpeers; |
| 9214 | } |
| 9215 | } |
| 9216 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9217 | /* initialize stick-tables on backend capable proxies. This must not |
| 9218 | * be done earlier because the data size may be discovered while parsing |
| 9219 | * other proxies. |
| 9220 | */ |
| 9221 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9222 | if (curproxy->state == PR_STSTOPPED) |
| 9223 | continue; |
| 9224 | |
| 9225 | if (!stktable_init(&curproxy->table)) { |
| 9226 | Alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
| 9227 | cfgerr++; |
| 9228 | } |
| 9229 | } |
| 9230 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9231 | if (mailers) { |
| 9232 | struct mailers *curmailers = mailers, **last; |
| 9233 | struct mailer *m, *mb; |
| 9234 | |
| 9235 | /* Remove all mailers sections which don't have a valid listener. |
| 9236 | * This can happen when a mailers section is never referenced. |
| 9237 | */ |
| 9238 | last = &mailers; |
| 9239 | while (*last) { |
| 9240 | curmailers = *last; |
| 9241 | if (curmailers->users) { |
| 9242 | last = &curmailers->next; |
| 9243 | continue; |
| 9244 | } |
| 9245 | |
| 9246 | Warning("Removing incomplete section 'mailers %s'.\n", |
| 9247 | curmailers->id); |
| 9248 | |
| 9249 | m = curmailers->mailer_list; |
| 9250 | while (m) { |
| 9251 | mb = m->next; |
| 9252 | free(m->id); |
| 9253 | free(m); |
| 9254 | m = mb; |
| 9255 | } |
| 9256 | |
| 9257 | /* Destroy and unlink this curmailers section. |
| 9258 | * Note: curmailers is backed up into *last. |
| 9259 | */ |
| 9260 | free(curmailers->id); |
| 9261 | curmailers = curmailers->next; |
| 9262 | free(*last); |
| 9263 | *last = curmailers; |
| 9264 | } |
| 9265 | } |
| 9266 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9267 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9268 | * a server-state file locally defined and none has been provided */ |
| 9269 | for (curproxy = proxy; curproxy; curproxy = curproxy->next) { |
| 9270 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9271 | curproxy->server_state_file_name == NULL) |
| 9272 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9273 | } |
| 9274 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9275 | pool2_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9276 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9277 | MEM_F_SHARED); |
| 9278 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9279 | if (cfgerr > 0) |
| 9280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9281 | out: |
| 9282 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9283 | } |
| 9284 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9285 | /* |
| 9286 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9287 | * parsing sessions. |
| 9288 | */ |
| 9289 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9290 | { |
| 9291 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9292 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9293 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9294 | /* |
| 9295 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9296 | */ |
| 9297 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9298 | { |
| 9299 | LIST_DEL(&kwl->list); |
| 9300 | LIST_INIT(&kwl->list); |
| 9301 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9302 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9303 | /* this function register new section in the haproxy configuration file. |
| 9304 | * <section_name> is the name of this new section and <section_parser> |
| 9305 | * is the called parser. If two section declaration have the same name, |
| 9306 | * only the first declared is used. |
| 9307 | */ |
| 9308 | int cfg_register_section(char *section_name, |
| 9309 | int (*section_parser)(const char *, int, char **, int)) |
| 9310 | { |
| 9311 | struct cfg_section *cs; |
| 9312 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9313 | list_for_each_entry(cs, §ions, list) { |
| 9314 | if (strcmp(cs->section_name, section_name) == 0) { |
| 9315 | Alert("register section '%s': already registered.\n", section_name); |
| 9316 | return 0; |
| 9317 | } |
| 9318 | } |
| 9319 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9320 | cs = calloc(1, sizeof(*cs)); |
| 9321 | if (!cs) { |
| 9322 | Alert("register section '%s': out of memory.\n", section_name); |
| 9323 | return 0; |
| 9324 | } |
| 9325 | |
| 9326 | cs->section_name = section_name; |
| 9327 | cs->section_parser = section_parser; |
| 9328 | |
| 9329 | LIST_ADDQ(§ions, &cs->list); |
| 9330 | |
| 9331 | return 1; |
| 9332 | } |
| 9333 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9334 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9335 | * free all config section entries |
| 9336 | */ |
| 9337 | void cfg_unregister_sections(void) |
| 9338 | { |
| 9339 | struct cfg_section *cs, *ics; |
| 9340 | |
| 9341 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9342 | LIST_DEL(&cs->list); |
| 9343 | free(cs); |
| 9344 | } |
| 9345 | } |
| 9346 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9347 | void cfg_backup_sections(struct list *backup_sections) |
| 9348 | { |
| 9349 | struct cfg_section *cs, *ics; |
| 9350 | |
| 9351 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9352 | LIST_DEL(&cs->list); |
| 9353 | LIST_ADDQ(backup_sections, &cs->list); |
| 9354 | } |
| 9355 | } |
| 9356 | |
| 9357 | void cfg_restore_sections(struct list *backup_sections) |
| 9358 | { |
| 9359 | struct cfg_section *cs, *ics; |
| 9360 | |
| 9361 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9362 | LIST_DEL(&cs->list); |
| 9363 | LIST_ADDQ(§ions, &cs->list); |
| 9364 | } |
| 9365 | } |
| 9366 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9367 | __attribute__((constructor)) |
| 9368 | static void cfgparse_init(void) |
| 9369 | { |
| 9370 | /* Register internal sections */ |
| 9371 | cfg_register_section("listen", cfg_parse_listen); |
| 9372 | cfg_register_section("frontend", cfg_parse_listen); |
| 9373 | cfg_register_section("backend", cfg_parse_listen); |
| 9374 | cfg_register_section("defaults", cfg_parse_listen); |
| 9375 | cfg_register_section("global", cfg_parse_global); |
| 9376 | cfg_register_section("userlist", cfg_parse_users); |
| 9377 | cfg_register_section("peers", cfg_parse_peers); |
| 9378 | cfg_register_section("mailers", cfg_parse_mailers); |
| 9379 | cfg_register_section("namespace_list", cfg_parse_netns); |
| 9380 | cfg_register_section("resolvers", cfg_parse_resolvers); |
| 9381 | } |
| 9382 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9383 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9384 | * Local variables: |
| 9385 | * c-indent-level: 8 |
| 9386 | * c-basic-offset: 8 |
| 9387 | * End: |
| 9388 | */ |