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> |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 45 | #include <common/hathreads.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 46 | |
| 47 | #include <types/capture.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 48 | #include <types/compression.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 49 | #include <types/filters.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 50 | #include <types/global.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 51 | #include <types/obj_type.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 52 | #include <types/peers.h> |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 53 | #include <types/mailers.h> |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 54 | #include <types/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 55 | #include <types/stats.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 56 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 57 | #include <proto/acl.h> |
Christopher Faulet | 4fce0d8 | 2017-09-18 11:57:31 +0200 | [diff] [blame] | 58 | #include <proto/action.h> |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 59 | #include <proto/auth.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 61 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | #include <proto/checks.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 63 | #include <proto/compression.h> |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 64 | #include <proto/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 65 | #include <proto/stats.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 66 | #include <proto/filters.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 67 | #include <proto/frontend.h> |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 68 | #include <proto/hdr_idx.h> |
Willy Tarreau | 61c112a | 2018-10-02 16:43:32 +0200 | [diff] [blame] | 69 | #include <proto/http_rules.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 70 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 71 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 72 | #include <proto/lb_fwlc.h> |
| 73 | #include <proto/lb_fwrr.h> |
| 74 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 75 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 76 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 77 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 78 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 79 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 80 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 81 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 82 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 83 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 84 | #include <proto/stream.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 85 | #include <proto/stick_table.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 86 | #include <proto/task.h> |
| 87 | #include <proto/tcp_rules.h> |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 88 | #include <proto/connection.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 89 | |
| 90 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 91 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 92 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 93 | * |
| 94 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 95 | */ |
| 96 | const char sslv3_client_hello_pkt[] = { |
| 97 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 98 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 99 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 100 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 101 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 102 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 103 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 104 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 105 | "\x00" /* Session ID length : empty (no session ID) */ |
| 106 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 107 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 108 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 109 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 110 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 111 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 112 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 113 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 114 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 115 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 116 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 117 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 118 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 119 | }; |
| 120 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 121 | /* various keyword modifiers */ |
| 122 | enum kw_mod { |
| 123 | KWM_STD = 0, /* normal */ |
| 124 | KWM_NO, /* "no" prefixed before the keyword */ |
| 125 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 126 | }; |
| 127 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 128 | /* permit to store configuration section */ |
| 129 | struct cfg_section { |
| 130 | struct list list; |
| 131 | char *section_name; |
| 132 | int (*section_parser)(const char *, int, char **, int); |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 133 | int (*post_section_parser)(); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 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 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 141 | /* store post configuration parsing */ |
| 142 | |
| 143 | struct cfg_postparser { |
| 144 | struct list list; |
| 145 | char *name; |
| 146 | int (*func)(); |
| 147 | }; |
| 148 | |
| 149 | struct list postparsers = LIST_HEAD_INIT(postparsers); |
| 150 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 151 | /* 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] | 152 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 153 | const char *name; |
| 154 | unsigned int val; |
| 155 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 156 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 157 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | /* proxy->options */ |
| 161 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 162 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 163 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 164 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 165 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 166 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 167 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 168 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 169 | { "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] | 170 | { "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] | 171 | { "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] | 172 | { "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] | 173 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 174 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 175 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 176 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 177 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 178 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 179 | #else |
| 180 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 181 | #endif |
| 182 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 183 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 184 | }; |
| 185 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 186 | /* proxy->options2 */ |
| 187 | static const struct cfg_opt cfg_opts2[] = |
| 188 | { |
| 189 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 190 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 191 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 192 | { "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] | 193 | #else |
| 194 | { "splice-request", 0, 0, 0, 0 }, |
| 195 | { "splice-response", 0, 0, 0, 0 }, |
| 196 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 197 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 198 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 199 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 200 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 201 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 202 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 203 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 204 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 205 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 206 | { "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] | 207 | { "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] | 208 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Christopher Faulet | 98db976 | 2018-09-21 10:25:19 +0200 | [diff] [blame] | 209 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 210 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 68ad3a4 | 2018-10-22 11:49:15 +0200 | [diff] [blame] | 211 | { "http-use-htx", PR_O2_USE_HTX, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 212 | { NULL, 0, 0, 0 } |
| 213 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 214 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 215 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 217 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 218 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 219 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 220 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 221 | /* List head of all known configuration keywords */ |
| 222 | static struct cfg_kw_list cfg_keywords = { |
| 223 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 224 | }; |
| 225 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 226 | /* |
| 227 | * converts <str> to a list of listeners which are dynamically allocated. |
| 228 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 229 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 230 | * - <port> is a numerical port from 1 to 65535 ; |
| 231 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 232 | * 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] | 233 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 234 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 235 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 236 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 237 | 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] | 238 | { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 239 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | int port, end; |
| 241 | |
| 242 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 243 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 244 | while (next && *next) { |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 245 | int inherited = 0; |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 246 | struct sockaddr_storage *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 247 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 248 | |
| 249 | str = next; |
| 250 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 251 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 252 | *next++ = 0; |
| 253 | } |
| 254 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 255 | ss2 = str2sa_range(str, NULL, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 256 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 257 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 258 | if (!ss2) |
| 259 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 260 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 261 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 262 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 263 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 264 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 265 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 266 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 267 | if (!port || !end) { |
| 268 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 269 | goto fail; |
| 270 | } |
| 271 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 272 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 273 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 274 | goto fail; |
| 275 | } |
| 276 | |
| 277 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 278 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 279 | goto fail; |
| 280 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 281 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 282 | else if (ss2->ss_family == AF_UNSPEC) { |
| 283 | socklen_t addr_len; |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 284 | inherited = 1; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 285 | |
| 286 | /* We want to attach to an already bound fd whose number |
| 287 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 288 | * Note that by definition there is a single listener. |
| 289 | * We still have to determine the address family to |
| 290 | * register the correct protocol. |
| 291 | */ |
| 292 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 293 | addr_len = sizeof(*ss2); |
| 294 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 295 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 296 | goto fail; |
| 297 | } |
| 298 | |
| 299 | port = end = get_host_port(ss2); |
William Lallemand | 2fe7dd0 | 2018-09-11 16:51:29 +0200 | [diff] [blame] | 300 | |
| 301 | } else if (ss2->ss_family == AF_CUST_SOCKPAIR) { |
| 302 | socklen_t addr_len; |
| 303 | inherited = 1; |
| 304 | |
| 305 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 306 | addr_len = sizeof(*ss2); |
| 307 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 308 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 309 | goto fail; |
| 310 | } |
| 311 | |
| 312 | ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */ |
| 313 | port = end = 0; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 314 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 315 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 316 | /* OK the address looks correct */ |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 317 | if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) { |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 318 | memprintf(err, "%s for address '%s'.\n", *err, str); |
| 319 | goto fail; |
| 320 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 330 | * Report an error in <msg> when there are too many arguments. This version is |
| 331 | * intended to be used by keyword parsers so that the message will be included |
| 332 | * into the general error message. The index is the current keyword in args. |
| 333 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 334 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 335 | * message may also be null, it will simply not be produced (useful to check only). |
| 336 | * <msg> and <err_code> are only affected on error. |
| 337 | */ |
| 338 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 339 | { |
| 340 | int i; |
| 341 | |
| 342 | if (!*args[index + maxarg + 1]) |
| 343 | return 0; |
| 344 | |
| 345 | if (msg) { |
| 346 | *msg = NULL; |
| 347 | memprintf(msg, "%s", args[0]); |
| 348 | for (i = 1; i <= index; i++) |
| 349 | memprintf(msg, "%s %s", *msg, args[i]); |
| 350 | |
| 351 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 352 | } |
| 353 | if (err_code) |
| 354 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 355 | |
| 356 | return 1; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * same as too_many_args_idx with a 0 index |
| 361 | */ |
| 362 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 363 | { |
| 364 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 365 | } |
| 366 | |
| 367 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 368 | * Report a fatal Alert when there is too much arguments |
| 369 | * The index is the current keyword in args |
| 370 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 371 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 372 | */ |
| 373 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 374 | { |
| 375 | char *kw = NULL; |
| 376 | int i; |
| 377 | |
| 378 | if (!*args[index + maxarg + 1]) |
| 379 | return 0; |
| 380 | |
| 381 | memprintf(&kw, "%s", args[0]); |
| 382 | for (i = 1; i <= index; i++) { |
| 383 | memprintf(&kw, "%s %s", kw, args[i]); |
| 384 | } |
| 385 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 386 | ha_alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 387 | free(kw); |
| 388 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 389 | return 1; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * same as alertif_too_many_args_idx with a 0 index |
| 394 | */ |
| 395 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 396 | { |
| 397 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 398 | } |
| 399 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 400 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 401 | * Return 1 if the warning has been emitted, otherwise 0. |
| 402 | */ |
| 403 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 404 | { |
| 405 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 406 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 407 | file, line, arg); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 408 | return 1; |
| 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 413 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 414 | * Return 1 if the warning has been emitted, otherwise 0. |
| 415 | */ |
| 416 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 417 | { |
| 418 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 419 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 420 | file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 421 | return 1; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 426 | /* Report a warning if a rule is placed after a 'monitor fail' rule. |
| 427 | * Return 1 if the warning has been emitted, otherwise 0. |
| 428 | */ |
| 429 | int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
| 430 | { |
| 431 | if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { |
| 432 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", |
| 433 | file, line, arg); |
| 434 | return 1; |
| 435 | } |
| 436 | return 0; |
| 437 | } |
| 438 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 439 | /* Report a warning if a rule is placed after a 'block' rule. |
| 440 | * Return 1 if the warning has been emitted, otherwise 0. |
| 441 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 442 | 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] | 443 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 444 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 445 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 446 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 447 | return 1; |
| 448 | } |
| 449 | return 0; |
| 450 | } |
| 451 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 452 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 453 | * Return 1 if the warning has been emitted, otherwise 0. |
| 454 | */ |
| 455 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 456 | { |
| 457 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 458 | ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 459 | file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 460 | return 1; |
| 461 | } |
| 462 | return 0; |
| 463 | } |
| 464 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 465 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 466 | * Return 1 if the warning has been emitted, otherwise 0. |
| 467 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 468 | 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] | 469 | { |
| 470 | if (proxy->req_exp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 471 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 472 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 473 | return 1; |
| 474 | } |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | /* Report a warning if a rule is placed after a reqadd rule. |
| 479 | * Return 1 if the warning has been emitted, otherwise 0. |
| 480 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 481 | 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] | 482 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 483 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 484 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 485 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 486 | return 1; |
| 487 | } |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | /* Report a warning if a rule is placed after a redirect rule. |
| 492 | * Return 1 if the warning has been emitted, otherwise 0. |
| 493 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 494 | 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] | 495 | { |
| 496 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 497 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 498 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 499 | return 1; |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 505 | * Return 1 if the warning has been emitted, otherwise 0. |
| 506 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 507 | 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] | 508 | { |
| 509 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 510 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 511 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 512 | return 1; |
| 513 | } |
| 514 | return 0; |
| 515 | } |
| 516 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 517 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 518 | * Return 1 if the warning has been emitted, otherwise 0. |
| 519 | */ |
| 520 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 521 | { |
| 522 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 523 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 524 | file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 525 | return 1; |
| 526 | } |
| 527 | return 0; |
| 528 | } |
| 529 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 530 | /* report a warning if a redirect rule is dangerously placed */ |
| 531 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 532 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 533 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 534 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 535 | } |
| 536 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 537 | /* report a warning if a reqadd rule is dangerously placed */ |
| 538 | int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 539 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 540 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 541 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 544 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 545 | 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] | 546 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 547 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 548 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /* report a warning if an http-request rule is dangerously placed */ |
| 552 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 553 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 554 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 555 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 556 | } |
| 557 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 558 | /* report a warning if a block rule is dangerously placed */ |
| 559 | 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] | 560 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 561 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 562 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 563 | } |
| 564 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 565 | /* report a warning if a block rule is dangerously placed */ |
| 566 | int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 567 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 568 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 569 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 572 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 573 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 574 | { |
| 575 | return warnif_rule_after_monitor(proxy, file, line, arg) || |
| 576 | warnif_misplaced_monitor(proxy, file, line, arg); |
| 577 | } |
| 578 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 579 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 580 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 581 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 582 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 583 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 584 | } |
| 585 | |
| 586 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 587 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 588 | { |
| 589 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 590 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 593 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 594 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 595 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 596 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 597 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 598 | 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] | 599 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 600 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 601 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 602 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 603 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 604 | return 0; |
| 605 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 606 | acl = acl_cond_conflicts(cond, where); |
| 607 | if (acl) { |
| 608 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 609 | ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 610 | file, line, acl->name, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 611 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 612 | ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
| 613 | 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] | 614 | return ERR_WARN; |
| 615 | } |
| 616 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 617 | return 0; |
| 618 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 619 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 620 | ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
| 621 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 622 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 623 | ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
| 624 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 625 | return ERR_WARN; |
| 626 | } |
| 627 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 628 | /* Parse a string representing a process number or a set of processes. It must |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 629 | * be "all", "odd", "even", a number between 1 and <LONGBITS> or a range with |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 630 | * two such numbers delimited by a dash ('-'). On success, it returns |
| 631 | * 0. otherwise it returns 1 with an error message in <err>. |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 632 | * |
| 633 | * Note: this function can also be used to parse a thread number or a set of |
| 634 | * threads. |
| 635 | */ |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 636 | int parse_process_number(const char *arg, unsigned long *proc, int *autoinc, char **err) |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 637 | { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 638 | if (autoinc) { |
| 639 | *autoinc = 0; |
| 640 | if (strncmp(arg, "auto:", 5) == 0) { |
| 641 | arg += 5; |
| 642 | *autoinc = 1; |
| 643 | } |
| 644 | } |
| 645 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 646 | if (strcmp(arg, "all") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 647 | *proc |= ~0UL; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 648 | else if (strcmp(arg, "odd") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 649 | *proc |= ~0UL/3UL; /* 0x555....555 */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 650 | else if (strcmp(arg, "even") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 651 | *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 652 | else { |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 653 | char *dash; |
| 654 | unsigned int low, high; |
| 655 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 656 | if (!isdigit((int)*arg)) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 657 | memprintf(err, "'%s' is not a valid number.\n", arg); |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 658 | return -1; |
| 659 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 660 | |
| 661 | low = high = str2uic(arg); |
| 662 | if ((dash = strchr(arg, '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 663 | high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1)); |
| 664 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 665 | if (high < low) { |
| 666 | unsigned int swap = low; |
| 667 | low = high; |
| 668 | high = swap; |
| 669 | } |
| 670 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 671 | if (low < 1 || low > LONGBITS || high > LONGBITS) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 672 | memprintf(err, "'%s' is not a valid number/range." |
| 673 | " It supports numbers from 1 to %d.\n", |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 674 | arg, LONGBITS); |
| 675 | return 1; |
| 676 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 677 | |
| 678 | for (;low <= high; low++) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 679 | *proc |= 1UL << (low-1); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 680 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 681 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 682 | return 0; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 683 | } |
| 684 | |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 685 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 686 | /* Parse cpu sets. Each CPU set is either a unique number between 0 and |
| 687 | * <LONGBITS> or a range with two such numbers delimited by a dash |
| 688 | * ('-'). Multiple CPU numbers or ranges may be specified. On success, it |
| 689 | * returns 0. otherwise it returns 1 with an error message in <err>. |
| 690 | */ |
| 691 | static unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err) |
| 692 | { |
| 693 | int cur_arg = 0; |
| 694 | |
| 695 | *cpu_set = 0; |
| 696 | while (*args[cur_arg]) { |
| 697 | char *dash; |
| 698 | unsigned int low, high; |
| 699 | |
| 700 | if (!isdigit((int)*args[cur_arg])) { |
| 701 | memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]); |
| 702 | return -1; |
| 703 | } |
| 704 | |
| 705 | low = high = str2uic(args[cur_arg]); |
| 706 | if ((dash = strchr(args[cur_arg], '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 707 | high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1)); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 708 | |
| 709 | if (high < low) { |
| 710 | unsigned int swap = low; |
| 711 | low = high; |
| 712 | high = swap; |
| 713 | } |
| 714 | |
| 715 | if (high >= LONGBITS) { |
| 716 | memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1); |
| 717 | return 1; |
| 718 | } |
| 719 | |
| 720 | while (low <= high) |
| 721 | *cpu_set |= 1UL << low++; |
| 722 | |
| 723 | cur_arg++; |
| 724 | } |
| 725 | return 0; |
| 726 | } |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 727 | #endif |
| 728 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 729 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 730 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 731 | * any combination of : |
| 732 | * - ERR_ABORT: must abort ASAP |
| 733 | * - ERR_FATAL: we can continue parsing but not start the service |
| 734 | * - ERR_WARN: a warning has been emitted |
| 735 | * - ERR_ALERT: an alert has been emitted |
| 736 | * Only the two first ones can stop processing, the two others are just |
| 737 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 738 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 739 | 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] | 740 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 741 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 742 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 743 | |
| 744 | if (!strcmp(args[0], "global")) { /* new section */ |
| 745 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 746 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 747 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 748 | } |
| 749 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 750 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 751 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 752 | global.mode |= MODE_DAEMON; |
| 753 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 754 | else if (!strcmp(args[0], "master-worker")) { |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 755 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 756 | goto out; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 757 | if (*args[1]) { |
William Lallemand | 4cfede8 | 2017-11-24 22:02:34 +0100 | [diff] [blame] | 758 | if (!strcmp(args[1], "no-exit-on-failure")) { |
| 759 | global.tune.options |= GTUNE_NOEXIT_ONFAILURE; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 760 | } else { |
Tim Duesterhus | c578d9a | 2017-12-05 18:14:12 +0100 | [diff] [blame] | 761 | ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]); |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 763 | goto out; |
| 764 | } |
| 765 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 766 | global.mode |= MODE_MWORKER; |
| 767 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 768 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 769 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 770 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 771 | global.mode |= MODE_DEBUG; |
| 772 | } |
| 773 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 774 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 775 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 776 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 777 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 778 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 779 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 780 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 781 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 782 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 783 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 784 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 785 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 786 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 787 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 788 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 789 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 790 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 791 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 792 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 793 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 794 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 795 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 796 | global.tune.options &= ~GTUNE_USE_GAI; |
| 797 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 798 | else if (!strcmp(args[0], "noreuseport")) { |
| 799 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 800 | goto out; |
| 801 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 802 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 803 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 804 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 805 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 806 | global.mode |= MODE_QUIET; |
| 807 | } |
Olivier Houchard | 1599b80 | 2018-05-24 18:59:04 +0200 | [diff] [blame] | 808 | else if (!strcmp(args[0], "tune.runqueue-depth")) { |
| 809 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 810 | goto out; |
| 811 | if (global.tune.runqueue_depth != 0) { |
| 812 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 813 | err_code |= ERR_ALERT; |
| 814 | goto out; |
| 815 | } |
| 816 | if (*(args[1]) == 0) { |
| 817 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 819 | goto out; |
| 820 | } |
| 821 | global.tune.runqueue_depth = atol(args[1]); |
| 822 | |
| 823 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 824 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 825 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 826 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 827 | if (global.tune.maxpollevents != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 828 | ha_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] | 829 | err_code |= ERR_ALERT; |
| 830 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 831 | } |
| 832 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 833 | ha_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] | 834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 835 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 836 | } |
| 837 | global.tune.maxpollevents = atol(args[1]); |
| 838 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 839 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 840 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 841 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 842 | if (global.tune.maxaccept != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 843 | ha_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] | 844 | err_code |= ERR_ALERT; |
| 845 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 846 | } |
| 847 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 848 | ha_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] | 849 | err_code |= ERR_ALERT | ERR_FATAL; |
| 850 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 851 | } |
| 852 | global.tune.maxaccept = atol(args[1]); |
| 853 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 854 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 855 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 856 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 857 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 858 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 860 | goto out; |
| 861 | } |
| 862 | global.tune.chksize = atol(args[1]); |
| 863 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 864 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 865 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 866 | goto out; |
| 867 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 868 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 869 | err_code |= ERR_ALERT | ERR_FATAL; |
| 870 | goto out; |
| 871 | } |
| 872 | global.tune.recv_enough = atol(args[1]); |
| 873 | } |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 874 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 875 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 876 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 877 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 878 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto out; |
| 881 | } |
| 882 | global.tune.buf_limit = atol(args[1]); |
| 883 | if (global.tune.buf_limit) { |
| 884 | if (global.tune.buf_limit < 3) |
| 885 | global.tune.buf_limit = 3; |
| 886 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 887 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 888 | } |
| 889 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 890 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 891 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 892 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 893 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 894 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 896 | goto out; |
| 897 | } |
| 898 | global.tune.reserved_bufs = atol(args[1]); |
| 899 | if (global.tune.reserved_bufs < 2) |
| 900 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 901 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 902 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 903 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 904 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 905 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 906 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 907 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 908 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 910 | goto out; |
| 911 | } |
| 912 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 913 | if (global.tune.bufsize <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 914 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 915 | err_code |= ERR_ALERT | ERR_FATAL; |
| 916 | goto out; |
| 917 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 918 | } |
| 919 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 920 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 921 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 922 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 923 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 925 | goto out; |
| 926 | } |
| 927 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 928 | if (global.tune.maxrewrite < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 929 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 930 | err_code |= ERR_ALERT | ERR_FATAL; |
| 931 | goto out; |
| 932 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 933 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 934 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 935 | unsigned int idle; |
| 936 | const char *res; |
| 937 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 938 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 939 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 940 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 941 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 943 | goto out; |
| 944 | } |
| 945 | |
| 946 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 947 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 948 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 949 | file, linenum, *res, args[0]); |
| 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
| 952 | } |
| 953 | |
| 954 | if (idle > 65535) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 955 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto out; |
| 958 | } |
| 959 | global.tune.idle_timer = idle; |
| 960 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 961 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 962 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 963 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 964 | if (global.tune.client_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 965 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 966 | err_code |= ERR_ALERT; |
| 967 | goto out; |
| 968 | } |
| 969 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 970 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 972 | goto out; |
| 973 | } |
| 974 | global.tune.client_rcvbuf = atol(args[1]); |
| 975 | } |
| 976 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 977 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 978 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 979 | if (global.tune.server_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 980 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 981 | err_code |= ERR_ALERT; |
| 982 | goto out; |
| 983 | } |
| 984 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 985 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 987 | goto out; |
| 988 | } |
| 989 | global.tune.server_rcvbuf = atol(args[1]); |
| 990 | } |
| 991 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 992 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 993 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 994 | if (global.tune.client_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 995 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 996 | err_code |= ERR_ALERT; |
| 997 | goto out; |
| 998 | } |
| 999 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1000 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | global.tune.client_sndbuf = atol(args[1]); |
| 1005 | } |
| 1006 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1007 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1008 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1009 | if (global.tune.server_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1010 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1011 | err_code |= ERR_ALERT; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1015 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1017 | goto out; |
| 1018 | } |
| 1019 | global.tune.server_sndbuf = atol(args[1]); |
| 1020 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1021 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1022 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1023 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1024 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1025 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1026 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1027 | goto out; |
| 1028 | } |
| 1029 | global.tune.pipesize = atol(args[1]); |
| 1030 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1031 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1032 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1033 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1034 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1035 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1036 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1037 | goto out; |
| 1038 | } |
| 1039 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1040 | } |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 1041 | else if (!strcmp(args[0], "tune.http.logurilen")) { |
| 1042 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1043 | goto out; |
| 1044 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1045 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 1046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1047 | goto out; |
| 1048 | } |
| 1049 | global.tune.requri_len = atol(args[1]) + 1; |
| 1050 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1051 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1052 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1053 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1054 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1055 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1056 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1057 | goto out; |
| 1058 | } |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1059 | global.tune.max_http_hdr = atoi(args[1]); |
| 1060 | if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1061 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 1062 | file, linenum, args[0]); |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1063 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1064 | goto out; |
| 1065 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1066 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1067 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1068 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1069 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1070 | if (*args[1]) { |
| 1071 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1072 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1073 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1074 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1079 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1080 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1082 | goto out; |
| 1083 | } |
| 1084 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1085 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1086 | if (*args[1]) { |
| 1087 | global.tune.pattern_cache = atoi(args[1]); |
| 1088 | if (global.tune.pattern_cache < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1089 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1090 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1091 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1092 | goto out; |
| 1093 | } |
| 1094 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1095 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1096 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1098 | goto out; |
| 1099 | } |
| 1100 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1101 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1102 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1103 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1104 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1105 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1106 | err_code |= ERR_ALERT; |
| 1107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1108 | } |
| 1109 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1110 | ha_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] | 1111 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1112 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1113 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1114 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1115 | ha_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]); |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1116 | err_code |= ERR_WARN; |
| 1117 | goto out; |
| 1118 | } |
| 1119 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1120 | } |
| 1121 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1122 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1123 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1124 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1125 | ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1126 | err_code |= ERR_ALERT; |
| 1127 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1128 | } |
| 1129 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1130 | ha_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] | 1131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1132 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1133 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1134 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1135 | ha_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]); |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1136 | err_code |= ERR_WARN; |
| 1137 | goto out; |
| 1138 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1139 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1140 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1141 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1142 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1143 | global.external_check = 1; |
| 1144 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1145 | /* user/group name handling */ |
| 1146 | else if (!strcmp(args[0], "user")) { |
| 1147 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1148 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1149 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1150 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1151 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1152 | err_code |= ERR_ALERT; |
| 1153 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1154 | } |
| 1155 | errno = 0; |
| 1156 | ha_user = getpwnam(args[1]); |
| 1157 | if (ha_user != NULL) { |
| 1158 | global.uid = (int)ha_user->pw_uid; |
| 1159 | } |
| 1160 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1161 | ha_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] | 1162 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | else if (!strcmp(args[0], "group")) { |
| 1166 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1167 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1168 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1169 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1170 | ha_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] | 1171 | err_code |= ERR_ALERT; |
| 1172 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1173 | } |
| 1174 | errno = 0; |
| 1175 | ha_group = getgrnam(args[1]); |
| 1176 | if (ha_group != NULL) { |
| 1177 | global.gid = (int)ha_group->gr_gid; |
| 1178 | } |
| 1179 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1180 | ha_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] | 1181 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1185 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1186 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1187 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1188 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1189 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1191 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1192 | } |
| 1193 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1194 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1195 | ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1196 | file, linenum, args[0], LONGBITS, global.nbproc); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1198 | goto out; |
| 1199 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1200 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1201 | else if (!strcmp(args[0], "nbthread")) { |
| 1202 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1203 | goto out; |
| 1204 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1205 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1207 | goto out; |
| 1208 | } |
Willy Tarreau | 0ccd322 | 2018-07-30 10:34:35 +0200 | [diff] [blame] | 1209 | global.nbthread = parse_nbthread(args[1], &errmsg); |
| 1210 | if (!global.nbthread) { |
| 1211 | ha_alert("parsing [%s:%d] : '%s' %s.\n", |
| 1212 | file, linenum, args[0], errmsg); |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1214 | goto out; |
| 1215 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1216 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1217 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1218 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1219 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1220 | if (global.maxconn != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1221 | ha_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] | 1222 | err_code |= ERR_ALERT; |
| 1223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1224 | } |
| 1225 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1226 | ha_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] | 1227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1228 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1229 | } |
| 1230 | global.maxconn = atol(args[1]); |
| 1231 | #ifdef SYSTEM_MAXCONN |
| 1232 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1233 | ha_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); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1234 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1235 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1236 | } |
| 1237 | #endif /* SYSTEM_MAXCONN */ |
| 1238 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1239 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1240 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1241 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1242 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1243 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1245 | goto out; |
| 1246 | } |
| 1247 | if (strcmp(args[1],"none") == 0) |
| 1248 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1249 | else if (strcmp(args[1],"required") == 0) |
| 1250 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1251 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1252 | ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1254 | goto out; |
| 1255 | } |
| 1256 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1257 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1258 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1259 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1260 | if (global.cps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1261 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1262 | err_code |= ERR_ALERT; |
| 1263 | goto out; |
| 1264 | } |
| 1265 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1266 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1268 | goto out; |
| 1269 | } |
| 1270 | global.cps_lim = atol(args[1]); |
| 1271 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1272 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1273 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1274 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1275 | if (global.sps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1276 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1277 | err_code |= ERR_ALERT; |
| 1278 | goto out; |
| 1279 | } |
| 1280 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1281 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1283 | goto out; |
| 1284 | } |
| 1285 | global.sps_lim = atol(args[1]); |
| 1286 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1287 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1288 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1289 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1290 | if (global.ssl_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1291 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1292 | err_code |= ERR_ALERT; |
| 1293 | goto out; |
| 1294 | } |
| 1295 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1296 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1298 | goto out; |
| 1299 | } |
| 1300 | global.ssl_lim = atol(args[1]); |
| 1301 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1302 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1303 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1304 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1305 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1306 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1308 | goto out; |
| 1309 | } |
| 1310 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1311 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1312 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1313 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1314 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1315 | if (global.maxpipes != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1316 | ha_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] | 1317 | err_code |= ERR_ALERT; |
| 1318 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1319 | } |
| 1320 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1321 | ha_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] | 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1323 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1324 | } |
| 1325 | global.maxpipes = atol(args[1]); |
| 1326 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1327 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1328 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1329 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1330 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1331 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1332 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1333 | goto out; |
| 1334 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1335 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1336 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1337 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1338 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1339 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1340 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1341 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1343 | goto out; |
| 1344 | } |
| 1345 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1346 | if (compress_min_idle > 100) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1347 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1349 | goto out; |
| 1350 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1351 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1352 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1353 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1354 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1355 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1356 | if (global.rlimit_nofile != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1357 | ha_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] | 1358 | err_code |= ERR_ALERT; |
| 1359 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1360 | } |
| 1361 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1362 | ha_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] | 1363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1364 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1365 | } |
| 1366 | global.rlimit_nofile = atol(args[1]); |
| 1367 | } |
| 1368 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1369 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1370 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1371 | if (global.chroot != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1372 | ha_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] | 1373 | err_code |= ERR_ALERT; |
| 1374 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1375 | } |
| 1376 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1377 | ha_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] | 1378 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1379 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1380 | } |
| 1381 | global.chroot = strdup(args[1]); |
| 1382 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1383 | else if (!strcmp(args[0], "description")) { |
| 1384 | int i, len=0; |
| 1385 | char *d; |
| 1386 | |
| 1387 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1388 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1389 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1391 | goto out; |
| 1392 | } |
| 1393 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1394 | for (i = 1; *args[i]; i++) |
| 1395 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1396 | |
| 1397 | if (global.desc) |
| 1398 | free(global.desc); |
| 1399 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1400 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1401 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1402 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1403 | for (i = 2; *args[i]; i++) |
| 1404 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1405 | } |
| 1406 | else if (!strcmp(args[0], "node")) { |
| 1407 | int i; |
| 1408 | char c; |
| 1409 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1410 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1411 | goto out; |
| 1412 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1413 | for (i=0; args[1][i]; i++) { |
| 1414 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1415 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1416 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1417 | break; |
| 1418 | } |
| 1419 | |
| 1420 | if (!i || args[1][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1421 | ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1422 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1423 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1425 | goto out; |
| 1426 | } |
| 1427 | |
| 1428 | if (global.node) |
| 1429 | free(global.node); |
| 1430 | |
| 1431 | global.node = strdup(args[1]); |
| 1432 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1433 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1434 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1435 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1436 | if (global.pidfile != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1437 | ha_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] | 1438 | err_code |= ERR_ALERT; |
| 1439 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1440 | } |
| 1441 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1442 | ha_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] | 1443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1444 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1445 | } |
| 1446 | global.pidfile = strdup(args[1]); |
| 1447 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1448 | else if (!strcmp(args[0], "unix-bind")) { |
| 1449 | int cur_arg = 1; |
| 1450 | while (*(args[cur_arg])) { |
| 1451 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1452 | if (global.unix_bind.prefix != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1453 | ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1454 | err_code |= ERR_ALERT; |
| 1455 | cur_arg += 2; |
| 1456 | continue; |
| 1457 | } |
| 1458 | |
| 1459 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1460 | ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1462 | goto out; |
| 1463 | } |
| 1464 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1465 | cur_arg += 2; |
| 1466 | continue; |
| 1467 | } |
| 1468 | |
| 1469 | if (!strcmp(args[cur_arg], "mode")) { |
| 1470 | |
| 1471 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1472 | cur_arg += 2; |
| 1473 | continue; |
| 1474 | } |
| 1475 | |
| 1476 | if (!strcmp(args[cur_arg], "uid")) { |
| 1477 | |
| 1478 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1479 | cur_arg += 2; |
| 1480 | continue; |
| 1481 | } |
| 1482 | |
| 1483 | if (!strcmp(args[cur_arg], "gid")) { |
| 1484 | |
| 1485 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1486 | cur_arg += 2; |
| 1487 | continue; |
| 1488 | } |
| 1489 | |
| 1490 | if (!strcmp(args[cur_arg], "user")) { |
| 1491 | struct passwd *user; |
| 1492 | |
| 1493 | user = getpwnam(args[cur_arg + 1]); |
| 1494 | if (!user) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1495 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1496 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1498 | goto out; |
| 1499 | } |
| 1500 | |
| 1501 | global.unix_bind.ux.uid = user->pw_uid; |
| 1502 | cur_arg += 2; |
| 1503 | continue; |
| 1504 | } |
| 1505 | |
| 1506 | if (!strcmp(args[cur_arg], "group")) { |
| 1507 | struct group *group; |
| 1508 | |
| 1509 | group = getgrnam(args[cur_arg + 1]); |
| 1510 | if (!group) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1511 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1512 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1514 | goto out; |
| 1515 | } |
| 1516 | |
| 1517 | global.unix_bind.ux.gid = group->gr_gid; |
| 1518 | cur_arg += 2; |
| 1519 | continue; |
| 1520 | } |
| 1521 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1522 | ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
| 1523 | file, linenum, args[0]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1525 | goto out; |
| 1526 | } |
| 1527 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 1528 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 1529 | if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 1530 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1531 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1532 | goto out; |
| 1533 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1534 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1535 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1536 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1537 | |
| 1538 | if (global.log_send_hostname != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1539 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1540 | err_code |= ERR_ALERT; |
| 1541 | goto out; |
| 1542 | } |
| 1543 | |
| 1544 | if (*(args[1])) |
| 1545 | name = args[1]; |
| 1546 | else |
| 1547 | name = hostname; |
| 1548 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1549 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1550 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1551 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1552 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1553 | if (global.server_state_base != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1554 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1555 | err_code |= ERR_ALERT; |
| 1556 | goto out; |
| 1557 | } |
| 1558 | |
| 1559 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1560 | ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1561 | err_code |= ERR_FATAL; |
| 1562 | goto out; |
| 1563 | } |
| 1564 | |
| 1565 | global.server_state_base = strdup(args[1]); |
| 1566 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1567 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1568 | if (global.server_state_file != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1569 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1570 | err_code |= ERR_ALERT; |
| 1571 | goto out; |
| 1572 | } |
| 1573 | |
| 1574 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1575 | ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1576 | err_code |= ERR_FATAL; |
| 1577 | goto out; |
| 1578 | } |
| 1579 | |
| 1580 | global.server_state_file = strdup(args[1]); |
| 1581 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1582 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1583 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1584 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1585 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1586 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1587 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1588 | goto out; |
| 1589 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1590 | chunk_destroy(&global.log_tag); |
| 1591 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1592 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1593 | 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] | 1594 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1595 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1596 | if (global.spread_checks != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1597 | ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1598 | err_code |= ERR_ALERT; |
| 1599 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1600 | } |
| 1601 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1602 | ha_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] | 1603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1604 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1605 | } |
| 1606 | global.spread_checks = atol(args[1]); |
| 1607 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1608 | ha_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] | 1609 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1610 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1611 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1612 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1613 | const char *err; |
| 1614 | unsigned int val; |
| 1615 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1616 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1617 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1618 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1619 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1621 | goto out; |
| 1622 | } |
| 1623 | |
| 1624 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1625 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1626 | ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1628 | } |
| 1629 | global.max_spread_checks = val; |
| 1630 | if (global.max_spread_checks < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1631 | ha_alert("parsing [%s:%d]: '%s' needs a positive delay in milliseconds.\n",file, linenum, args[0]); |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1633 | } |
| 1634 | } |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1635 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 1636 | /* map a process list to a CPU set */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1637 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1638 | char *slash; |
| 1639 | unsigned long proc = 0, thread = 0, cpus; |
| 1640 | int i, j, n, autoinc; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1641 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1642 | if (!*args[1] || !*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1643 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 1644 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 1645 | " followed by a list of CPU ranges with numbers from 0 to %d.\n", |
| 1646 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1648 | goto out; |
| 1649 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1650 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1651 | if ((slash = strchr(args[1], '/')) != NULL) |
| 1652 | *slash = 0; |
| 1653 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1654 | if (parse_process_number(args[1], &proc, &autoinc, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1655 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1657 | goto out; |
| 1658 | } |
| 1659 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1660 | if (slash) { |
| 1661 | if (parse_process_number(slash+1, &thread, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1662 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1664 | goto out; |
| 1665 | } |
| 1666 | *slash = '/'; |
| 1667 | |
Willy Tarreau | 9504dd6 | 2018-10-15 09:37:03 +0200 | [diff] [blame] | 1668 | if (autoinc && atleast2(proc) && atleast2(thread)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1669 | ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind " |
| 1670 | "a process range _AND_ a thread range\n", |
| 1671 | file, linenum, args[0], args[1]); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1673 | goto out; |
| 1674 | } |
| 1675 | } |
| 1676 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1677 | if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1678 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1680 | goto out; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1681 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1682 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1683 | if (autoinc && |
| 1684 | my_popcountl(proc) != my_popcountl(cpus) && |
| 1685 | my_popcountl(thread) != my_popcountl(cpus)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1686 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1687 | "must have the same size to be automatically bound\n", |
| 1688 | file, linenum, args[0]); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1689 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1690 | goto out; |
| 1691 | } |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1692 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1693 | for (i = n = 0; i < LONGBITS; i++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1694 | /* No mapping for this process */ |
| 1695 | if (!(proc & (1UL << i))) |
| 1696 | continue; |
| 1697 | |
| 1698 | /* Mapping at the process level */ |
| 1699 | if (!thread) { |
| 1700 | if (!autoinc) |
| 1701 | global.cpu_map.proc[i] = cpus; |
| 1702 | else { |
| 1703 | n += my_ffsl(cpus >> n); |
| 1704 | global.cpu_map.proc[i] = (1UL << (n-1)); |
| 1705 | } |
| 1706 | continue; |
| 1707 | } |
| 1708 | |
| 1709 | /* Mapping at the thread level */ |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1710 | for (j = 0; j < MAX_THREADS; j++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1711 | /* Np mapping for this thread */ |
| 1712 | if (!(thread & (1UL << j))) |
| 1713 | continue; |
| 1714 | |
| 1715 | if (!autoinc) |
| 1716 | global.cpu_map.thread[i][j] = cpus; |
| 1717 | else { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1718 | n += my_ffsl(cpus >> n); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1719 | global.cpu_map.thread[i][j] = (1UL << (n-1)); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1720 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1721 | } |
| 1722 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1723 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1724 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1725 | file, linenum, args[0]); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1727 | goto out; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1728 | #endif /* ! USE_CPU_AFFINITY */ |
| 1729 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1730 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1731 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1732 | goto out; |
| 1733 | |
| 1734 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1735 | ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1736 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1737 | goto out; |
| 1738 | } |
| 1739 | |
| 1740 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1741 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1742 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1744 | goto out; |
| 1745 | } |
| 1746 | } |
| 1747 | else if (!strcmp(args[0], "unsetenv")) { |
| 1748 | int arg; |
| 1749 | |
| 1750 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1751 | ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1753 | goto out; |
| 1754 | } |
| 1755 | |
| 1756 | for (arg = 1; *args[arg]; arg++) { |
| 1757 | if (unsetenv(args[arg]) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1758 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1759 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1760 | goto out; |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | else if (!strcmp(args[0], "resetenv")) { |
| 1765 | extern char **environ; |
| 1766 | char **env = environ; |
| 1767 | |
| 1768 | /* args contain variable names to keep, one per argument */ |
| 1769 | while (*env) { |
| 1770 | int arg; |
| 1771 | |
| 1772 | /* look for current variable in among all those we want to keep */ |
| 1773 | for (arg = 1; *args[arg]; arg++) { |
| 1774 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1775 | (*env)[strlen(args[arg])] == '=') |
| 1776 | break; |
| 1777 | } |
| 1778 | |
| 1779 | /* delete this variable */ |
| 1780 | if (!*args[arg]) { |
| 1781 | char *delim = strchr(*env, '='); |
| 1782 | |
| 1783 | if (!delim || delim - *env >= trash.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1784 | ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
| 1787 | } |
| 1788 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1789 | memcpy(trash.area, *env, delim - *env); |
| 1790 | trash.area[delim - *env] = 0; |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1791 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1792 | if (unsetenv(trash.area) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1793 | ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1794 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1795 | goto out; |
| 1796 | } |
| 1797 | } |
| 1798 | else |
| 1799 | env++; |
| 1800 | } |
| 1801 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1802 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1803 | struct cfg_kw_list *kwl; |
| 1804 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1805 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1806 | |
| 1807 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1808 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1809 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1810 | continue; |
| 1811 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1812 | 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] | 1813 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1814 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1815 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1816 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1817 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1818 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1819 | err_code |= ERR_WARN; |
| 1820 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1821 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1822 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | } |
| 1826 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1827 | ha_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] | 1828 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1829 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1830 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1831 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1832 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1833 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1836 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1837 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1838 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1839 | defproxy.mode = PR_MODE_TCP; |
| 1840 | defproxy.state = PR_STNEW; |
| 1841 | defproxy.maxconn = cfg_maxpconn; |
| 1842 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1843 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1844 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1845 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1846 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1847 | defproxy.defsrv.check.fastinter = 0; |
| 1848 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1849 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1850 | defproxy.defsrv.agent.fastinter = 0; |
| 1851 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1852 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1853 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1854 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1855 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1856 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1857 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1858 | defproxy.defsrv.maxqueue = 0; |
| 1859 | defproxy.defsrv.minconn = 0; |
| 1860 | defproxy.defsrv.maxconn = 0; |
| 1861 | defproxy.defsrv.slowstart = 0; |
| 1862 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1863 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1864 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1865 | |
| 1866 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1867 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1870 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1871 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1872 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1873 | * ERR_FATAL in case of error. |
| 1874 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1875 | static int create_cond_regex_rule(const char *file, int line, |
| 1876 | struct proxy *px, int dir, int action, int flags, |
| 1877 | const char *cmd, const char *reg, const char *repl, |
| 1878 | const char **cond_start) |
| 1879 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1880 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1881 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1882 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1883 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1884 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1885 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1886 | int cs; |
| 1887 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1888 | |
| 1889 | if (px == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1890 | ha_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] | 1891 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1892 | goto err; |
| 1893 | } |
| 1894 | |
| 1895 | if (*reg == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1896 | ha_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] | 1897 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1898 | goto err; |
| 1899 | } |
| 1900 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1901 | 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] | 1902 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1903 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1904 | if (cond_start && |
| 1905 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 1906 | if ((cond = build_acl_cond(file, line, &px->acl, px, cond_start, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1907 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1908 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1909 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1910 | goto err; |
| 1911 | } |
| 1912 | } |
| 1913 | else if (cond_start && **cond_start) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1914 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1915 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1916 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1917 | goto err; |
| 1918 | } |
| 1919 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1920 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1921 | (dir == SMP_OPT_DIR_REQ) ? |
| 1922 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1923 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1924 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1925 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1926 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1927 | if (!preg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1928 | ha_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] | 1929 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1930 | goto err; |
| 1931 | } |
| 1932 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1933 | cs = !(flags & REG_ICASE); |
| 1934 | cap = !(flags & REG_NOSUB); |
| 1935 | error = NULL; |
| 1936 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1937 | ha_alert("parsing [%s:%d] : '%s' : regular expression '%s' : %s\n", file, line, cmd, reg, error); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1938 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1939 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1940 | goto err; |
| 1941 | } |
| 1942 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1943 | 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] | 1944 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1945 | if (repl && err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1946 | ha_alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1947 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1948 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1949 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1952 | 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] | 1953 | ret_code |= ERR_WARN; |
| 1954 | |
| 1955 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1956 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1957 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1958 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1959 | err: |
| 1960 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1961 | free(errmsg); |
| 1962 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1963 | } |
| 1964 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1965 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1966 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1967 | * Returns the error code, 0 if OK, or any combination of : |
| 1968 | * - ERR_ABORT: must abort ASAP |
| 1969 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1970 | * - ERR_WARN: a warning has been emitted |
| 1971 | * - ERR_ALERT: an alert has been emitted |
| 1972 | * Only the two first ones can stop processing, the two others are just |
| 1973 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1974 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1975 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1976 | { |
| 1977 | static struct peers *curpeers = NULL; |
| 1978 | struct peer *newpeer = NULL; |
| 1979 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1980 | struct bind_conf *bind_conf; |
| 1981 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1982 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1983 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1984 | |
| 1985 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1986 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1987 | ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1988 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1989 | goto out; |
| 1990 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1991 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1992 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1993 | goto out; |
| 1994 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1995 | err = invalid_char(args[1]); |
| 1996 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1997 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1998 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1999 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 2000 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2003 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2004 | /* |
| 2005 | * If there are two proxies with the same name only following |
| 2006 | * combinations are allowed: |
| 2007 | */ |
| 2008 | if (strcmp(curpeers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2009 | ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", |
| 2010 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2011 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2015 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2016 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2017 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2018 | goto out; |
| 2019 | } |
| 2020 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2021 | curpeers->next = cfg_peers; |
| 2022 | cfg_peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2023 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2024 | curpeers->conf.line = linenum; |
| 2025 | curpeers->last_change = now.tv_sec; |
| 2026 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2027 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2028 | } |
| 2029 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2030 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2031 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2032 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2033 | |
| 2034 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2035 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2036 | file, linenum, args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2038 | goto out; |
| 2039 | } |
| 2040 | |
| 2041 | err = invalid_char(args[1]); |
| 2042 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2043 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2044 | file, linenum, *err, args[1]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2045 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2046 | goto out; |
| 2047 | } |
| 2048 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2049 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2050 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2051 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2052 | goto out; |
| 2053 | } |
| 2054 | |
| 2055 | /* the peers are linked backwards first */ |
| 2056 | curpeers->count++; |
| 2057 | newpeer->next = curpeers->remote; |
| 2058 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2059 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2060 | newpeer->conf.line = linenum; |
| 2061 | |
| 2062 | newpeer->last_change = now.tv_sec; |
| 2063 | newpeer->id = strdup(args[1]); |
| 2064 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2065 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2066 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2067 | ha_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] | 2068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2069 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2070 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2071 | |
| 2072 | proto = protocol_by_family(sk->ss_family); |
| 2073 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2074 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2075 | file, linenum, args[0], args[1]); |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2076 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2077 | goto out; |
| 2078 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2079 | |
| 2080 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2081 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2082 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2084 | goto out; |
| 2085 | } |
| 2086 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2087 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2088 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2089 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2091 | goto out; |
| 2092 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2093 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2094 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2095 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2096 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2097 | newpeer->sock_init_arg = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2098 | HA_SPIN_INIT(&newpeer->lock); |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2099 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2100 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2101 | /* Current is local peer, it define a frontend */ |
| 2102 | newpeer->local = 1; |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2103 | cfg_peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2104 | |
| 2105 | if (!curpeers->peers_fe) { |
| 2106 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2107 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2108 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2109 | goto out; |
| 2110 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2111 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2112 | init_new_proxy(curpeers->peers_fe); |
| 2113 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2114 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2115 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2116 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2117 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2118 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2119 | bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW)); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2120 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2121 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2122 | if (errmsg && *errmsg) { |
| 2123 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2124 | ha_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] | 2125 | } |
| 2126 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2127 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2128 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2129 | err_code |= ERR_FATAL; |
| 2130 | goto out; |
| 2131 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2132 | |
| 2133 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2134 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2135 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2136 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2137 | l->accept = session_accept_fd; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2138 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2139 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2140 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2141 | global.maxsock += l->maxconn; |
| 2142 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2143 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2144 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2145 | ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2146 | file, linenum, args[0], args[1], |
| 2147 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2148 | err_code |= ERR_FATAL; |
| 2149 | goto out; |
| 2150 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2151 | } |
| 2152 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2153 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2154 | curpeers->state = PR_STSTOPPED; |
| 2155 | } |
| 2156 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2157 | curpeers->state = PR_STNEW; |
| 2158 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2159 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2160 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2161 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2162 | goto out; |
| 2163 | } |
| 2164 | |
| 2165 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2166 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2167 | return err_code; |
| 2168 | } |
| 2169 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2170 | /* |
| 2171 | * Parse a <resolvers> section. |
| 2172 | * Returns the error code, 0 if OK, or any combination of : |
| 2173 | * - ERR_ABORT: must abort ASAP |
| 2174 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2175 | * - ERR_WARN: a warning has been emitted |
| 2176 | * - ERR_ALERT: an alert has been emitted |
| 2177 | * Only the two first ones can stop processing, the two others are just |
| 2178 | * indicators. |
| 2179 | */ |
| 2180 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2181 | { |
| 2182 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2183 | struct dns_nameserver *newnameserver = NULL; |
| 2184 | const char *err; |
| 2185 | int err_code = 0; |
| 2186 | char *errmsg = NULL; |
| 2187 | |
| 2188 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2189 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2190 | ha_alert("parsing [%s:%d] : missing name for resolvers section.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2191 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2192 | goto out; |
| 2193 | } |
| 2194 | |
| 2195 | err = invalid_char(args[1]); |
| 2196 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2197 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2198 | file, linenum, *err, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2199 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2200 | goto out; |
| 2201 | } |
| 2202 | |
| 2203 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2204 | /* Error if two resolvers owns the same name */ |
| 2205 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2206 | ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2207 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2208 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2209 | } |
| 2210 | } |
| 2211 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2212 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2213 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2214 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2215 | goto out; |
| 2216 | } |
| 2217 | |
| 2218 | /* default values */ |
| 2219 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2220 | curr_resolvers->conf.file = strdup(file); |
| 2221 | curr_resolvers->conf.line = linenum; |
| 2222 | curr_resolvers->id = strdup(args[1]); |
| 2223 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2224 | /* default maximum response size */ |
| 2225 | curr_resolvers->accepted_payload_size = 512; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2226 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2227 | curr_resolvers->hold.nx = 30000; |
| 2228 | curr_resolvers->hold.other = 30000; |
| 2229 | curr_resolvers->hold.refused = 30000; |
| 2230 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 686408b | 2017-08-18 10:15:42 +0200 | [diff] [blame] | 2231 | curr_resolvers->hold.obsolete = 0; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2232 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2233 | curr_resolvers->hold.valid = 10000; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2234 | curr_resolvers->timeout.resolve = 1000; |
| 2235 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2236 | curr_resolvers->resolve_retries = 3; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2237 | curr_resolvers->nb_nameservers = 0; |
| 2238 | LIST_INIT(&curr_resolvers->nameservers); |
| 2239 | LIST_INIT(&curr_resolvers->resolutions.curr); |
| 2240 | LIST_INIT(&curr_resolvers->resolutions.wait); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2241 | HA_SPIN_INIT(&curr_resolvers->lock); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2242 | } |
| 2243 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2244 | struct sockaddr_storage *sk; |
| 2245 | int port1, port2; |
| 2246 | struct protocol *proto; |
| 2247 | |
| 2248 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2249 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2250 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2252 | goto out; |
| 2253 | } |
| 2254 | |
| 2255 | err = invalid_char(args[1]); |
| 2256 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2257 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2258 | file, linenum, *err, args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2260 | goto out; |
| 2261 | } |
| 2262 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2263 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2264 | /* Error if two resolvers owns the same name */ |
| 2265 | if (strcmp(newnameserver->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2266 | ha_alert("Parsing [%s:%d]: nameserver '%s' has same name as another nameserver (declared at %s:%d).\n", |
Ben Draut | 44e609b | 2018-05-29 15:40:08 -0600 | [diff] [blame] | 2267 | file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line); |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2269 | } |
| 2270 | } |
| 2271 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2272 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2273 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2274 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2275 | goto out; |
| 2276 | } |
| 2277 | |
| 2278 | /* the nameservers are linked backward first */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2279 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2280 | newnameserver->resolvers = curr_resolvers; |
| 2281 | newnameserver->conf.file = strdup(file); |
| 2282 | newnameserver->conf.line = linenum; |
| 2283 | newnameserver->id = strdup(args[1]); |
| 2284 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2285 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2286 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2287 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2289 | goto out; |
| 2290 | } |
| 2291 | |
| 2292 | proto = protocol_by_family(sk->ss_family); |
| 2293 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2294 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2295 | file, linenum, args[0], args[1]); |
| 2296 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2297 | goto out; |
| 2298 | } |
| 2299 | |
| 2300 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2301 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2302 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2303 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2304 | goto out; |
| 2305 | } |
| 2306 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2307 | if (!port1 && !port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2308 | ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2309 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2311 | goto out; |
| 2312 | } |
| 2313 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2314 | newnameserver->addr = *sk; |
| 2315 | } |
Ben Draut | 44e609b | 2018-05-29 15:40:08 -0600 | [diff] [blame] | 2316 | else if (strcmp(args[0], "parse-resolv-conf") == 0) { |
| 2317 | const char *whitespace = "\r\n\t "; |
| 2318 | char *resolv_line = NULL; |
| 2319 | int resolv_linenum = 0; |
| 2320 | FILE *f = NULL; |
| 2321 | char *address = NULL; |
| 2322 | struct sockaddr_storage *sk = NULL; |
| 2323 | struct protocol *proto; |
| 2324 | int duplicate_name = 0; |
| 2325 | |
| 2326 | if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) { |
| 2327 | ha_alert("parsing [%s:%d] : out of memory.\n", |
| 2328 | file, linenum); |
| 2329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2330 | goto resolv_out; |
| 2331 | } |
| 2332 | |
| 2333 | if ((f = fopen("/etc/resolv.conf", "r")) == NULL) { |
| 2334 | ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n", |
| 2335 | file, linenum); |
| 2336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2337 | goto resolv_out; |
| 2338 | } |
| 2339 | |
| 2340 | sk = calloc(1, sizeof(*sk)); |
| 2341 | if (sk == NULL) { |
| 2342 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", |
| 2343 | resolv_linenum); |
| 2344 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2345 | goto resolv_out; |
| 2346 | } |
| 2347 | |
| 2348 | while (fgets(resolv_line, LINESIZE, f) != NULL) { |
| 2349 | resolv_linenum++; |
| 2350 | if (strncmp(resolv_line, "nameserver", 10) != 0) |
| 2351 | continue; |
| 2352 | |
| 2353 | address = strtok(resolv_line + 10, whitespace); |
| 2354 | if (address == resolv_line + 10) |
| 2355 | continue; |
| 2356 | |
| 2357 | if (address == NULL) { |
| 2358 | ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n", |
| 2359 | resolv_linenum); |
| 2360 | err_code |= ERR_WARN; |
| 2361 | continue; |
| 2362 | } |
| 2363 | |
| 2364 | duplicate_name = 0; |
| 2365 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
| 2366 | if (strcmp(newnameserver->id, address) == 0) { |
| 2367 | ha_warning("Parsing [/etc/resolv.conf:%d] : generated name for /etc/resolv.conf nameserver '%s' conflicts with another nameserver (declared at %s:%d), it appears to be a duplicate and will be excluded.\n", |
| 2368 | resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line); |
| 2369 | err_code |= ERR_WARN; |
| 2370 | duplicate_name = 1; |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | if (duplicate_name) |
| 2375 | continue; |
| 2376 | |
| 2377 | memset(sk, 0, sizeof(*sk)); |
| 2378 | sk = str2ip2(address, sk, 1); |
| 2379 | if (!sk) { |
| 2380 | ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, namerserver will be excluded.\n", |
| 2381 | resolv_linenum, address); |
| 2382 | err_code |= ERR_WARN; |
| 2383 | continue; |
| 2384 | } |
| 2385 | |
| 2386 | set_host_port(sk, 53); |
| 2387 | |
| 2388 | proto = protocol_by_family(sk->ss_family); |
| 2389 | if (!proto || !proto->connect) { |
| 2390 | ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n", |
| 2391 | resolv_linenum, address); |
| 2392 | err_code |= ERR_WARN; |
| 2393 | continue; |
| 2394 | } |
| 2395 | |
| 2396 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
| 2397 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2398 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2399 | goto resolv_out; |
| 2400 | } |
| 2401 | |
| 2402 | newnameserver->conf.file = strdup("/etc/resolv.conf"); |
| 2403 | if (newnameserver->conf.file == NULL) { |
| 2404 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2406 | goto resolv_out; |
| 2407 | } |
| 2408 | |
| 2409 | newnameserver->id = strdup(address); |
| 2410 | if (newnameserver->id == NULL) { |
| 2411 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2412 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2413 | goto resolv_out; |
| 2414 | } |
| 2415 | |
| 2416 | newnameserver->resolvers = curr_resolvers; |
| 2417 | newnameserver->conf.line = resolv_linenum; |
| 2418 | newnameserver->addr = *sk; |
| 2419 | |
| 2420 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
| 2421 | } |
| 2422 | |
| 2423 | resolv_out: |
| 2424 | free(sk); |
| 2425 | free(resolv_line); |
| 2426 | if (f != NULL) |
| 2427 | fclose(f); |
| 2428 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2429 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2430 | const char *res; |
| 2431 | unsigned int time; |
| 2432 | |
| 2433 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2434 | ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2435 | file, linenum, args[0]); |
| 2436 | ha_alert("<event> can be either 'valid', 'nx', 'refused', 'timeout', or 'other'\n"); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
| 2439 | } |
| 2440 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2441 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2442 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2443 | file, linenum, *res, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2444 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2445 | goto out; |
| 2446 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2447 | if (strcmp(args[1], "nx") == 0) |
| 2448 | curr_resolvers->hold.nx = time; |
| 2449 | else if (strcmp(args[1], "other") == 0) |
| 2450 | curr_resolvers->hold.other = time; |
| 2451 | else if (strcmp(args[1], "refused") == 0) |
| 2452 | curr_resolvers->hold.refused = time; |
| 2453 | else if (strcmp(args[1], "timeout") == 0) |
| 2454 | curr_resolvers->hold.timeout = time; |
| 2455 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2456 | curr_resolvers->hold.valid = time; |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2457 | else if (strcmp(args[1], "obsolete") == 0) |
| 2458 | curr_resolvers->hold.obsolete = time; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2459 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2460 | ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n", |
| 2461 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2463 | goto out; |
| 2464 | } |
| 2465 | |
| 2466 | } |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2467 | else if (strcmp(args[0], "accepted_payload_size") == 0) { |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2468 | int i = 0; |
| 2469 | |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2470 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2471 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2472 | file, linenum, args[0]); |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2474 | goto out; |
| 2475 | } |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2476 | |
| 2477 | i = atoi(args[1]); |
Willy Tarreau | 0c219be | 2017-08-22 12:01:26 +0200 | [diff] [blame] | 2478 | if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2479 | ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n", |
| 2480 | file, linenum, args[0], DNS_HEADER_SIZE, DNS_MAX_UDP_MESSAGE, args[1]); |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2482 | goto out; |
| 2483 | } |
| 2484 | |
| 2485 | curr_resolvers->accepted_payload_size = i; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2486 | } |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2487 | else if (strcmp(args[0], "resolution_pool_size") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2488 | ha_warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n", |
| 2489 | file, linenum, args[0]); |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2490 | err_code |= ERR_WARN; |
| 2491 | goto out; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2492 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2493 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2494 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2495 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2496 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2497 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2498 | goto out; |
| 2499 | } |
| 2500 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2501 | } |
| 2502 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2503 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2504 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n", |
| 2505 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2507 | goto out; |
| 2508 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2509 | else if (strcmp(args[1], "retry") == 0 || |
| 2510 | strcmp(args[1], "resolve") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2511 | const char *res; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2512 | unsigned int tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2513 | |
| 2514 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2515 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2516 | file, linenum, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2517 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2518 | goto out; |
| 2519 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2520 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2521 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2522 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2523 | file, linenum, *res, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2525 | goto out; |
| 2526 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2527 | if (args[1][2] == 't') |
| 2528 | curr_resolvers->timeout.retry = tout; |
| 2529 | else |
| 2530 | curr_resolvers->timeout.resolve = tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2531 | } |
| 2532 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2533 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n", |
| 2534 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2536 | goto out; |
| 2537 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2538 | } /* neither "nameserver" nor "resolvers" */ |
| 2539 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2540 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2541 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2542 | goto out; |
| 2543 | } |
| 2544 | |
| 2545 | out: |
| 2546 | free(errmsg); |
| 2547 | return err_code; |
| 2548 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2549 | |
| 2550 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2551 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2552 | * Returns the error code, 0 if OK, or any combination of : |
| 2553 | * - ERR_ABORT: must abort ASAP |
| 2554 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2555 | * - ERR_WARN: a warning has been emitted |
| 2556 | * - ERR_ALERT: an alert has been emitted |
| 2557 | * Only the two first ones can stop processing, the two others are just |
| 2558 | * indicators. |
| 2559 | */ |
| 2560 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2561 | { |
| 2562 | static struct mailers *curmailers = NULL; |
| 2563 | struct mailer *newmailer = NULL; |
| 2564 | const char *err; |
| 2565 | int err_code = 0; |
| 2566 | char *errmsg = NULL; |
| 2567 | |
| 2568 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2569 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2570 | ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2571 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2572 | goto out; |
| 2573 | } |
| 2574 | |
| 2575 | err = invalid_char(args[1]); |
| 2576 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2577 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2578 | file, linenum, *err, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2579 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2580 | goto out; |
| 2581 | } |
| 2582 | |
| 2583 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2584 | /* |
| 2585 | * If there are two proxies with the same name only following |
| 2586 | * combinations are allowed: |
| 2587 | */ |
| 2588 | if (strcmp(curmailers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2589 | ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", |
| 2590 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2591 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2595 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2596 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2597 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2598 | goto out; |
| 2599 | } |
| 2600 | |
| 2601 | curmailers->next = mailers; |
| 2602 | mailers = curmailers; |
| 2603 | curmailers->conf.file = strdup(file); |
| 2604 | curmailers->conf.line = linenum; |
| 2605 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2606 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2607 | * But need enough time so that timeouts don't occur |
| 2608 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2609 | } |
| 2610 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2611 | struct sockaddr_storage *sk; |
| 2612 | int port1, port2; |
| 2613 | struct protocol *proto; |
| 2614 | |
| 2615 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2616 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2617 | file, linenum, args[0]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2619 | goto out; |
| 2620 | } |
| 2621 | |
| 2622 | err = invalid_char(args[1]); |
| 2623 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2624 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2625 | file, linenum, *err, args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2627 | goto out; |
| 2628 | } |
| 2629 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2630 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2631 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2632 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2633 | goto out; |
| 2634 | } |
| 2635 | |
| 2636 | /* the mailers are linked backwards first */ |
| 2637 | curmailers->count++; |
| 2638 | newmailer->next = curmailers->mailer_list; |
| 2639 | curmailers->mailer_list = newmailer; |
| 2640 | newmailer->mailers = curmailers; |
| 2641 | newmailer->conf.file = strdup(file); |
| 2642 | newmailer->conf.line = linenum; |
| 2643 | |
| 2644 | newmailer->id = strdup(args[1]); |
| 2645 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2646 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2647 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2648 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
| 2653 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2654 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2655 | ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n", |
| 2656 | file, linenum, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2658 | goto out; |
| 2659 | } |
| 2660 | |
| 2661 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2662 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2663 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
| 2668 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2669 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2670 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2672 | goto out; |
| 2673 | } |
| 2674 | |
| 2675 | newmailer->addr = *sk; |
| 2676 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2677 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2678 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2679 | } |
| 2680 | else if (strcmp(args[0], "timeout") == 0) { |
| 2681 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2682 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2683 | file, linenum, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2685 | goto out; |
| 2686 | } |
| 2687 | else if (strcmp(args[1], "mail") == 0) { |
| 2688 | const char *res; |
| 2689 | unsigned int timeout_mail; |
| 2690 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2691 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2692 | file, linenum, args[0], args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2693 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2694 | goto out; |
| 2695 | } |
| 2696 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2697 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2698 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2699 | file, linenum, *res, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2701 | goto out; |
| 2702 | } |
| 2703 | if (timeout_mail <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2704 | ha_alert("parsing [%s:%d] : '%s %s' expects a positive <time> argument.\n", file, linenum, args[0], args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2705 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2706 | goto out; |
| 2707 | } |
| 2708 | curmailers->timeout.mail = timeout_mail; |
| 2709 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2710 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2711 | file, linenum, args[0], args[1]); |
| 2712 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2713 | goto out; |
| 2714 | } |
| 2715 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2716 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2717 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2719 | goto out; |
| 2720 | } |
| 2721 | |
| 2722 | out: |
| 2723 | free(errmsg); |
| 2724 | return err_code; |
| 2725 | } |
| 2726 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2727 | static void free_email_alert(struct proxy *p) |
| 2728 | { |
| 2729 | free(p->email_alert.mailers.name); |
| 2730 | p->email_alert.mailers.name = NULL; |
| 2731 | free(p->email_alert.from); |
| 2732 | p->email_alert.from = NULL; |
| 2733 | free(p->email_alert.to); |
| 2734 | p->email_alert.to = NULL; |
| 2735 | free(p->email_alert.myhostname); |
| 2736 | p->email_alert.myhostname = NULL; |
| 2737 | } |
| 2738 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2739 | 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] | 2740 | { |
| 2741 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2742 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2743 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2744 | int rc; |
| 2745 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2746 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2747 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2748 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2749 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2750 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2751 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2752 | if (!strcmp(args[0], "listen")) |
| 2753 | rc = PR_CAP_LISTEN; |
| 2754 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2755 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2756 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2757 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2758 | else |
| 2759 | rc = PR_CAP_NONE; |
| 2760 | |
| 2761 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2762 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2763 | ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 2764 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 2765 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2766 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2767 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2768 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2769 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2770 | err = invalid_char(args[1]); |
| 2771 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2772 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2773 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2774 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2775 | } |
| 2776 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2777 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2778 | if (curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2779 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2780 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2781 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2782 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2783 | } |
| 2784 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2785 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2786 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2787 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2788 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2789 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2790 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2791 | init_new_proxy(curproxy); |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 2792 | curproxy->next = proxies_list; |
| 2793 | proxies_list = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2794 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2795 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2796 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2797 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2798 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2799 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2800 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2801 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2802 | if (curproxy->cap & PR_CAP_FE) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2803 | ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2804 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2808 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2809 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2810 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2811 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2812 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2813 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2814 | curproxy->no_options = defproxy.no_options; |
| 2815 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2816 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2817 | curproxy->except_net = defproxy.except_net; |
| 2818 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2819 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2820 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2821 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2822 | if (defproxy.fwdfor_hdr_len) { |
| 2823 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2824 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2825 | } |
| 2826 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2827 | if (defproxy.orgto_hdr_len) { |
| 2828 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2829 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2830 | } |
| 2831 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2832 | if (defproxy.server_id_hdr_len) { |
| 2833 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2834 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2835 | } |
| 2836 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2837 | if (curproxy->cap & PR_CAP_FE) { |
| 2838 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2839 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2840 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2841 | |
| 2842 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2843 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2844 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2845 | |
| 2846 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2847 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2848 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2849 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2850 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2851 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2852 | curproxy->fullconn = defproxy.fullconn; |
| 2853 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2854 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2855 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2856 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2857 | if (defproxy.check_req) { |
| 2858 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2859 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2860 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2861 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2862 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2863 | if (defproxy.expect_str) { |
| 2864 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2865 | if (defproxy.expect_regex) { |
| 2866 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2867 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2868 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2872 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2873 | if (defproxy.cookie_name) |
| 2874 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2875 | curproxy->cookie_len = defproxy.cookie_len; |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2876 | |
| 2877 | if (defproxy.dyncookie_key) |
| 2878 | curproxy->dyncookie_key = strdup(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2879 | if (defproxy.cookie_domain) |
| 2880 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2881 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2882 | if (defproxy.cookie_maxidle) |
| 2883 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2884 | |
| 2885 | if (defproxy.cookie_maxlife) |
| 2886 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2887 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2888 | if (defproxy.rdp_cookie_name) |
| 2889 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2890 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2891 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2892 | if (defproxy.url_param_name) |
| 2893 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2894 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2895 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2896 | if (defproxy.hh_name) |
| 2897 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2898 | curproxy->hh_len = defproxy.hh_len; |
| 2899 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2900 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2901 | if (defproxy.conn_src.iface_name) |
| 2902 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2903 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2904 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2905 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2906 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2907 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2908 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2909 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2910 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2911 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2912 | if (defproxy.capture_name) |
| 2913 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2914 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2915 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2916 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2917 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2918 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2919 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2920 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2921 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2922 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2923 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2924 | curproxy->mon_net = defproxy.mon_net; |
| 2925 | curproxy->mon_mask = defproxy.mon_mask; |
| 2926 | if (defproxy.monitor_uri) |
| 2927 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2928 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2929 | if (defproxy.defbe.name) |
| 2930 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2931 | |
| 2932 | /* 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] | 2933 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2934 | if (curproxy->conf.logformat_string && |
| 2935 | curproxy->conf.logformat_string != default_http_log_format && |
| 2936 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2937 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2938 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2939 | |
| 2940 | if (defproxy.conf.lfs_file) { |
| 2941 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2942 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2943 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2944 | |
| 2945 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2946 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2947 | if (curproxy->conf.logformat_sd_string && |
| 2948 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2949 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2950 | |
| 2951 | if (defproxy.conf.lfsd_file) { |
| 2952 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2953 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2954 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2958 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2959 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2960 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2961 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2962 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2963 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2964 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2965 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2966 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2967 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2968 | } |
| 2969 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2970 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2971 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2972 | |
| 2973 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2974 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2975 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2976 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
Christopher Faulet | 28ac099 | 2018-03-26 16:09:19 +0200 | [diff] [blame] | 2977 | node->ref = tmplogsrv->ref; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2978 | LIST_INIT(&node->list); |
| 2979 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2980 | } |
| 2981 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2982 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2983 | if (curproxy->conf.uniqueid_format_string) |
| 2984 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2985 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2986 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2987 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2988 | if (defproxy.conf.uif_file) { |
| 2989 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2990 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2991 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2992 | |
| 2993 | /* copy default header unique id */ |
| 2994 | if (defproxy.header_unique_id) |
| 2995 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2996 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2997 | /* default compression options */ |
| 2998 | if (defproxy.comp != NULL) { |
| 2999 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 3000 | curproxy->comp->algos = defproxy.comp->algos; |
| 3001 | curproxy->comp->types = defproxy.comp->types; |
| 3002 | } |
| 3003 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3004 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3005 | curproxy->conf.used_listener_id = EB_ROOT; |
| 3006 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3007 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3008 | if (defproxy.check_path) |
| 3009 | curproxy->check_path = strdup(defproxy.check_path); |
| 3010 | if (defproxy.check_command) |
| 3011 | curproxy->check_command = strdup(defproxy.check_command); |
| 3012 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3013 | if (defproxy.email_alert.mailers.name) |
| 3014 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3015 | if (defproxy.email_alert.from) |
| 3016 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3017 | if (defproxy.email_alert.to) |
| 3018 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3019 | if (defproxy.email_alert.myhostname) |
| 3020 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3021 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3022 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3023 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3024 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3025 | } |
| 3026 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3027 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3028 | /* FIXME-20070101: we should do this too at the end of the |
| 3029 | * config parsing to free all default values. |
| 3030 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3031 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3032 | err_code |= ERR_ABORT; |
| 3033 | goto out; |
| 3034 | } |
| 3035 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3036 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3037 | free(defproxy.check_command); |
| 3038 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3039 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3040 | free(defproxy.rdp_cookie_name); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3041 | free(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3042 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3043 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3044 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3045 | free(defproxy.capture_name); |
| 3046 | free(defproxy.monitor_uri); |
| 3047 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3048 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3049 | free(defproxy.fwdfor_hdr_name); |
| 3050 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3051 | free(defproxy.orgto_hdr_name); |
| 3052 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3053 | free(defproxy.server_id_hdr_name); |
| 3054 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3055 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3056 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3057 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3058 | free(defproxy.expect_regex); |
| 3059 | defproxy.expect_regex = NULL; |
| 3060 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3061 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3062 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3063 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3064 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3065 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3066 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3067 | free(defproxy.conf.uniqueid_format_string); |
| 3068 | free(defproxy.conf.lfs_file); |
| 3069 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3070 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3071 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3072 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3073 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3074 | free(defproxy.conf.logformat_sd_string); |
| 3075 | free(defproxy.conf.lfsd_file); |
| 3076 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3077 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3078 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3079 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3080 | /* we cannot free uri_auth because it might already be used */ |
| 3081 | init_default_instance(); |
| 3082 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3083 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3084 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3085 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3086 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3087 | } |
| 3088 | else if (curproxy == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3089 | ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3091 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3092 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3093 | |
| 3094 | /* update the current file and line being parsed */ |
| 3095 | curproxy->conf.args.file = curproxy->conf.file; |
| 3096 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3097 | |
| 3098 | /* Now let's parse the proxy-specific keywords */ |
Frédéric Lécaille | b82f742 | 2017-04-13 18:24:23 +0200 | [diff] [blame] | 3099 | if (!strcmp(args[0], "server") || |
| 3100 | !strcmp(args[0], "default-server") || |
| 3101 | !strcmp(args[0], "server-template")) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3102 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3103 | if (err_code & ERR_FATAL) |
| 3104 | goto out; |
| 3105 | } |
| 3106 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3107 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3108 | int cur_arg; |
| 3109 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3110 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3111 | ha_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] | 3112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3113 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3114 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3115 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3116 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3117 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3118 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3119 | ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
| 3120 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3121 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3122 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3123 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3124 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 3125 | bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW)); |
Willy Tarreau | 8dc21fa | 2013-01-24 15:17:20 +0100 | [diff] [blame] | 3126 | |
| 3127 | /* use default settings for unix sockets */ |
| 3128 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3129 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3130 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3131 | |
| 3132 | /* NOTE: the following line might create several listeners if there |
| 3133 | * are comma-separated IPs or port ranges. So all further processing |
| 3134 | * will have to be applied to all listeners created after last_listen. |
| 3135 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3136 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3137 | if (errmsg && *errmsg) { |
| 3138 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3139 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 3140 | } |
| 3141 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3142 | ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3143 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3145 | goto out; |
| 3146 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3147 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3148 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3149 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3150 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3153 | cur_arg = 2; |
| 3154 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3155 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3156 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3157 | char *err; |
| 3158 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3159 | kw = bind_find_kw(args[cur_arg]); |
| 3160 | if (kw) { |
| 3161 | char *err = NULL; |
| 3162 | int code; |
| 3163 | |
| 3164 | if (!kw->parse) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3165 | ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3166 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3167 | cur_arg += 1 + kw->skip ; |
| 3168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3169 | goto out; |
| 3170 | } |
| 3171 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3172 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3173 | err_code |= code; |
| 3174 | |
| 3175 | if (code) { |
| 3176 | if (err && *err) { |
| 3177 | indent_msg(&err, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3178 | ha_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] | 3179 | } |
| 3180 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3181 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3182 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3183 | if (code & ERR_FATAL) { |
| 3184 | free(err); |
| 3185 | cur_arg += 1 + kw->skip; |
| 3186 | goto out; |
| 3187 | } |
| 3188 | } |
| 3189 | free(err); |
| 3190 | cur_arg += 1 + kw->skip; |
| 3191 | continue; |
| 3192 | } |
| 3193 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3194 | err = NULL; |
| 3195 | if (!bind_dumped) { |
| 3196 | bind_dump_kws(&err); |
| 3197 | indent_msg(&err, 4); |
| 3198 | bind_dumped = 1; |
| 3199 | } |
| 3200 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3201 | ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3202 | file, linenum, args[0], args[1], args[cur_arg], |
| 3203 | err ? " Registered keywords :" : "", err ? err : ""); |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3204 | free(err); |
| 3205 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3207 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3208 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3209 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3210 | } |
| 3211 | 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] | 3212 | if (!*args[1] || !str2net(args[1], 1, &curproxy->mon_net, &curproxy->mon_mask)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3213 | ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3214 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3216 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3217 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3218 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3220 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3221 | /* flush useless bits */ |
| 3222 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3223 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3224 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3225 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3226 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3227 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3228 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3229 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3230 | goto out; |
| 3231 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3232 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3233 | ha_alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3234 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3236 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3237 | } |
| 3238 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3239 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3240 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3241 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3242 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3243 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3244 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3245 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3246 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3247 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3248 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3249 | goto out; |
| 3250 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3251 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3252 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3253 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3254 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3255 | ha_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] | 3256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3257 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3258 | } |
| 3259 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3260 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3261 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3262 | |
| 3263 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3264 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3265 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3267 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3268 | } |
| 3269 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3270 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3271 | goto out; |
| 3272 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3273 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3274 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3275 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3276 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3277 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3281 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3282 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3283 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3284 | if (curproxy->uuid <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3285 | ha_alert("parsing [%s:%d]: custom id has to be > 0.\n", |
| 3286 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3288 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3291 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3292 | if (node) { |
| 3293 | struct proxy *target = container_of(node, struct proxy, conf.id); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3294 | ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3295 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3296 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3298 | goto out; |
| 3299 | } |
| 3300 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3301 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3302 | else if (!strcmp(args[0], "description")) { |
| 3303 | int i, len=0; |
| 3304 | char *d; |
| 3305 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3306 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3307 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3308 | file, linenum, args[0]); |
| 3309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3310 | goto out; |
| 3311 | } |
| 3312 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3313 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3314 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3315 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3316 | return -1; |
| 3317 | } |
| 3318 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3319 | for (i = 1; *args[i]; i++) |
| 3320 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3321 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3322 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3323 | curproxy->desc = d; |
| 3324 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3325 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3326 | for (i = 2; *args[i]; i++) |
| 3327 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3328 | |
| 3329 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3330 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3331 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3333 | curproxy->state = PR_STSTOPPED; |
| 3334 | } |
| 3335 | 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] | 3336 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3337 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3338 | curproxy->state = PR_STNEW; |
| 3339 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3340 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3341 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3342 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3343 | |
| 3344 | while (*args[cur_arg]) { |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3345 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3346 | set = 0; |
| 3347 | break; |
| 3348 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 3349 | if (parse_process_number(args[cur_arg], &set, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3350 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 3351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3352 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3353 | } |
| 3354 | cur_arg++; |
| 3355 | } |
| 3356 | curproxy->bind_proc = set; |
| 3357 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3358 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3359 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3360 | ha_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] | 3361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3362 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3363 | } |
| 3364 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3365 | err = invalid_char(args[1]); |
| 3366 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3367 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3368 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3369 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1822e8c | 2017-04-12 18:54:00 +0200 | [diff] [blame] | 3370 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3371 | } |
| 3372 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3373 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3374 | ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3375 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3377 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3378 | } |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3379 | } |
| 3380 | else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */ |
| 3381 | |
| 3382 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3383 | err_code |= ERR_WARN; |
| 3384 | |
| 3385 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3386 | ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 3387 | file, linenum, args[0]); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3389 | goto out; |
| 3390 | } |
| 3391 | free(curproxy->dyncookie_key); |
| 3392 | curproxy->dyncookie_key = strdup(args[1]); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3393 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3394 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3395 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3396 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3397 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3398 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3399 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3400 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3401 | ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3402 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3405 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3406 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3407 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3408 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3409 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3410 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3411 | curproxy->cookie_name = strdup(args[1]); |
| 3412 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3413 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3414 | cur_arg = 2; |
| 3415 | while (*(args[cur_arg])) { |
| 3416 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3417 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3418 | } |
| 3419 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3420 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3421 | } |
| 3422 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3423 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3424 | } |
| 3425 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3426 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3427 | } |
| 3428 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3429 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3430 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3431 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3432 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3433 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3435 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3436 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3437 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3438 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3439 | } |
| 3440 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3441 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3442 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3443 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3444 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3445 | ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3446 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3447 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3448 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3449 | } |
| 3450 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3451 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3452 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3453 | ha_warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3454 | " dots nor does not start with a dot." |
| 3455 | " RFC forbids it, this configuration may not work properly.\n", |
| 3456 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3457 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3461 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3462 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3463 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3465 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3466 | } |
| 3467 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3468 | if (!curproxy->cookie_domain) { |
| 3469 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3470 | } else { |
| 3471 | /* one domain was already specified, add another one by |
| 3472 | * building the string which will be returned along with |
| 3473 | * the cookie. |
| 3474 | */ |
| 3475 | char *new_ptr; |
| 3476 | int new_len = strlen(curproxy->cookie_domain) + |
| 3477 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3478 | new_ptr = malloc(new_len); |
| 3479 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3480 | free(curproxy->cookie_domain); |
| 3481 | curproxy->cookie_domain = new_ptr; |
| 3482 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3483 | cur_arg++; |
| 3484 | } |
| 3485 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3486 | unsigned int maxidle; |
| 3487 | const char *res; |
| 3488 | |
| 3489 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3490 | ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3491 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3493 | goto out; |
| 3494 | } |
| 3495 | |
| 3496 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3497 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3498 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3499 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3501 | goto out; |
| 3502 | } |
| 3503 | curproxy->cookie_maxidle = maxidle; |
| 3504 | cur_arg++; |
| 3505 | } |
| 3506 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3507 | unsigned int maxlife; |
| 3508 | const char *res; |
| 3509 | |
| 3510 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3511 | ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3512 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3514 | goto out; |
| 3515 | } |
| 3516 | |
| 3517 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3518 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3519 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3520 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3522 | goto out; |
| 3523 | } |
| 3524 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3525 | cur_arg++; |
| 3526 | } |
Olivier Houchard | a5938f7 | 2017-03-15 15:12:06 +0100 | [diff] [blame] | 3527 | else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */ |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3528 | |
| 3529 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 3530 | err_code |= ERR_WARN; |
| 3531 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 3532 | } |
| 3533 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3534 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3535 | ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n", |
| 3536 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3538 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3539 | } |
| 3540 | cur_arg++; |
| 3541 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3542 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3543 | ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' 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 | } |
| 3547 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3548 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3549 | ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3550 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3551 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3552 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3553 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3554 | if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3555 | ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3556 | file, linenum); |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3557 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3558 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3559 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3560 | else if (!strcmp(args[0], "email-alert")) { |
| 3561 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3562 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3563 | file, linenum, args[0]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3565 | goto out; |
| 3566 | } |
| 3567 | |
| 3568 | if (!strcmp(args[1], "from")) { |
| 3569 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3570 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3571 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3573 | goto out; |
| 3574 | } |
| 3575 | free(curproxy->email_alert.from); |
| 3576 | curproxy->email_alert.from = strdup(args[2]); |
| 3577 | } |
| 3578 | else if (!strcmp(args[1], "mailers")) { |
| 3579 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3580 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3581 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3583 | goto out; |
| 3584 | } |
| 3585 | free(curproxy->email_alert.mailers.name); |
| 3586 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3587 | } |
| 3588 | else if (!strcmp(args[1], "myhostname")) { |
| 3589 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3590 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3591 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3593 | goto out; |
| 3594 | } |
| 3595 | free(curproxy->email_alert.myhostname); |
| 3596 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3597 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3598 | else if (!strcmp(args[1], "level")) { |
| 3599 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3600 | if (curproxy->email_alert.level < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3601 | ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3602 | file, linenum, args[1], args[2]); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
| 3605 | } |
| 3606 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3607 | else if (!strcmp(args[1], "to")) { |
| 3608 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3609 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3610 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3612 | goto out; |
| 3613 | } |
| 3614 | free(curproxy->email_alert.to); |
| 3615 | curproxy->email_alert.to = strdup(args[2]); |
| 3616 | } |
| 3617 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3618 | ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3619 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3620 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3621 | goto out; |
| 3622 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3623 | /* Indicate that the email_alert is at least partially configured */ |
| 3624 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3625 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3626 | else if (!strcmp(args[0], "external-check")) { |
| 3627 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3628 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3629 | file, linenum, args[0]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3631 | goto out; |
| 3632 | } |
| 3633 | |
| 3634 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3635 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3636 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3637 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3638 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3639 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3641 | goto out; |
| 3642 | } |
| 3643 | free(curproxy->check_command); |
| 3644 | curproxy->check_command = strdup(args[2]); |
| 3645 | } |
| 3646 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3647 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3648 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3649 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3650 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3651 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3652 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3653 | goto out; |
| 3654 | } |
| 3655 | free(curproxy->check_path); |
| 3656 | curproxy->check_path = strdup(args[2]); |
| 3657 | } |
| 3658 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3659 | ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3660 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3662 | goto out; |
| 3663 | } |
| 3664 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3665 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3666 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3667 | ha_alert("parsing [%s:%d] : missing persist method.\n", |
| 3668 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3670 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3674 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3675 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3676 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3677 | const char *beg, *end; |
| 3678 | |
| 3679 | beg = args[1] + 11; |
| 3680 | end = strchr(beg, ')'); |
| 3681 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3682 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3683 | goto out; |
| 3684 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3685 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3686 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3687 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3688 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3689 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | free(curproxy->rdp_cookie_name); |
| 3693 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3694 | curproxy->rdp_cookie_len = end-beg; |
| 3695 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3696 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3697 | free(curproxy->rdp_cookie_name); |
| 3698 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3699 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3700 | } |
| 3701 | else { /* syntax */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3702 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3703 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3705 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3706 | } |
| 3707 | } |
| 3708 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3709 | ha_alert("parsing [%s:%d] : unknown persist method.\n", |
| 3710 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3711 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3712 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3713 | } |
| 3714 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3715 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3716 | ha_alert("parsing [%s:%d] : '%s' is not supported anymore, please check the documentation.\n", file, linenum, args[0]); |
Willy Tarreau | 6db62c5 | 2015-08-10 19:04:29 +0200 | [diff] [blame] | 3717 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3718 | goto out; |
| 3719 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3720 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3721 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3722 | err_code |= ERR_WARN; |
| 3723 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3724 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3725 | } |
| 3726 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3727 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3728 | } |
| 3729 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3730 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3731 | } |
| 3732 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3733 | ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3734 | file, linenum, args[0], args[1]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3736 | goto out; |
| 3737 | } |
| 3738 | } |
| 3739 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3740 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3741 | err_code |= ERR_WARN; |
| 3742 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3743 | ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3744 | file, linenum, args[0]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3745 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3746 | goto out; |
| 3747 | } |
| 3748 | else if (!strcmp(args[1], "use-backend-name")) |
| 3749 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3750 | else |
| 3751 | curproxy->server_state_file_name = strdup(args[1]); |
| 3752 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3753 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3754 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3755 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3756 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3757 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3758 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3759 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3761 | goto out; |
| 3762 | } |
| 3763 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3764 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3765 | goto out; |
| 3766 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3767 | if (*(args[4]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3768 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3769 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3770 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3771 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3772 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3773 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3774 | curproxy->capture_name = strdup(args[2]); |
| 3775 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3776 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3777 | curproxy->to_log |= LW_COOKIE; |
| 3778 | } |
| 3779 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3780 | struct cap_hdr *hdr; |
| 3781 | |
| 3782 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3783 | ha_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] | 3784 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3785 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3786 | } |
| 3787 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3788 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3789 | goto out; |
| 3790 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3791 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3792 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3793 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3794 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3795 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3796 | } |
| 3797 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3798 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3799 | hdr->next = curproxy->req_cap; |
| 3800 | hdr->name = strdup(args[3]); |
| 3801 | hdr->namelen = strlen(args[3]); |
| 3802 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3803 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3804 | hdr->index = curproxy->nb_req_cap++; |
| 3805 | curproxy->req_cap = hdr; |
| 3806 | curproxy->to_log |= LW_REQHDR; |
| 3807 | } |
| 3808 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3809 | struct cap_hdr *hdr; |
| 3810 | |
| 3811 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3812 | ha_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] | 3813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3814 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3815 | } |
| 3816 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3817 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3818 | goto out; |
| 3819 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3820 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3821 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3822 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3824 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3825 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3826 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3827 | hdr->next = curproxy->rsp_cap; |
| 3828 | hdr->name = strdup(args[3]); |
| 3829 | hdr->namelen = strlen(args[3]); |
| 3830 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3831 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3832 | hdr->index = curproxy->nb_rsp_cap++; |
| 3833 | curproxy->rsp_cap = hdr; |
| 3834 | curproxy->to_log |= LW_RSPHDR; |
| 3835 | } |
| 3836 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3837 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3838 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3839 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3840 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | } |
| 3842 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3843 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3844 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3845 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3846 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3847 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3848 | goto out; |
| 3849 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3850 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3851 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3852 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3854 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3855 | } |
| 3856 | curproxy->conn_retries = atol(args[1]); |
| 3857 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3858 | 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] | 3859 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3860 | |
| 3861 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3862 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3864 | goto out; |
| 3865 | } |
| 3866 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3867 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3868 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3869 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3870 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3871 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3872 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REQ_AUTH)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3873 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3874 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3875 | err_code |= ERR_WARN; |
| 3876 | } |
| 3877 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3878 | 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] | 3879 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3880 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3881 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3882 | goto out; |
| 3883 | } |
| 3884 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3885 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3886 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3887 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3888 | file, linenum); |
| 3889 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3890 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3891 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3892 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3893 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3894 | |
| 3895 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3896 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3897 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3898 | goto out; |
| 3899 | } |
| 3900 | |
| 3901 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3902 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3903 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3904 | LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_DENY)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3905 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3906 | file, linenum, args[0]); |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3907 | err_code |= ERR_WARN; |
| 3908 | } |
| 3909 | |
| 3910 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3911 | |
| 3912 | if (!rule) { |
| 3913 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3914 | goto out; |
| 3915 | } |
| 3916 | |
| 3917 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3918 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3919 | file, linenum); |
| 3920 | |
| 3921 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3922 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3923 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3924 | /* set the header name and length into the proxy structure */ |
| 3925 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3926 | err_code |= ERR_WARN; |
| 3927 | |
| 3928 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3929 | ha_alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3930 | file, linenum, args[0]); |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3932 | goto out; |
| 3933 | } |
| 3934 | |
| 3935 | /* set the desired header name */ |
| 3936 | free(curproxy->server_id_hdr_name); |
| 3937 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3938 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3939 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3940 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3941 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3942 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3943 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3944 | ha_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] | 3945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3946 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3947 | } |
| 3948 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3949 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3950 | * be processed before all http-request rules, we put them into their own list |
| 3951 | * and will insert them at the end. |
| 3952 | */ |
| 3953 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3954 | if (!rule) { |
| 3955 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3956 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3957 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3958 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3959 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3960 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3961 | file, linenum); |
| 3962 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3963 | |
| 3964 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3965 | ha_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]); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3966 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3967 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3968 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3969 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3970 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3971 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3972 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3973 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3974 | goto out; |
| 3975 | } |
| 3976 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3977 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3978 | ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3979 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3981 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3982 | } |
| 3983 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3984 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3985 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3986 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3987 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3988 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3989 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3990 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3991 | struct switching_rule *rule; |
| 3992 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3993 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3994 | ha_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] | 3995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3996 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3997 | } |
| 3998 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3999 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4000 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4001 | |
| 4002 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4003 | ha_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] | 4004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4005 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4006 | } |
| 4007 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4008 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4009 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4010 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4011 | file, linenum, errmsg); |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4012 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4013 | goto out; |
| 4014 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4015 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4016 | 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] | 4017 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4018 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4019 | ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 4020 | file, linenum, args[2]); |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4022 | goto out; |
| 4023 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4024 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4025 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4026 | if (!rule) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4027 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4028 | goto out; |
| 4029 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4030 | rule->cond = cond; |
| 4031 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4032 | rule->line = linenum; |
| 4033 | rule->file = strdup(file); |
| 4034 | if (!rule->file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4035 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4036 | goto out; |
| 4037 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4038 | LIST_INIT(&rule->list); |
| 4039 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4040 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4041 | else if (strcmp(args[0], "use-server") == 0) { |
| 4042 | struct server_rule *rule; |
| 4043 | |
| 4044 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4045 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4046 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4047 | goto out; |
| 4048 | } |
| 4049 | |
| 4050 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4051 | err_code |= ERR_WARN; |
| 4052 | |
| 4053 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4054 | ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4056 | goto out; |
| 4057 | } |
| 4058 | |
| 4059 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4060 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4061 | file, linenum, args[0]); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4063 | goto out; |
| 4064 | } |
| 4065 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4066 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4067 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4068 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4069 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4070 | goto out; |
| 4071 | } |
| 4072 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4073 | 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] | 4074 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4075 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4076 | rule->cond = cond; |
| 4077 | rule->srv.name = strdup(args[1]); |
| 4078 | LIST_INIT(&rule->list); |
| 4079 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4080 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4081 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4082 | else if ((!strcmp(args[0], "force-persist")) || |
| 4083 | (!strcmp(args[0], "ignore-persist"))) { |
| 4084 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4085 | |
| 4086 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4087 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4089 | goto out; |
| 4090 | } |
| 4091 | |
Cyril Bonté | 4288c5a | 2018-03-12 22:02:59 +0100 | [diff] [blame] | 4092 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4093 | err_code |= ERR_WARN; |
| 4094 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4095 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4096 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4097 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4098 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4099 | goto out; |
| 4100 | } |
| 4101 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4102 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4103 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4104 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4105 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4106 | goto out; |
| 4107 | } |
| 4108 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4109 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4110 | * where force-persist is applied. |
| 4111 | */ |
| 4112 | 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] | 4113 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4114 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4115 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4116 | if (!strcmp(args[0], "force-persist")) { |
| 4117 | rule->type = PERSIST_TYPE_FORCE; |
| 4118 | } else { |
| 4119 | rule->type = PERSIST_TYPE_IGNORE; |
| 4120 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4121 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4122 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4123 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4124 | else if (!strcmp(args[0], "stick-table")) { |
| 4125 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4126 | struct proxy *other; |
| 4127 | |
Willy Tarreau | c786768 | 2018-07-27 10:26:22 +0200 | [diff] [blame] | 4128 | if (curproxy == &defproxy) { |
| 4129 | ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n", |
| 4130 | file, linenum); |
| 4131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4132 | goto out; |
| 4133 | } |
| 4134 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4135 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4136 | if (other) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4137 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4138 | file, linenum, curproxy->id, proxy_type_str(other), other->id, other->conf.file, other->conf.line); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4139 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4140 | goto out; |
| 4141 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4142 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4143 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4144 | curproxy->table.type = (unsigned int)-1; |
| 4145 | while (*args[myidx]) { |
| 4146 | const char *err; |
| 4147 | |
| 4148 | if (strcmp(args[myidx], "size") == 0) { |
| 4149 | myidx++; |
| 4150 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4151 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4152 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4154 | goto out; |
| 4155 | } |
| 4156 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4157 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4158 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4160 | goto out; |
| 4161 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4162 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4163 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4164 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4165 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4166 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4167 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4168 | file, linenum, args[myidx-1]); |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4169 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4170 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4171 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4172 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4173 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4174 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4175 | myidx++; |
| 4176 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4177 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4178 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4179 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4180 | goto out; |
| 4181 | } |
| 4182 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4183 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4184 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4185 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4186 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4187 | goto out; |
| 4188 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4189 | if (val > INT_MAX) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4190 | ha_alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4191 | file, linenum, val); |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4193 | goto out; |
| 4194 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4195 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4196 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4197 | } |
| 4198 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4199 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4200 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4201 | } |
| 4202 | else if (strcmp(args[myidx], "type") == 0) { |
| 4203 | myidx++; |
| 4204 | if (stktable_parse_type(args, &myidx, &curproxy->table.type, &curproxy->table.key_size) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4205 | ha_alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4206 | file, linenum, args[myidx]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4208 | goto out; |
| 4209 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4210 | /* myidx already points to next arg */ |
| 4211 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4212 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4213 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4214 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4215 | |
| 4216 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4217 | nw = args[myidx]; |
| 4218 | while (*nw) { |
| 4219 | /* the "store" keyword supports a comma-separated list */ |
| 4220 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4221 | sa = NULL; /* store arg */ |
| 4222 | while (*nw && *nw != ',') { |
| 4223 | if (*nw == '(') { |
| 4224 | *nw = 0; |
| 4225 | sa = ++nw; |
| 4226 | while (*nw != ')') { |
| 4227 | if (!*nw) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4228 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4229 | file, linenum, args[0], cw); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
| 4232 | } |
| 4233 | nw++; |
| 4234 | } |
| 4235 | *nw = '\0'; |
| 4236 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4237 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4238 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4239 | if (*nw) |
| 4240 | *nw++ = '\0'; |
| 4241 | type = stktable_get_data_type(cw); |
| 4242 | if (type < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4243 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4244 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4246 | goto out; |
| 4247 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4248 | |
| 4249 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4250 | switch (err) { |
| 4251 | case PE_NONE: break; |
| 4252 | case PE_EXIST: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4253 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4254 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4255 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4256 | break; |
| 4257 | |
| 4258 | case PE_ARG_MISSING: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4259 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4260 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4262 | goto out; |
| 4263 | |
| 4264 | case PE_ARG_NOT_USED: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4265 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4266 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4268 | goto out; |
| 4269 | |
| 4270 | default: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4271 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4272 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4273 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4274 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4275 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4276 | } |
| 4277 | myidx++; |
| 4278 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4279 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4280 | ha_alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4281 | file, linenum, args[myidx]); |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4284 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | if (!curproxy->table.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4288 | ha_alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4289 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4290 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4291 | goto out; |
| 4292 | } |
| 4293 | |
| 4294 | if (curproxy->table.type == (unsigned int)-1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4295 | ha_alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4296 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4298 | goto out; |
| 4299 | } |
| 4300 | } |
| 4301 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4302 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4303 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4304 | int myidx = 0; |
| 4305 | const char *name = NULL; |
| 4306 | int flags; |
| 4307 | |
| 4308 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4309 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4311 | goto out; |
| 4312 | } |
| 4313 | |
| 4314 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4315 | err_code |= ERR_WARN; |
| 4316 | goto out; |
| 4317 | } |
| 4318 | |
| 4319 | myidx++; |
| 4320 | if ((strcmp(args[myidx], "store") == 0) || |
| 4321 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4322 | myidx++; |
| 4323 | flags = STK_IS_STORE; |
| 4324 | } |
| 4325 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4326 | myidx++; |
| 4327 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4328 | } |
| 4329 | else if (strcmp(args[myidx], "match") == 0) { |
| 4330 | myidx++; |
| 4331 | flags = STK_IS_MATCH; |
| 4332 | } |
| 4333 | else if (strcmp(args[myidx], "on") == 0) { |
| 4334 | myidx++; |
| 4335 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4336 | } |
| 4337 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4338 | ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4340 | goto out; |
| 4341 | } |
| 4342 | |
| 4343 | if (*(args[myidx]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4344 | ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4346 | goto out; |
| 4347 | } |
| 4348 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4349 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4350 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4351 | if (!expr) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4352 | ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4354 | goto out; |
| 4355 | } |
| 4356 | |
| 4357 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4358 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4359 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4360 | 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] | 4361 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4362 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4363 | goto out; |
| 4364 | } |
| 4365 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4366 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4367 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4368 | 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] | 4369 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4370 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4371 | goto out; |
| 4372 | } |
| 4373 | } |
| 4374 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4375 | /* 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] | 4376 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4377 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4378 | if (strcmp(args[myidx], "table") == 0) { |
| 4379 | myidx++; |
| 4380 | name = args[myidx++]; |
| 4381 | } |
| 4382 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4383 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4384 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4385 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4386 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4387 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4388 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4389 | goto out; |
| 4390 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4391 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4392 | else if (*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4393 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4394 | file, linenum, args[0], args[myidx]); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4395 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4396 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4397 | goto out; |
| 4398 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4399 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4400 | 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] | 4401 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4402 | 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] | 4403 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4404 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4405 | rule->cond = cond; |
| 4406 | rule->expr = expr; |
| 4407 | rule->flags = flags; |
| 4408 | rule->table.name = name ? strdup(name) : NULL; |
| 4409 | LIST_INIT(&rule->list); |
| 4410 | if (flags & STK_ON_RSP) |
| 4411 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4412 | else |
| 4413 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4414 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4415 | else if (!strcmp(args[0], "stats")) { |
| 4416 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4417 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4418 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4419 | if (!*args[1]) { |
| 4420 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4421 | } else if (!strcmp(args[1], "admin")) { |
| 4422 | struct stats_admin_rule *rule; |
| 4423 | |
| 4424 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4425 | ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4427 | goto out; |
| 4428 | } |
| 4429 | |
| 4430 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4431 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4432 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4433 | goto out; |
| 4434 | } |
| 4435 | |
| 4436 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4437 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4438 | file, linenum, args[0], args[1]); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4440 | goto out; |
| 4441 | } |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4442 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4443 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4444 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4446 | goto out; |
| 4447 | } |
| 4448 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4449 | err_code |= warnif_cond_conflicts(cond, |
| 4450 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4451 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4452 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4453 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4454 | rule->cond = cond; |
| 4455 | LIST_INIT(&rule->list); |
| 4456 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4457 | } else if (!strcmp(args[1], "uri")) { |
| 4458 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4459 | ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4461 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4462 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4463 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4464 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4465 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4466 | } |
| 4467 | } else if (!strcmp(args[1], "realm")) { |
| 4468 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4469 | ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4471 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4472 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4473 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4474 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4475 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4476 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4477 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4478 | unsigned interval; |
| 4479 | |
| 4480 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4481 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4482 | ha_alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4483 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4485 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4486 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4487 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4488 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4489 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4490 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4491 | } 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] | 4492 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4493 | |
| 4494 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4495 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4497 | goto out; |
| 4498 | } |
| 4499 | |
| 4500 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4501 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4502 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4503 | goto out; |
| 4504 | } |
| 4505 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4506 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4507 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4508 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4509 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4510 | err_code |= ERR_WARN; |
| 4511 | } |
| 4512 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4513 | 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] | 4514 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4515 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4516 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4517 | goto out; |
| 4518 | } |
| 4519 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4520 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4521 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4522 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4523 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4524 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4525 | } else if (!strcmp(args[1], "auth")) { |
| 4526 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4527 | ha_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] | 4528 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4529 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4530 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4531 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4532 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4533 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4534 | } |
| 4535 | } else if (!strcmp(args[1], "scope")) { |
| 4536 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4537 | ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4539 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4540 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4541 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4542 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4544 | } |
| 4545 | } else if (!strcmp(args[1], "enable")) { |
| 4546 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4547 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4548 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4549 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4550 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4551 | } else if (!strcmp(args[1], "hide-version")) { |
| 4552 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4553 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4554 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4555 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4556 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4557 | } else if (!strcmp(args[1], "show-legends")) { |
| 4558 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4559 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4560 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4561 | goto out; |
| 4562 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4563 | } else if (!strcmp(args[1], "show-node")) { |
| 4564 | |
| 4565 | if (*args[2]) { |
| 4566 | int i; |
| 4567 | char c; |
| 4568 | |
| 4569 | for (i=0; args[2][i]; i++) { |
| 4570 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4571 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4572 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4573 | break; |
| 4574 | } |
| 4575 | |
| 4576 | if (!i || args[2][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4577 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4578 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4579 | file, linenum, args[0], args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4581 | goto out; |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4586 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4587 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4588 | goto out; |
| 4589 | } |
| 4590 | } else if (!strcmp(args[1], "show-desc")) { |
| 4591 | char *desc = NULL; |
| 4592 | |
| 4593 | if (*args[2]) { |
| 4594 | int i, len=0; |
| 4595 | char *d; |
| 4596 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4597 | for (i = 2; *args[i]; i++) |
| 4598 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4599 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4600 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4601 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4602 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4603 | for (i = 3; *args[i]; i++) |
| 4604 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | if (!*args[2] && !global.desc) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4608 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4609 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4610 | else { |
| 4611 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4612 | free(desc); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4613 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4614 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4615 | goto out; |
| 4616 | } |
| 4617 | free(desc); |
| 4618 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4619 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4620 | stats_error_parsing: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4621 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 4622 | 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] | 4623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4624 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4625 | } |
| 4626 | } |
| 4627 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4628 | int optnum; |
| 4629 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4630 | if (*(args[1]) == '\0') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4631 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4632 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4634 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4635 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4636 | |
| 4637 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4638 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4639 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4640 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4641 | file, linenum, cfg_opts[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4642 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4643 | goto out; |
| 4644 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4645 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4646 | goto out; |
| 4647 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4648 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4649 | err_code |= ERR_WARN; |
| 4650 | goto out; |
| 4651 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4652 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4653 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4654 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4655 | |
| 4656 | switch (kwm) { |
| 4657 | case KWM_STD: |
| 4658 | curproxy->options |= cfg_opts[optnum].val; |
| 4659 | break; |
| 4660 | case KWM_NO: |
| 4661 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4662 | break; |
| 4663 | case KWM_DEF: /* already cleared */ |
| 4664 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4665 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4666 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4667 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4668 | } |
| 4669 | } |
| 4670 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4671 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4672 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4673 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4674 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4675 | file, linenum, cfg_opts2[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4677 | goto out; |
| 4678 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4679 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4680 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4681 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4682 | err_code |= ERR_WARN; |
| 4683 | goto out; |
| 4684 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4685 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4686 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4687 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4688 | |
| 4689 | switch (kwm) { |
| 4690 | case KWM_STD: |
| 4691 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4692 | break; |
| 4693 | case KWM_NO: |
| 4694 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4695 | break; |
| 4696 | case KWM_DEF: /* already cleared */ |
| 4697 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4698 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4699 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4703 | /* HTTP options override each other. They can be cancelled using |
| 4704 | * "no option xxx" which only switches to default mode if the mode |
| 4705 | * was this one (useful for cancelling options set in defaults |
| 4706 | * sections). |
| 4707 | */ |
Christopher Faulet | 315b39c | 2018-09-21 16:26:19 +0200 | [diff] [blame] | 4708 | if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4709 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4710 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4711 | if (kwm == KWM_STD) { |
| 4712 | curproxy->options &= ~PR_O_HTTP_MODE; |
Christopher Faulet | 315b39c | 2018-09-21 16:26:19 +0200 | [diff] [blame] | 4713 | curproxy->options |= PR_O_HTTP_CLO; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4714 | goto out; |
| 4715 | } |
| 4716 | else if (kwm == KWM_NO) { |
Christopher Faulet | 315b39c | 2018-09-21 16:26:19 +0200 | [diff] [blame] | 4717 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO) |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4718 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4719 | goto out; |
| 4720 | } |
| 4721 | } |
| 4722 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4723 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4724 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4725 | if (kwm == KWM_STD) { |
| 4726 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4727 | curproxy->options |= PR_O_HTTP_SCL; |
| 4728 | goto out; |
| 4729 | } |
| 4730 | else if (kwm == KWM_NO) { |
| 4731 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4732 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4733 | goto out; |
| 4734 | } |
| 4735 | } |
| 4736 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4737 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4738 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4739 | if (kwm == KWM_STD) { |
| 4740 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4741 | curproxy->options |= PR_O_HTTP_KAL; |
| 4742 | goto out; |
| 4743 | } |
| 4744 | else if (kwm == KWM_NO) { |
| 4745 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4746 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4747 | goto out; |
| 4748 | } |
| 4749 | } |
| 4750 | else if (strcmp(args[1], "http-tunnel") == 0) { |
Christopher Faulet | 4212a30 | 2018-09-21 10:42:19 +0200 | [diff] [blame] | 4751 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[1], NULL)) { |
| 4752 | err_code |= ERR_WARN; |
| 4753 | goto out; |
| 4754 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4755 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4756 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4757 | if (kwm == KWM_STD) { |
| 4758 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4759 | curproxy->options |= PR_O_HTTP_TUN; |
| 4760 | goto out; |
| 4761 | } |
| 4762 | else if (kwm == KWM_NO) { |
| 4763 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4764 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4765 | goto out; |
| 4766 | } |
| 4767 | } |
| 4768 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4769 | /* Redispatch can take an integer argument that control when the |
| 4770 | * resispatch occurs. All values are relative to the retries option. |
| 4771 | * This can be cancelled using "no option xxx". |
| 4772 | */ |
| 4773 | if (strcmp(args[1], "redispatch") == 0) { |
| 4774 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4775 | err_code |= ERR_WARN; |
| 4776 | goto out; |
| 4777 | } |
| 4778 | |
| 4779 | curproxy->no_options &= ~PR_O_REDISP; |
| 4780 | curproxy->options &= ~PR_O_REDISP; |
| 4781 | |
| 4782 | switch (kwm) { |
| 4783 | case KWM_STD: |
| 4784 | curproxy->options |= PR_O_REDISP; |
| 4785 | curproxy->redispatch_after = -1; |
| 4786 | if(*args[2]) { |
| 4787 | curproxy->redispatch_after = atol(args[2]); |
| 4788 | } |
| 4789 | break; |
| 4790 | case KWM_NO: |
| 4791 | curproxy->no_options |= PR_O_REDISP; |
| 4792 | curproxy->redispatch_after = 0; |
| 4793 | break; |
| 4794 | case KWM_DEF: /* already cleared */ |
| 4795 | break; |
| 4796 | } |
| 4797 | goto out; |
| 4798 | } |
| 4799 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4800 | if (kwm != KWM_STD) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4801 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 4802 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4804 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4807 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4808 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4809 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4810 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4811 | if (*(args[2]) != '\0') { |
| 4812 | if (!strcmp(args[2], "clf")) { |
| 4813 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4814 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4815 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4816 | ha_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] | 4817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4818 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4819 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4820 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4821 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4822 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4823 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4824 | char *oldlogformat = "log-format"; |
| 4825 | char *clflogformat = ""; |
| 4826 | |
| 4827 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4828 | oldlogformat = "option httplog"; |
| 4829 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4830 | oldlogformat = "option tcplog"; |
| 4831 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4832 | oldlogformat = "option httplog clf"; |
| 4833 | if (logformat == clf_http_log_format) |
| 4834 | clflogformat = " clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4835 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 4836 | file, linenum, clflogformat, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4837 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4838 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4839 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4840 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4841 | free(curproxy->conf.logformat_string); |
| 4842 | curproxy->conf.logformat_string = logformat; |
| 4843 | |
| 4844 | free(curproxy->conf.lfs_file); |
| 4845 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4846 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4847 | |
| 4848 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4849 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 4850 | file, linenum, curproxy->id); |
| 4851 | err_code |= ERR_WARN; |
| 4852 | } |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4853 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4854 | else if (!strcmp(args[1], "tcplog")) { |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4855 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4856 | char *oldlogformat = "log-format"; |
| 4857 | |
| 4858 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4859 | oldlogformat = "option httplog"; |
| 4860 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4861 | oldlogformat = "option tcplog"; |
| 4862 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4863 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4864 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 4865 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4866 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4867 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4868 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4869 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4870 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4871 | free(curproxy->conf.logformat_string); |
| 4872 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4873 | |
| 4874 | free(curproxy->conf.lfs_file); |
| 4875 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4876 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4877 | |
| 4878 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4879 | goto out; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4880 | |
| 4881 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4882 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 4883 | file, linenum, curproxy->id); |
| 4884 | err_code |= ERR_WARN; |
| 4885 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4886 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4887 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4888 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4889 | 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] | 4890 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4891 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4892 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4893 | goto out; |
| 4894 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4895 | if (curproxy->cap & PR_CAP_FE) |
| 4896 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4897 | if (curproxy->cap & PR_CAP_BE) |
| 4898 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4899 | } |
| 4900 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4901 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4902 | err_code |= ERR_WARN; |
| 4903 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4905 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4906 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4907 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4908 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4909 | if (!*args[2]) { /* no argument */ |
| 4910 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4911 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4912 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4913 | 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] | 4914 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4915 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4916 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4917 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4918 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4919 | if (*args[4]) |
| 4920 | reqlen += strlen(args[4]); |
| 4921 | else |
| 4922 | reqlen += strlen("HTTP/1.0"); |
| 4923 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4924 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4925 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4926 | "%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] | 4927 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4928 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4929 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4930 | } |
| 4931 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4932 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4933 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4934 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4935 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4936 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4937 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4938 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4939 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4940 | |
| 4941 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4942 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4943 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4944 | else if (!strcmp(args[1], "smtpchk")) { |
| 4945 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4946 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4947 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4948 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4949 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4950 | |
| 4951 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4952 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4953 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4954 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4955 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4956 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4957 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4958 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4959 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4960 | } else { |
| 4961 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4962 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4963 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4964 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4965 | } |
| 4966 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4967 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4968 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4969 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4970 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4971 | /* use PostgreSQL request to check servers' health */ |
| 4972 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4973 | err_code |= ERR_WARN; |
| 4974 | |
| 4975 | free(curproxy->check_req); |
| 4976 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4977 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4978 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4979 | |
| 4980 | if (*(args[2])) { |
| 4981 | int cur_arg = 2; |
| 4982 | |
| 4983 | while (*(args[cur_arg])) { |
| 4984 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4985 | char * packet; |
| 4986 | uint32_t packet_len; |
| 4987 | uint32_t pv; |
| 4988 | |
| 4989 | /* suboption header - needs additional argument for it */ |
| 4990 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4991 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4992 | file, linenum, args[0], args[1], args[cur_arg]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4994 | goto out; |
| 4995 | } |
| 4996 | |
| 4997 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4998 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4999 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 5000 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5001 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5002 | |
| 5003 | memcpy(packet + 4, &pv, 4); |
| 5004 | |
| 5005 | /* copy "user" */ |
| 5006 | memcpy(packet + 8, "user", 4); |
| 5007 | |
| 5008 | /* copy username */ |
| 5009 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 5010 | |
| 5011 | free(curproxy->check_req); |
| 5012 | curproxy->check_req = packet; |
| 5013 | curproxy->check_len = packet_len; |
| 5014 | |
| 5015 | packet_len = htonl(packet_len); |
| 5016 | memcpy(packet, &packet_len, 4); |
| 5017 | cur_arg += 2; |
| 5018 | } else { |
| 5019 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5020 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5021 | file, linenum, args[0], args[1]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5023 | goto out; |
| 5024 | } |
| 5025 | } /* end while loop */ |
| 5026 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5027 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 5028 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5031 | else if (!strcmp(args[1], "redis-check")) { |
| 5032 | /* use REDIS PING request to check servers' health */ |
| 5033 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5034 | err_code |= ERR_WARN; |
| 5035 | |
| 5036 | free(curproxy->check_req); |
| 5037 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5038 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5039 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 5040 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5041 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5042 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 5043 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5044 | |
| 5045 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5046 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5047 | } |
| 5048 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5049 | else if (!strcmp(args[1], "mysql-check")) { |
| 5050 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5051 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5052 | err_code |= ERR_WARN; |
| 5053 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5054 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 5055 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5056 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5057 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
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 | /* 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] | 5060 | * const char mysql40_client_auth_pkt[] = { |
| 5061 | * "\x0e\x00\x00" // packet length |
| 5062 | * "\x01" // packet number |
| 5063 | * "\x00\x00" // client capabilities |
| 5064 | * "\x00\x00\x01" // max packet |
| 5065 | * "haproxy\x00" // username (null terminated string) |
| 5066 | * "\x00" // filler (always 0x00) |
| 5067 | * "\x01\x00\x00" // packet length |
| 5068 | * "\x00" // packet number |
| 5069 | * "\x01" // COM_QUIT command |
| 5070 | * }; |
| 5071 | */ |
| 5072 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5073 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5074 | * const char mysql41_client_auth_pkt[] = { |
| 5075 | * "\x0e\x00\x00\" // packet length |
| 5076 | * "\x01" // packet number |
| 5077 | * "\x00\x00\x00\x00" // client capabilities |
| 5078 | * "\x00\x00\x00\x01" // max packet |
| 5079 | * "\x21" // character set (UTF-8) |
| 5080 | * char[23] // All zeroes |
| 5081 | * "haproxy\x00" // username (null terminated string) |
| 5082 | * "\x00" // filler (always 0x00) |
| 5083 | * "\x01\x00\x00" // packet length |
| 5084 | * "\x00" // packet number |
| 5085 | * "\x01" // COM_QUIT command |
| 5086 | * }; |
| 5087 | */ |
| 5088 | |
| 5089 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5090 | if (*(args[2])) { |
| 5091 | int cur_arg = 2; |
| 5092 | |
| 5093 | while (*(args[cur_arg])) { |
| 5094 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5095 | char *mysqluser; |
| 5096 | int packetlen, reqlen, userlen; |
| 5097 | |
| 5098 | /* suboption header - needs additional argument for it */ |
| 5099 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5100 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5101 | file, linenum, args[0], args[1], args[cur_arg]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5102 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5103 | goto out; |
| 5104 | } |
| 5105 | mysqluser = args[cur_arg + 1]; |
| 5106 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5107 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5108 | if (*(args[cur_arg+2])) { |
| 5109 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5110 | packetlen = userlen + 7 + 27; |
| 5111 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5112 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5113 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5114 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5115 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5116 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5117 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5118 | ((unsigned char) packetlen & 0xff), |
| 5119 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5120 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5121 | |
| 5122 | curproxy->check_req[3] = 1; |
Olivier Houchard | 3332090 | 2018-10-16 18:39:38 +0200 | [diff] [blame] | 5123 | curproxy->check_req[5] = 0x82; // 130 |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5124 | curproxy->check_req[11] = 1; |
| 5125 | curproxy->check_req[12] = 33; |
| 5126 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5127 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5128 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5129 | cur_arg += 3; |
| 5130 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5131 | ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'post-41'.\n", file, linenum, args[cur_arg+2]); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5132 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5133 | goto out; |
| 5134 | } |
| 5135 | } else { |
| 5136 | packetlen = userlen + 7; |
| 5137 | reqlen = packetlen + 9; |
| 5138 | |
| 5139 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5140 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5141 | curproxy->check_len = reqlen; |
| 5142 | |
| 5143 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5144 | ((unsigned char) packetlen & 0xff), |
| 5145 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5146 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5147 | |
| 5148 | curproxy->check_req[3] = 1; |
Olivier Houchard | 3332090 | 2018-10-16 18:39:38 +0200 | [diff] [blame] | 5149 | curproxy->check_req[5] = 0x80; |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5150 | curproxy->check_req[8] = 1; |
| 5151 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5152 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5153 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5154 | cur_arg += 2; |
| 5155 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5156 | } else { |
| 5157 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5158 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5159 | file, linenum, args[0], args[1]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5161 | goto out; |
| 5162 | } |
| 5163 | } /* end while loop */ |
| 5164 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5165 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5166 | else if (!strcmp(args[1], "ldap-check")) { |
| 5167 | /* use LDAP request to check servers' health */ |
| 5168 | free(curproxy->check_req); |
| 5169 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5170 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5171 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5172 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5173 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5174 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5175 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5176 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5177 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5178 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5179 | else if (!strcmp(args[1], "spop-check")) { |
| 5180 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5181 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5182 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5183 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5184 | goto out; |
| 5185 | } |
| 5186 | if (curproxy->cap & PR_CAP_FE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5187 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5188 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5190 | goto out; |
| 5191 | } |
| 5192 | |
| 5193 | /* use SPOE request to check servers' health */ |
| 5194 | free(curproxy->check_req); |
| 5195 | curproxy->check_req = NULL; |
| 5196 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5197 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5198 | |
Christopher Faulet | 8ef7525 | 2017-02-20 22:56:03 +0100 | [diff] [blame] | 5199 | if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5200 | ha_alert("parsing [%s:%d] : failed to prepare SPOP healthcheck request.\n", file, linenum); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5202 | goto out; |
| 5203 | } |
| 5204 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5205 | goto out; |
| 5206 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5207 | else if (!strcmp(args[1], "tcp-check")) { |
| 5208 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5209 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5210 | err_code |= ERR_WARN; |
| 5211 | |
| 5212 | free(curproxy->check_req); |
| 5213 | curproxy->check_req = NULL; |
| 5214 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5215 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5216 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5217 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5218 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5219 | else if (!strcmp(args[1], "external-check")) { |
| 5220 | /* excute an external command to check servers' health */ |
| 5221 | free(curproxy->check_req); |
| 5222 | curproxy->check_req = NULL; |
| 5223 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5224 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5225 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5226 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5227 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5228 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5229 | int cur_arg; |
| 5230 | |
| 5231 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5232 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5233 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5234 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5235 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5236 | |
| 5237 | free(curproxy->fwdfor_hdr_name); |
| 5238 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5239 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5240 | |
| 5241 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5242 | cur_arg = 2; |
| 5243 | while (*(args[cur_arg])) { |
| 5244 | if (!strcmp(args[cur_arg], "except")) { |
| 5245 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5246 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5247 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5248 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5250 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5251 | } |
| 5252 | /* flush useless bits */ |
| 5253 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5254 | cur_arg += 2; |
| 5255 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5256 | /* suboption header - needs additional argument for it */ |
| 5257 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5258 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5259 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5261 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5262 | } |
| 5263 | free(curproxy->fwdfor_hdr_name); |
| 5264 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5265 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5266 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5267 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5268 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5269 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5270 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5271 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5272 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 5273 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5275 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5276 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5277 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5278 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5279 | else if (!strcmp(args[1], "originalto")) { |
| 5280 | int cur_arg; |
| 5281 | |
| 5282 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5283 | * set default options (ie: bitfield, header name, etc) |
| 5284 | */ |
| 5285 | |
| 5286 | curproxy->options |= PR_O_ORGTO; |
| 5287 | |
| 5288 | free(curproxy->orgto_hdr_name); |
| 5289 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5290 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5291 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5292 | /* 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] | 5293 | cur_arg = 2; |
| 5294 | while (*(args[cur_arg])) { |
| 5295 | if (!strcmp(args[cur_arg], "except")) { |
| 5296 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5297 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5298 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5299 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5300 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5301 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5302 | } |
| 5303 | /* flush useless bits */ |
| 5304 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5305 | cur_arg += 2; |
| 5306 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5307 | /* suboption header - needs additional argument for it */ |
| 5308 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5309 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5310 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5311 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5312 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5313 | } |
| 5314 | free(curproxy->orgto_hdr_name); |
| 5315 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5316 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5317 | cur_arg += 2; |
| 5318 | } else { |
| 5319 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5320 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5321 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5323 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5324 | } |
| 5325 | } /* end while loop */ |
| 5326 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5327 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5328 | ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5330 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5331 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5332 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5333 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5334 | else if (!strcmp(args[0], "default_backend")) { |
| 5335 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5336 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5337 | |
| 5338 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5339 | ha_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] | 5340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5341 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5342 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5343 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5344 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5345 | |
| 5346 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5347 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5348 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5349 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5350 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5351 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5352 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5353 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5354 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n", |
| 5355 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5356 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5357 | /* enable reconnections to dispatch */ |
| 5358 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5359 | |
| 5360 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5361 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5362 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5363 | else if (!strcmp(args[0], "http-reuse")) { |
| 5364 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5365 | err_code |= ERR_WARN; |
| 5366 | |
| 5367 | if (strcmp(args[1], "never") == 0) { |
| 5368 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5369 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5370 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5371 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5372 | goto out; |
| 5373 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5374 | else if (strcmp(args[1], "safe") == 0) { |
| 5375 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5376 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5377 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5378 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5379 | goto out; |
| 5380 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5381 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5382 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5383 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5384 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5385 | goto out; |
| 5386 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5387 | else if (strcmp(args[1], "always") == 0) { |
| 5388 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5389 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5390 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5391 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5392 | goto out; |
| 5393 | } |
| 5394 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5395 | ha_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] | 5396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5397 | goto out; |
| 5398 | } |
| 5399 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5400 | else if (!strcmp(args[0], "http-check")) { |
| 5401 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5402 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5403 | |
| 5404 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5405 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5406 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5407 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5408 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5409 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5410 | else if (strcmp(args[1], "send-state") == 0) { |
| 5411 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5412 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5413 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5414 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5415 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5416 | else if (strcmp(args[1], "expect") == 0) { |
| 5417 | const char *ptr_arg; |
| 5418 | int cur_arg; |
| 5419 | |
| 5420 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5421 | ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5423 | goto out; |
| 5424 | } |
| 5425 | |
| 5426 | cur_arg = 2; |
| 5427 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5428 | while (*(ptr_arg = args[cur_arg])) { |
| 5429 | while (*ptr_arg == '!') { |
| 5430 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5431 | ptr_arg++; |
| 5432 | } |
| 5433 | if (*ptr_arg) |
| 5434 | break; |
| 5435 | cur_arg++; |
| 5436 | } |
| 5437 | /* now ptr_arg points to the beginning of a word past any possible |
| 5438 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5439 | */ |
| 5440 | if (strcmp(ptr_arg, "status") == 0) { |
| 5441 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5442 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5443 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5444 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5445 | goto out; |
| 5446 | } |
| 5447 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5448 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5449 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5450 | } |
| 5451 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5452 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5453 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5454 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5456 | goto out; |
| 5457 | } |
| 5458 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5459 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5460 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5461 | } |
| 5462 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5463 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5464 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5465 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5467 | goto out; |
| 5468 | } |
| 5469 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5470 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5471 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5472 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5473 | free(curproxy->expect_regex); |
| 5474 | curproxy->expect_regex = NULL; |
| 5475 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5476 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5477 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5478 | error = NULL; |
| 5479 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5480 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5481 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5482 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5484 | goto out; |
| 5485 | } |
| 5486 | } |
| 5487 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5488 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5489 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5490 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5492 | goto out; |
| 5493 | } |
| 5494 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5495 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5496 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5497 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5498 | free(curproxy->expect_regex); |
| 5499 | curproxy->expect_regex = NULL; |
| 5500 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5501 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5502 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5503 | error = NULL; |
| 5504 | if (!regex_comp(args[cur_arg + 1], curproxy->expect_regex, 1, 1, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5505 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5506 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5507 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5508 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5509 | goto out; |
| 5510 | } |
| 5511 | } |
| 5512 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5513 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5514 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5516 | goto out; |
| 5517 | } |
| 5518 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5519 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5520 | ha_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] | 5521 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5522 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5523 | } |
| 5524 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5525 | else if (!strcmp(args[0], "tcp-check")) { |
| 5526 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5527 | err_code |= ERR_WARN; |
| 5528 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5529 | if (strcmp(args[1], "comment") == 0) { |
| 5530 | int cur_arg; |
| 5531 | struct tcpcheck_rule *tcpcheck; |
| 5532 | |
| 5533 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5534 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5535 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5536 | |
| 5537 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5538 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5539 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5541 | goto out; |
| 5542 | } |
| 5543 | |
| 5544 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5545 | |
| 5546 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5547 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5548 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5549 | } |
| 5550 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5551 | const char *ptr_arg; |
| 5552 | int cur_arg; |
| 5553 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5554 | |
| 5555 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5556 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5557 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5558 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5559 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5560 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5561 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5562 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5563 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5564 | ha_alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5565 | file, linenum); |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5567 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5571 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5572 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5573 | |
| 5574 | /* parsing each parameters to fill up the rule */ |
| 5575 | while (*(ptr_arg = args[cur_arg])) { |
| 5576 | /* tcp port */ |
| 5577 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5578 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5579 | (atol(args[cur_arg + 1]) < 1) ){ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5580 | ha_alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5581 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5582 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5583 | goto out; |
| 5584 | } |
| 5585 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5586 | cur_arg += 2; |
| 5587 | } |
| 5588 | /* send proxy protocol */ |
| 5589 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5590 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5591 | cur_arg++; |
| 5592 | } |
| 5593 | #ifdef USE_OPENSSL |
| 5594 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5595 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5596 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5597 | cur_arg++; |
| 5598 | } |
| 5599 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5600 | /* comment for this tcpcheck line */ |
| 5601 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5602 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5603 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5604 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5605 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5606 | goto out; |
| 5607 | } |
| 5608 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5609 | cur_arg += 2; |
| 5610 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5611 | else { |
| 5612 | #ifdef USE_OPENSSL |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5613 | ha_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] | 5614 | #else /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5615 | ha_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] | 5616 | #endif /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5617 | file, linenum, args[0], args[1], args[cur_arg]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5619 | goto out; |
| 5620 | } |
| 5621 | |
| 5622 | } |
| 5623 | |
| 5624 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5625 | } |
| 5626 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5627 | if (! *(args[2]) ) { |
| 5628 | /* SEND string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5629 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5630 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5632 | goto out; |
| 5633 | } else { |
| 5634 | struct tcpcheck_rule *tcpcheck; |
| 5635 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5636 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5637 | |
| 5638 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5639 | tcpcheck->string_len = strlen(args[2]); |
| 5640 | tcpcheck->string = strdup(args[2]); |
| 5641 | tcpcheck->expect_regex = NULL; |
| 5642 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5643 | /* comment for this tcpcheck line */ |
| 5644 | if (strcmp(args[3], "comment") == 0) { |
| 5645 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5646 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5647 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5649 | goto out; |
| 5650 | } |
| 5651 | tcpcheck->comment = strdup(args[4]); |
| 5652 | } |
| 5653 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5654 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5655 | } |
| 5656 | } |
| 5657 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5658 | if (! *(args[2]) ) { |
| 5659 | /* SEND binary string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5660 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5661 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5663 | goto out; |
| 5664 | } else { |
| 5665 | struct tcpcheck_rule *tcpcheck; |
| 5666 | char *err = NULL; |
| 5667 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5668 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5669 | |
| 5670 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5671 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5672 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5673 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5675 | goto out; |
| 5676 | } |
| 5677 | tcpcheck->expect_regex = NULL; |
| 5678 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5679 | /* comment for this tcpcheck line */ |
| 5680 | if (strcmp(args[3], "comment") == 0) { |
| 5681 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5682 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5683 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5685 | goto out; |
| 5686 | } |
| 5687 | tcpcheck->comment = strdup(args[4]); |
| 5688 | } |
| 5689 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5690 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5691 | } |
| 5692 | } |
| 5693 | else if (strcmp(args[1], "expect") == 0) { |
| 5694 | const char *ptr_arg; |
| 5695 | int cur_arg; |
| 5696 | int inverse = 0; |
| 5697 | |
| 5698 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5699 | ha_alert("parsing [%s:%d] : '%s %s' already specified.\n", file, linenum, args[0], args[1]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5700 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5701 | goto out; |
| 5702 | } |
| 5703 | |
| 5704 | cur_arg = 2; |
| 5705 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5706 | while (*(ptr_arg = args[cur_arg])) { |
| 5707 | while (*ptr_arg == '!') { |
| 5708 | inverse = !inverse; |
| 5709 | ptr_arg++; |
| 5710 | } |
| 5711 | if (*ptr_arg) |
| 5712 | break; |
| 5713 | cur_arg++; |
| 5714 | } |
| 5715 | /* now ptr_arg points to the beginning of a word past any possible |
| 5716 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5717 | */ |
| 5718 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5719 | struct tcpcheck_rule *tcpcheck; |
| 5720 | char *err = NULL; |
| 5721 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5722 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5723 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5724 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5726 | goto out; |
| 5727 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5728 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5729 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5730 | |
| 5731 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5732 | if (parse_binary(args[cur_arg + 1], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5733 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5734 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5736 | goto out; |
| 5737 | } |
| 5738 | tcpcheck->expect_regex = NULL; |
| 5739 | tcpcheck->inverse = inverse; |
| 5740 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5741 | /* tcpcheck comment */ |
| 5742 | cur_arg += 2; |
| 5743 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5744 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5745 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5746 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5748 | goto out; |
| 5749 | } |
| 5750 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5751 | } |
| 5752 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5753 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5754 | } |
| 5755 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5756 | struct tcpcheck_rule *tcpcheck; |
| 5757 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5758 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5759 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5760 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5761 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5762 | goto out; |
| 5763 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5764 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5765 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5766 | |
| 5767 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5768 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5769 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5770 | tcpcheck->expect_regex = NULL; |
| 5771 | tcpcheck->inverse = inverse; |
| 5772 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5773 | /* tcpcheck comment */ |
| 5774 | cur_arg += 2; |
| 5775 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5776 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5777 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5778 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5779 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5780 | goto out; |
| 5781 | } |
| 5782 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5783 | } |
| 5784 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5785 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5786 | } |
| 5787 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5788 | struct tcpcheck_rule *tcpcheck; |
| 5789 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5790 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5791 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5792 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5794 | goto out; |
| 5795 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5796 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5797 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5798 | |
| 5799 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5800 | tcpcheck->string_len = 0; |
| 5801 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5802 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5803 | error = NULL; |
| 5804 | if (!regex_comp(args[cur_arg + 1], tcpcheck->expect_regex, 1, 1, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5805 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5806 | file, linenum, args[0], args[1], ptr_arg, args[cur_arg + 1], error); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5807 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5808 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5809 | goto out; |
| 5810 | } |
| 5811 | tcpcheck->inverse = inverse; |
| 5812 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5813 | /* tcpcheck comment */ |
| 5814 | cur_arg += 2; |
| 5815 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5816 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5817 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5818 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5820 | goto out; |
| 5821 | } |
| 5822 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5823 | } |
| 5824 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5825 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5826 | } |
| 5827 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5828 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5829 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5831 | goto out; |
| 5832 | } |
| 5833 | } |
| 5834 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5835 | ha_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] | 5836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5837 | goto out; |
| 5838 | } |
| 5839 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5840 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5841 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5842 | ha_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] | 5843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5844 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5845 | } |
| 5846 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5847 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5848 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5849 | |
| 5850 | if (strcmp(args[1], "fail") == 0) { |
| 5851 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5852 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5853 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5854 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5856 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5857 | } |
| 5858 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 5859 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 5860 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5861 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5862 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5864 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5865 | } |
| 5866 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5867 | } |
| 5868 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5869 | ha_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] | 5870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5871 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5872 | } |
| 5873 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5874 | #ifdef TPROXY |
| 5875 | else if (!strcmp(args[0], "transparent")) { |
| 5876 | /* enable transparent proxy connections */ |
| 5877 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5878 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5879 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5880 | } |
| 5881 | #endif |
| 5882 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5883 | 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] | 5884 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5885 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5886 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5887 | ha_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] | 5888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5889 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5890 | } |
| 5891 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5892 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5893 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5894 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5895 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5896 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5897 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5898 | |
| 5899 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5900 | ha_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] | 5901 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5902 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5903 | } |
| 5904 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5905 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5906 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5907 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5908 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5909 | 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] | 5910 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5911 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5912 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5913 | ha_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] | 5914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5915 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5916 | } |
| 5917 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5918 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5919 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5921 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5922 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5923 | ha_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] | 5924 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5925 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5926 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5927 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5928 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5929 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5930 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5932 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5933 | } |
| 5934 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5935 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5936 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5937 | } |
| 5938 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5939 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5940 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5941 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5942 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5943 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5944 | ha_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] | 5945 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5946 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5947 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5948 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5949 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5950 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5951 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5952 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5953 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5954 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5955 | goto out; |
| 5956 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5957 | |
| 5958 | proto = protocol_by_family(sk->ss_family); |
| 5959 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5960 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5961 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5963 | goto out; |
| 5964 | } |
| 5965 | |
| 5966 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5967 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5968 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5970 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5971 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5972 | |
| 5973 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5974 | ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5975 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5976 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5977 | goto out; |
| 5978 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5979 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5980 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5981 | goto out; |
| 5982 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5983 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5984 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5985 | } |
| 5986 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5987 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5988 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5989 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5990 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5991 | ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5993 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5994 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5995 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5996 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5997 | /** |
| 5998 | * The syntax for hash-type config element is |
| 5999 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 6000 | * |
| 6001 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 6002 | */ |
| 6003 | 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] | 6004 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6005 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 6006 | err_code |= ERR_WARN; |
| 6007 | |
| 6008 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6009 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 6010 | } |
| 6011 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6012 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 6013 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6014 | else if (strcmp(args[1], "avalanche") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6015 | ha_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]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6017 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 6018 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6019 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6020 | ha_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] | 6021 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6022 | goto out; |
| 6023 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6024 | |
| 6025 | /* set the hash function to use */ |
| 6026 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6027 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6028 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6029 | |
| 6030 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 6031 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 6032 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6033 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6034 | /* set the hash function */ |
| 6035 | if (!strcmp(args[2], "sdbm")) { |
| 6036 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 6037 | } |
| 6038 | else if (!strcmp(args[2], "djb2")) { |
| 6039 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6040 | } |
| 6041 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 6042 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6043 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6044 | else if (!strcmp(args[2], "crc32")) { |
| 6045 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 6046 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6047 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6048 | ha_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] | 6049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6050 | goto out; |
| 6051 | } |
| 6052 | |
| 6053 | /* set the hash modifier */ |
| 6054 | if (!strcmp(args[3], "avalanche")) { |
| 6055 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 6056 | } |
| 6057 | else if (*args[3]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6058 | ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6060 | goto out; |
| 6061 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 6062 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6063 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6064 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 6065 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6066 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6068 | goto out; |
| 6069 | } |
| 6070 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 6071 | if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6072 | ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6074 | goto out; |
| 6075 | } |
| 6076 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6077 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 6078 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6079 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6081 | goto out; |
| 6082 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6083 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6084 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6085 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6086 | goto out; |
| 6087 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6088 | free(curproxy->conf.uniqueid_format_string); |
| 6089 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6090 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6091 | free(curproxy->conf.uif_file); |
| 6092 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6093 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6094 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6095 | |
| 6096 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6097 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6098 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6099 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6100 | goto out; |
| 6101 | } |
| 6102 | free(curproxy->header_unique_id); |
| 6103 | curproxy->header_unique_id = strdup(args[1]); |
| 6104 | } |
| 6105 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6106 | else if (strcmp(args[0], "log-format") == 0) { |
| 6107 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6108 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6110 | goto out; |
| 6111 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6112 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6113 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6114 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6115 | goto out; |
| 6116 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6117 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 6118 | char *oldlogformat = "log-format"; |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6119 | |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6120 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 6121 | oldlogformat = "option httplog"; |
| 6122 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 6123 | oldlogformat = "option tcplog"; |
| 6124 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 6125 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6126 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 6127 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6128 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6129 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6130 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6131 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6132 | free(curproxy->conf.logformat_string); |
| 6133 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6134 | |
| 6135 | free(curproxy->conf.lfs_file); |
| 6136 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6137 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6138 | |
| 6139 | /* get a chance to improve log-format error reporting by |
| 6140 | * reporting the correct line-number when possible. |
| 6141 | */ |
| 6142 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6143 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6144 | file, linenum, curproxy->id); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6145 | err_code |= ERR_WARN; |
| 6146 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6147 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6148 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6149 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6150 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6152 | goto out; |
| 6153 | } |
| 6154 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6155 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6156 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6157 | goto out; |
| 6158 | } |
| 6159 | |
| 6160 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6161 | free(curproxy->conf.logformat_sd_string); |
| 6162 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6163 | |
| 6164 | free(curproxy->conf.lfsd_file); |
| 6165 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6166 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6167 | |
| 6168 | /* get a chance to improve log-format-sd error reporting by |
| 6169 | * reporting the correct line-number when possible. |
| 6170 | */ |
| 6171 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6172 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6173 | file, linenum, curproxy->id); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6174 | err_code |= ERR_WARN; |
| 6175 | } |
| 6176 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6177 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6178 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6179 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6181 | goto out; |
| 6182 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6183 | chunk_destroy(&curproxy->log_tag); |
| 6184 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6185 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 6186 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 6187 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 6188 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6189 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6190 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | 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] | 6194 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6195 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6196 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6197 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6198 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6199 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6200 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6201 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6202 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6203 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6204 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6206 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6207 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6208 | |
| 6209 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6210 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6211 | free(curproxy->conn_src.iface_name); |
| 6212 | curproxy->conn_src.iface_name = NULL; |
| 6213 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6214 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6215 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6216 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6217 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6218 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6219 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6220 | goto out; |
| 6221 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6222 | |
| 6223 | proto = protocol_by_family(sk->ss_family); |
| 6224 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6225 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6226 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6228 | goto out; |
| 6229 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6230 | |
| 6231 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6232 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6233 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6235 | goto out; |
| 6236 | } |
| 6237 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6238 | curproxy->conn_src.source_addr = *sk; |
| 6239 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6240 | |
| 6241 | cur_arg = 2; |
| 6242 | while (*(args[cur_arg])) { |
| 6243 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6244 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6245 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6246 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6247 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6249 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6253 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6254 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6255 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6256 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6257 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6258 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6259 | char *name, *end; |
| 6260 | |
| 6261 | name = args[cur_arg+1] + 7; |
| 6262 | while (isspace(*name)) |
| 6263 | name++; |
| 6264 | |
| 6265 | end = name; |
| 6266 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6267 | end++; |
| 6268 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6269 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6270 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6271 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6272 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6273 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6274 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6275 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6276 | |
| 6277 | /* now look for an occurrence number */ |
| 6278 | while (isspace(*end)) |
| 6279 | end++; |
| 6280 | if (*end == ',') { |
| 6281 | end++; |
| 6282 | name = end; |
| 6283 | if (*end == '-') |
| 6284 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6285 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6286 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6287 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6288 | } |
| 6289 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6290 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6291 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6292 | " occurrences values smaller than %d.\n", |
| 6293 | file, linenum, MAX_HDR_HISTORY); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6295 | goto out; |
| 6296 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6297 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6298 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6299 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6300 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6301 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6302 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6303 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6304 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6305 | goto out; |
| 6306 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6307 | |
| 6308 | proto = protocol_by_family(sk->ss_family); |
| 6309 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6310 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6311 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6313 | goto out; |
| 6314 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6315 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6316 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6317 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6318 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6320 | goto out; |
| 6321 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6322 | curproxy->conn_src.tproxy_addr = *sk; |
| 6323 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6324 | } |
| 6325 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6326 | #else /* no TPROXY support */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6327 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 6328 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6330 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6331 | #endif |
| 6332 | cur_arg += 2; |
| 6333 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6334 | } |
| 6335 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6336 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6337 | #ifdef SO_BINDTODEVICE |
| 6338 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6339 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6340 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6341 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6342 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6343 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6344 | free(curproxy->conn_src.iface_name); |
| 6345 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6346 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6347 | global.last_checks |= LSTCHK_NETADM; |
| 6348 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6349 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6350 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6352 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6353 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6354 | cur_arg += 2; |
| 6355 | continue; |
| 6356 | } |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6357 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 6358 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6360 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6361 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6362 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6363 | else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6364 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6365 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6366 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6367 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6368 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6369 | 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] | 6370 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6371 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6372 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6373 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6374 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6375 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6376 | |
| 6377 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6378 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6379 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6380 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6381 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6382 | } |
| 6383 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6384 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6385 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6386 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6387 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6388 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6389 | } |
| 6390 | else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6391 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6392 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6393 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6394 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6395 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6396 | } |
| 6397 | 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] | 6398 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6399 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6400 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6401 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6402 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6403 | } |
| 6404 | 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] | 6405 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6406 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6407 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6408 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6409 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6410 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6411 | 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] | 6412 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6413 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6414 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6415 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6416 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6417 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6418 | 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] | 6419 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6420 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6421 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6423 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6424 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6425 | |
| 6426 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6427 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6428 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6429 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6430 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6431 | } |
| 6432 | 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] | 6433 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6434 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6435 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6436 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6437 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6438 | } |
| 6439 | 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] | 6440 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6441 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6442 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6443 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6444 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6445 | } |
| 6446 | 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] | 6447 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6448 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6449 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6450 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6451 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6452 | } |
| 6453 | 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] | 6454 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6455 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6456 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6457 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6458 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6459 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6460 | 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] | 6461 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6462 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6463 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6464 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6465 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6466 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6467 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6468 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6469 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6470 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6471 | ha_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] | 6472 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6473 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6474 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6475 | 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] | 6476 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6477 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6478 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6479 | ha_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] | 6480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6481 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6482 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6483 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6484 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6485 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6486 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6487 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6489 | goto out; |
| 6490 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6491 | err_code |= warnif_cond_conflicts(cond, |
| 6492 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6493 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6494 | } |
| 6495 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6496 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6497 | file, linenum, args[0], args[2]); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6499 | goto out; |
| 6500 | } |
| 6501 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6502 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6503 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6504 | wl->s = strdup(args[1]); |
| 6505 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6506 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6507 | } |
| 6508 | 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] | 6509 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6510 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6511 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6513 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6514 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6515 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6516 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6517 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6518 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6519 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6520 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6521 | } |
| 6522 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6523 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6524 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6525 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6526 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6527 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6528 | } |
| 6529 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6530 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6531 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6532 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6533 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6534 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6535 | } |
| 6536 | 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] | 6537 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6538 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6539 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6540 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6541 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6542 | } |
| 6543 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6544 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6545 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6546 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6547 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6548 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6549 | } |
| 6550 | 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] | 6551 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6552 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6553 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6554 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6555 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6556 | } |
| 6557 | 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] | 6558 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6559 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6560 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6561 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6562 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6563 | } |
| 6564 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6565 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6566 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6567 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6568 | ha_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] | 6569 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6570 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6571 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6572 | 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] | 6573 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6574 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6575 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6576 | ha_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] | 6577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6578 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6579 | } |
| 6580 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6581 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6582 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args+2, &errmsg)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6583 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6584 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6586 | goto out; |
| 6587 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6588 | err_code |= warnif_cond_conflicts(cond, |
| 6589 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6590 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6591 | } |
| 6592 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6593 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6594 | file, linenum, args[0], args[2]); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6596 | goto out; |
| 6597 | } |
| 6598 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6599 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6600 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6601 | wl->s = strdup(args[1]); |
| 6602 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6603 | } |
| 6604 | else if (!strcmp(args[0], "errorloc") || |
| 6605 | !strcmp(args[0], "errorloc302") || |
| 6606 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6607 | int errnum, errlen; |
| 6608 | char *err; |
| 6609 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6610 | 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] | 6611 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6612 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6613 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6614 | ha_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] | 6615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6616 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | errnum = atol(args[1]); |
| 6620 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6621 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6622 | err = malloc(errlen); |
| 6623 | 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] | 6624 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6625 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6626 | err = malloc(errlen); |
| 6627 | 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] | 6628 | } |
| 6629 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6630 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6631 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6632 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6633 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6634 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6635 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6636 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6637 | |
| 6638 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6639 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6640 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6641 | free(err); |
| 6642 | } |
| 6643 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6644 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6645 | int errnum, errlen, fd; |
| 6646 | char *err; |
| 6647 | struct stat stat; |
| 6648 | |
| 6649 | 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] | 6650 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6651 | |
| 6652 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6653 | ha_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] | 6654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6655 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | fd = open(args[2], O_RDONLY); |
| 6659 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6660 | ha_alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6661 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6662 | if (fd >= 0) |
| 6663 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6665 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6666 | } |
| 6667 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6668 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6669 | errlen = stat.st_size; |
| 6670 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6671 | ha_warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
| 6672 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6673 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6674 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6678 | errnum = read(fd, err, errlen); |
| 6679 | if (errnum != errlen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6680 | ha_alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6681 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6682 | close(fd); |
| 6683 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6685 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6686 | } |
| 6687 | close(fd); |
| 6688 | |
| 6689 | errnum = atol(args[1]); |
| 6690 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6691 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6692 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6693 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6694 | break; |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6699 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6700 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6701 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6702 | free(err); |
| 6703 | } |
| 6704 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6705 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6706 | struct cfg_kw_list *kwl; |
| 6707 | int index; |
| 6708 | |
| 6709 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6710 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6711 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6712 | continue; |
| 6713 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6714 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6715 | 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] | 6716 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6717 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6719 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6720 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6721 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6722 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6723 | err_code |= ERR_WARN; |
| 6724 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6725 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6726 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6727 | } |
| 6728 | } |
| 6729 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6730 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6731 | ha_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] | 6732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6733 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6734 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6735 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6736 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6737 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6738 | } |
| 6739 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6740 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6741 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6742 | { |
| 6743 | #ifdef CONFIG_HAP_NS |
| 6744 | const char *err; |
| 6745 | const char *item = args[0]; |
| 6746 | |
| 6747 | if (!strcmp(item, "namespace_list")) { |
| 6748 | return 0; |
| 6749 | } |
| 6750 | else if (!strcmp(item, "namespace")) { |
| 6751 | size_t idx = 1; |
| 6752 | const char *current; |
| 6753 | while (*(current = args[idx++])) { |
| 6754 | err = invalid_char(current); |
| 6755 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6756 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6757 | file, linenum, *err, item, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6758 | return ERR_ALERT | ERR_FATAL; |
| 6759 | } |
| 6760 | |
| 6761 | if (netns_store_lookup(current, strlen(current))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6762 | ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6763 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6764 | return ERR_ALERT | ERR_FATAL; |
| 6765 | } |
| 6766 | if (!netns_store_insert(current)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6767 | ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6768 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6769 | return ERR_ALERT | ERR_FATAL; |
| 6770 | } |
| 6771 | } |
| 6772 | } |
| 6773 | |
| 6774 | return 0; |
| 6775 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6776 | ha_alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6777 | file, linenum); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6778 | return ERR_ALERT | ERR_FATAL; |
| 6779 | #endif |
| 6780 | } |
| 6781 | |
| 6782 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6783 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6784 | { |
| 6785 | |
| 6786 | int err_code = 0; |
| 6787 | const char *err; |
| 6788 | |
| 6789 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6790 | struct userlist *newul; |
| 6791 | |
| 6792 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6793 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6794 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6795 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6796 | goto out; |
| 6797 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6798 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6799 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6800 | |
| 6801 | err = invalid_char(args[1]); |
| 6802 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6803 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6804 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6806 | goto out; |
| 6807 | } |
| 6808 | |
| 6809 | for (newul = userlist; newul; newul = newul->next) |
| 6810 | if (!strcmp(newul->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6811 | ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6812 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6813 | err_code |= ERR_WARN; |
| 6814 | goto out; |
| 6815 | } |
| 6816 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6817 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6818 | if (!newul) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6819 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6820 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6821 | goto out; |
| 6822 | } |
| 6823 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6824 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6825 | if (!newul->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6826 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6827 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6828 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6829 | goto out; |
| 6830 | } |
| 6831 | |
| 6832 | newul->next = userlist; |
| 6833 | userlist = newul; |
| 6834 | |
| 6835 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6836 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6837 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6838 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6839 | |
| 6840 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6841 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6842 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6844 | goto out; |
| 6845 | } |
| 6846 | |
| 6847 | err = invalid_char(args[1]); |
| 6848 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6849 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6850 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6852 | goto out; |
| 6853 | } |
| 6854 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6855 | if (!userlist) |
| 6856 | goto out; |
| 6857 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6858 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6859 | if (!strcmp(ag->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6860 | ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6861 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6862 | err_code |= ERR_ALERT; |
| 6863 | goto out; |
| 6864 | } |
| 6865 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6866 | ag = calloc(1, sizeof(*ag)); |
| 6867 | if (!ag) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6868 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6869 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6870 | goto out; |
| 6871 | } |
| 6872 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6873 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6874 | if (!ag->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6875 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6876 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6877 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6878 | goto out; |
| 6879 | } |
| 6880 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6881 | cur_arg = 2; |
| 6882 | |
| 6883 | while (*args[cur_arg]) { |
| 6884 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6885 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6886 | cur_arg += 2; |
| 6887 | continue; |
| 6888 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6889 | ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6890 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6891 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6892 | free(ag->groupusers); |
| 6893 | free(ag->name); |
| 6894 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6895 | goto out; |
| 6896 | } |
| 6897 | } |
| 6898 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6899 | ag->next = userlist->groups; |
| 6900 | userlist->groups = ag; |
| 6901 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6902 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6903 | struct auth_users *newuser; |
| 6904 | int cur_arg; |
| 6905 | |
| 6906 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6907 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6908 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6910 | goto out; |
| 6911 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6912 | if (!userlist) |
| 6913 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6914 | |
| 6915 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6916 | if (!strcmp(newuser->user, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6917 | ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6918 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6919 | err_code |= ERR_ALERT; |
| 6920 | goto out; |
| 6921 | } |
| 6922 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6923 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6924 | if (!newuser) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6925 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6926 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6927 | goto out; |
| 6928 | } |
| 6929 | |
| 6930 | newuser->user = strdup(args[1]); |
| 6931 | |
| 6932 | newuser->next = userlist->users; |
| 6933 | userlist->users = newuser; |
| 6934 | |
| 6935 | cur_arg = 2; |
| 6936 | |
| 6937 | while (*args[cur_arg]) { |
| 6938 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6939 | #ifdef CONFIG_HAP_CRYPT |
| 6940 | if (!crypt("", args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6941 | ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6942 | file, linenum, newuser->user); |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6944 | goto out; |
| 6945 | } |
| 6946 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6947 | ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6948 | file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6949 | err_code |= ERR_ALERT; |
| 6950 | #endif |
| 6951 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6952 | cur_arg += 2; |
| 6953 | continue; |
| 6954 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6955 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6956 | newuser->flags |= AU_O_INSECURE; |
| 6957 | cur_arg += 2; |
| 6958 | continue; |
| 6959 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6960 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6961 | cur_arg += 2; |
| 6962 | continue; |
| 6963 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6964 | ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6965 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6967 | goto out; |
| 6968 | } |
| 6969 | } |
| 6970 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6971 | ha_alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6973 | } |
| 6974 | |
| 6975 | out: |
| 6976 | return err_code; |
| 6977 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6978 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6979 | int |
| 6980 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6981 | { |
| 6982 | char *beg, *end, *scope = NULL; |
| 6983 | int err_code = 0; |
| 6984 | const char *err; |
| 6985 | |
| 6986 | beg = line + 1; |
| 6987 | end = strchr(beg, ']'); |
| 6988 | |
| 6989 | /* Detect end of scope declaration */ |
| 6990 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6991 | ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 6992 | file, linenum); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6994 | goto out; |
| 6995 | } |
| 6996 | |
| 6997 | /* Get scope name and check its validity */ |
| 6998 | scope = my_strndup(beg, end-beg); |
| 6999 | err = invalid_char(scope); |
| 7000 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7001 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 7002 | file, linenum, *err); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7003 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7004 | goto out; |
| 7005 | } |
| 7006 | |
| 7007 | /* Be sure to have a scope declaration alone on its line */ |
| 7008 | line = end+1; |
| 7009 | while (isspace((unsigned char)*line)) |
| 7010 | line++; |
| 7011 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7012 | ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 7013 | file, linenum, *line); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7014 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7015 | goto out; |
| 7016 | } |
| 7017 | |
| 7018 | /* We have a valid scope declaration, save it */ |
| 7019 | free(cfg_scope); |
| 7020 | cfg_scope = scope; |
| 7021 | scope = NULL; |
| 7022 | |
| 7023 | out: |
| 7024 | free(scope); |
| 7025 | return err_code; |
| 7026 | } |
| 7027 | |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 7028 | int |
| 7029 | cfg_parse_track_sc_num(unsigned int *track_sc_num, |
| 7030 | const char *arg, const char *end, char **errmsg) |
| 7031 | { |
| 7032 | const char *p; |
| 7033 | unsigned int num; |
| 7034 | |
| 7035 | p = arg; |
| 7036 | num = read_uint64(&arg, end); |
| 7037 | |
| 7038 | if (arg != end) { |
| 7039 | memprintf(errmsg, "Wrong track-sc number '%s'", p); |
| 7040 | return -1; |
| 7041 | } |
| 7042 | |
| 7043 | if (num >= MAX_SESS_STKCTR) { |
| 7044 | memprintf(errmsg, "%u track-sc number exceeding " |
| 7045 | "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1); |
| 7046 | return -1; |
| 7047 | } |
| 7048 | |
| 7049 | *track_sc_num = num; |
| 7050 | return 0; |
| 7051 | } |
| 7052 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7053 | /* |
| 7054 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7055 | * Returns the error code, 0 if OK, or any combination of : |
| 7056 | * - ERR_ABORT: must abort ASAP |
| 7057 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7058 | * - ERR_WARN: a warning has been emitted |
| 7059 | * - ERR_ALERT: an alert has been emitted |
| 7060 | * Only the two first ones can stop processing, the two others are just |
| 7061 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7062 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7063 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7064 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7065 | char *thisline; |
| 7066 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7067 | FILE *f; |
| 7068 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7069 | int err_code = 0; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7070 | struct cfg_section *cs = NULL, *pcs = NULL; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7071 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7072 | int readbytes = 0; |
| 7073 | |
| 7074 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7075 | ha_alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7076 | return -1; |
| 7077 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7078 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7079 | if ((f=fopen(file,"r")) == NULL) { |
| 7080 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7081 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7082 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7083 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7084 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7085 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7086 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7087 | char *end; |
| 7088 | char *args[MAX_LINE_ARGS + 1]; |
| 7089 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7090 | int dquote = 0; /* double quote */ |
| 7091 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7092 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7093 | linenum++; |
| 7094 | |
| 7095 | end = line + strlen(line); |
| 7096 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7097 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7098 | /* Check if we reached the limit and the last char is not \n. |
| 7099 | * Watch out for the last line without the terminating '\n'! |
| 7100 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7101 | char *newline; |
| 7102 | int newlinesize = linesize * 2; |
| 7103 | |
| 7104 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7105 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7106 | ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7107 | file, linenum); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7108 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7109 | continue; |
| 7110 | } |
| 7111 | |
| 7112 | readbytes = linesize - 1; |
| 7113 | linesize = newlinesize; |
| 7114 | thisline = newline; |
| 7115 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7116 | } |
| 7117 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7118 | readbytes = 0; |
| 7119 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7120 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7121 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7122 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7123 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7124 | |
| 7125 | if (*line == '[') {/* This is the begining if a scope */ |
| 7126 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7127 | goto next_line; |
| 7128 | } |
| 7129 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7130 | arg = 0; |
| 7131 | args[arg] = line; |
| 7132 | |
| 7133 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7134 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7135 | if (dquote) |
| 7136 | dquote = 0; |
| 7137 | else |
| 7138 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7139 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7140 | end--; |
| 7141 | } |
| 7142 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7143 | if (squote) |
| 7144 | squote = 0; |
| 7145 | else |
| 7146 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7147 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7148 | end--; |
| 7149 | } |
| 7150 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7151 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7152 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7153 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7154 | int skip = 0; |
| 7155 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7156 | *line = line[1]; |
| 7157 | skip = 1; |
| 7158 | } |
| 7159 | else if (line[1] == 'r') { |
| 7160 | *line = '\r'; |
| 7161 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7162 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7163 | else if (line[1] == 'n') { |
| 7164 | *line = '\n'; |
| 7165 | skip = 1; |
| 7166 | } |
| 7167 | else if (line[1] == 't') { |
| 7168 | *line = '\t'; |
| 7169 | skip = 1; |
| 7170 | } |
| 7171 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7172 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7173 | unsigned char hex1, hex2; |
| 7174 | hex1 = toupper(line[2]) - '0'; |
| 7175 | hex2 = toupper(line[3]) - '0'; |
| 7176 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7177 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7178 | *line = (hex1<<4) + hex2; |
| 7179 | skip = 3; |
| 7180 | } |
| 7181 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7182 | ha_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] | 7183 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7184 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7185 | } else if (line[1] == '"') { |
| 7186 | *line = '"'; |
| 7187 | skip = 1; |
| 7188 | } else if (line[1] == '\'') { |
| 7189 | *line = '\''; |
| 7190 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7191 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7192 | *line = '$'; |
| 7193 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7194 | } |
| 7195 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7196 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7197 | end -= skip; |
| 7198 | } |
| 7199 | line++; |
| 7200 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7201 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7202 | /* end of string, end of loop */ |
| 7203 | *line = 0; |
| 7204 | break; |
| 7205 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7206 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7207 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7208 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7209 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7210 | line++; |
| 7211 | args[++arg] = line; |
| 7212 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7213 | else if (dquote && *line == '$') { |
| 7214 | /* environment variables are evaluated inside double quotes */ |
| 7215 | char *var_beg; |
| 7216 | char *var_end; |
| 7217 | char save_char; |
| 7218 | char *value; |
| 7219 | int val_len; |
| 7220 | int newlinesize; |
| 7221 | int braces = 0; |
| 7222 | |
| 7223 | var_beg = line + 1; |
| 7224 | var_end = var_beg; |
| 7225 | |
| 7226 | if (*var_beg == '{') { |
| 7227 | var_beg++; |
| 7228 | var_end++; |
| 7229 | braces = 1; |
| 7230 | } |
| 7231 | |
| 7232 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7233 | ha_alert("parsing [%s:%d] : Variable expansion: Unrecognized character '%c' in variable name.\n", file, linenum, *var_beg); |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7234 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7235 | goto next_line; /* skip current line */ |
| 7236 | } |
| 7237 | |
| 7238 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7239 | var_end++; |
| 7240 | |
| 7241 | save_char = *var_end; |
| 7242 | *var_end = '\0'; |
| 7243 | value = getenv(var_beg); |
| 7244 | *var_end = save_char; |
| 7245 | val_len = value ? strlen(value) : 0; |
| 7246 | |
| 7247 | if (braces) { |
| 7248 | if (*var_end == '}') { |
| 7249 | var_end++; |
| 7250 | braces = 0; |
| 7251 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7252 | ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7254 | goto next_line; /* skip current line */ |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7259 | |
| 7260 | /* if not enough space in thisline */ |
| 7261 | if (newlinesize > linesize) { |
| 7262 | char *newline; |
| 7263 | |
| 7264 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7265 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7266 | ha_alert("parsing [%s:%d] : Variable expansion: Not enough memory.\n", file, linenum); |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7268 | goto next_line; /* slip current line */ |
| 7269 | } |
| 7270 | /* recompute pointers if realloc returns a new pointer */ |
| 7271 | if (newline != thisline) { |
| 7272 | int i; |
| 7273 | int diff; |
| 7274 | |
| 7275 | for (i = 0; i <= arg; i++) { |
| 7276 | diff = args[i] - thisline; |
| 7277 | args[i] = newline + diff; |
| 7278 | } |
| 7279 | |
| 7280 | diff = var_end - thisline; |
| 7281 | var_end = newline + diff; |
| 7282 | diff = end - thisline; |
| 7283 | end = newline + diff; |
| 7284 | diff = line - thisline; |
| 7285 | line = newline + diff; |
| 7286 | thisline = newline; |
| 7287 | } |
| 7288 | linesize = newlinesize; |
| 7289 | } |
| 7290 | |
| 7291 | /* insert value inside the line */ |
| 7292 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7293 | memcpy(line, value, val_len); |
| 7294 | end += val_len - (var_end - line); |
| 7295 | line += val_len; |
| 7296 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7297 | else { |
| 7298 | line++; |
| 7299 | } |
| 7300 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7301 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7302 | if (dquote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7303 | ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7305 | } |
| 7306 | |
| 7307 | if (squote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7308 | ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7310 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7311 | |
| 7312 | /* empty line */ |
| 7313 | if (!**args) |
| 7314 | continue; |
| 7315 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7316 | if (*line) { |
| 7317 | /* we had to stop due to too many args. |
| 7318 | * Let's terminate the string, print the offending part then cut the |
| 7319 | * last arg. |
| 7320 | */ |
| 7321 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7322 | line++; |
| 7323 | *line = '\0'; |
| 7324 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7325 | ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
| 7326 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7328 | args[arg] = line; |
| 7329 | } |
| 7330 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7331 | /* zero out remaining args and ensure that at least one entry |
| 7332 | * is zeroed out. |
| 7333 | */ |
| 7334 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7335 | args[arg] = line; |
| 7336 | } |
| 7337 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7338 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7339 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7340 | char *tmp; |
| 7341 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7342 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7343 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7344 | for (arg=0; *args[arg+1]; arg++) |
| 7345 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7346 | *tmp = '\0'; // fix the next arg to \0 |
| 7347 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7348 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7349 | else if (!strcmp(args[0], "default")) { |
| 7350 | kwm = KWM_DEF; |
| 7351 | for (arg=0; *args[arg+1]; arg++) |
| 7352 | args[arg] = args[arg+1]; // shift args after inversion |
| 7353 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7354 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7355 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7356 | strcmp(args[0], "log") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7357 | ha_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] | 7358 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7359 | } |
| 7360 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7361 | /* detect section start */ |
| 7362 | list_for_each_entry(ics, §ions, list) { |
| 7363 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7364 | cursection = ics->section_name; |
| 7365 | cs = ics; |
| 7366 | break; |
| 7367 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7368 | } |
| 7369 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7370 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7371 | ha_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] | 7372 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7373 | } else { |
| 7374 | /* else it's a section keyword */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7375 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7376 | if (pcs != cs && pcs && pcs->post_section_parser) { |
| 7377 | err_code |= pcs->post_section_parser(); |
| 7378 | if (err_code & ERR_ABORT) |
| 7379 | goto err; |
| 7380 | } |
| 7381 | |
| 7382 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7383 | if (err_code & ERR_ABORT) |
| 7384 | goto err; |
| 7385 | } |
| 7386 | pcs = cs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7387 | } |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7388 | |
| 7389 | if (pcs == cs && pcs && pcs->post_section_parser) |
| 7390 | err_code |= pcs->post_section_parser(); |
| 7391 | |
| 7392 | err: |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7393 | free(cfg_scope); |
| 7394 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7395 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7396 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7397 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7398 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7399 | } |
| 7400 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7401 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7402 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7403 | * bound to all of its processes. After that, if the target is a "listen" |
| 7404 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7405 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7406 | * checked first to ensure that <to> is already bound to all processes of |
| 7407 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7408 | * path to the destination. |
| 7409 | * |
| 7410 | * It is possible to set <to> to NULL for the first call so that the function |
| 7411 | * takes care of visiting the initial frontend in <from>. |
| 7412 | * |
| 7413 | * It is important to note that the function relies on the fact that all names |
| 7414 | * have already been resolved. |
| 7415 | */ |
| 7416 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7417 | { |
| 7418 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7419 | |
| 7420 | if (to) { |
| 7421 | /* check whether we need to go down */ |
| 7422 | if (from->bind_proc && |
| 7423 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7424 | return; |
| 7425 | |
| 7426 | if (!from->bind_proc && !to->bind_proc) |
| 7427 | return; |
| 7428 | |
| 7429 | to->bind_proc = from->bind_proc ? |
| 7430 | (to->bind_proc | from->bind_proc) : 0; |
| 7431 | |
| 7432 | /* now propagate down */ |
| 7433 | from = to; |
| 7434 | } |
| 7435 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7436 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7437 | return; |
| 7438 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7439 | if (from->state == PR_STSTOPPED) |
| 7440 | return; |
| 7441 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7442 | /* default_backend */ |
| 7443 | if (from->defbe.be) |
| 7444 | propagate_processes(from, from->defbe.be); |
| 7445 | |
| 7446 | /* use_backend */ |
| 7447 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7448 | if (rule->dynamic) |
| 7449 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7450 | to = rule->be.backend; |
| 7451 | propagate_processes(from, to); |
| 7452 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7453 | } |
| 7454 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7455 | /* |
| 7456 | * Returns the error code, 0 if OK, or any combination of : |
| 7457 | * - ERR_ABORT: must abort ASAP |
| 7458 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7459 | * - ERR_WARN: a warning has been emitted |
| 7460 | * - ERR_ALERT: an alert has been emitted |
| 7461 | * Only the two first ones can stop processing, the two others are just |
| 7462 | * indicators. |
| 7463 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7464 | int check_config_validity() |
| 7465 | { |
| 7466 | int cfgerr = 0; |
| 7467 | struct proxy *curproxy = NULL; |
| 7468 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7469 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7470 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7471 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7472 | char *err; |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 7473 | struct cfg_postparser *postparser; |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 7474 | struct dns_resolvers *curr_resolvers = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7475 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7476 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7477 | /* |
| 7478 | * Now, check for the integrity of all that we have collected. |
| 7479 | */ |
| 7480 | |
| 7481 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7482 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7483 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7484 | if (!global.tune.max_http_hdr) |
| 7485 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7486 | |
| 7487 | if (!global.tune.cookie_len) |
| 7488 | global.tune.cookie_len = CAPTURE_LEN; |
| 7489 | |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 7490 | if (!global.tune.requri_len) |
| 7491 | global.tune.requri_len = REQURI_LEN; |
| 7492 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7493 | pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED); |
Emeric Brun | 96fd926 | 2017-07-05 13:33:16 +0200 | [diff] [blame] | 7494 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7495 | pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7496 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7497 | /* Post initialisation of the users and groups lists. */ |
| 7498 | err_code = userlist_postinit(); |
| 7499 | if (err_code != ERR_NONE) |
| 7500 | goto out; |
| 7501 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7502 | /* first, we will invert the proxy list order */ |
| 7503 | curproxy = NULL; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7504 | while (proxies_list) { |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7505 | struct proxy *next; |
| 7506 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7507 | next = proxies_list->next; |
| 7508 | proxies_list->next = curproxy; |
| 7509 | curproxy = proxies_list; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7510 | if (!next) |
| 7511 | break; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7512 | proxies_list = next; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7513 | } |
| 7514 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7515 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7516 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7517 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7518 | struct sticking_rule *mrule; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7519 | struct act_rule *arule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7520 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7521 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7522 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7523 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7524 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7525 | /* proxy ID not set, use automatic numbering with first |
| 7526 | * spare entry starting with next_pxid. |
| 7527 | */ |
| 7528 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7529 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7530 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7531 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7532 | next_pxid++; |
| 7533 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7534 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7535 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7536 | /* ensure we don't keep listeners uselessly bound */ |
| 7537 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7538 | free((void *)curproxy->table.peers.name); |
| 7539 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7540 | continue; |
| 7541 | } |
| 7542 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7543 | /* Check multi-process mode compatibility for the current proxy */ |
| 7544 | |
| 7545 | if (curproxy->bind_proc) { |
| 7546 | /* an explicit bind-process was specified, let's check how many |
| 7547 | * processes remain. |
| 7548 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7549 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7550 | |
| 7551 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7552 | if (!curproxy->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7553 | ha_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); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7554 | curproxy->bind_proc = 1; |
| 7555 | } |
| 7556 | else if (!curproxy->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7557 | ha_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); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7558 | curproxy->bind_proc = 0; |
| 7559 | } |
| 7560 | } |
| 7561 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7562 | /* check and reduce the bind-proc of each listener */ |
| 7563 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7564 | unsigned long mask; |
| 7565 | |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7566 | /* HTTP frontends with "h2" as ALPN/NPN will work in |
| 7567 | * HTTP/2 and absolutely require buffers 16kB or larger. |
| 7568 | */ |
| 7569 | #ifdef USE_OPENSSL |
| 7570 | if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) { |
| 7571 | #ifdef OPENSSL_NPN_NEGOTIATED |
| 7572 | /* check NPN */ |
| 7573 | if (bind_conf->ssl_conf.npn_str && strcmp(bind_conf->ssl_conf.npn_str, "\002h2") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7574 | ha_alert("config : HTTP frontend '%s' enables HTTP/2 via NPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n", |
| 7575 | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7576 | cfgerr++; |
| 7577 | } |
| 7578 | #endif |
| 7579 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 7580 | /* check ALPN */ |
| 7581 | if (bind_conf->ssl_conf.alpn_str && strcmp(bind_conf->ssl_conf.alpn_str, "\002h2") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7582 | ha_alert("config : HTTP frontend '%s' enables HTTP/2 via ALPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n", |
| 7583 | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7584 | cfgerr++; |
| 7585 | } |
| 7586 | #endif |
| 7587 | } /* HTTP && bufsize < 16384 */ |
| 7588 | #endif |
| 7589 | |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7590 | /* detect and address thread affinity inconsistencies */ |
| 7591 | nbproc = 0; |
| 7592 | if (bind_conf->bind_proc) |
| 7593 | nbproc = my_ffsl(bind_conf->bind_proc); |
| 7594 | |
| 7595 | mask = bind_conf->bind_thread[nbproc - 1]; |
Willy Tarreau | 0c026f4 | 2018-08-01 19:12:20 +0200 | [diff] [blame] | 7596 | if (mask && !(mask & all_threads_mask)) { |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7597 | unsigned long new_mask = 0; |
| 7598 | |
| 7599 | while (mask) { |
Willy Tarreau | 0c026f4 | 2018-08-01 19:12:20 +0200 | [diff] [blame] | 7600 | new_mask |= mask & all_threads_mask; |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7601 | mask >>= global.nbthread; |
| 7602 | } |
| 7603 | |
| 7604 | for (nbproc = 0; nbproc < LONGBITS; nbproc++) { |
| 7605 | if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc))) |
| 7606 | bind_conf->bind_thread[nbproc] = new_mask; |
| 7607 | } |
| 7608 | ha_warning("Proxy '%s': the thread range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to thread numbers out of the range defined by the global 'nbthread' directive. The thread numbers were remapped to existing threads instead (mask 0x%lx).\n", |
| 7609 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask); |
| 7610 | } |
| 7611 | |
| 7612 | /* detect process and nbproc affinity inconsistencies */ |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7613 | if (!bind_conf->bind_proc) |
| 7614 | continue; |
| 7615 | |
| 7616 | mask = nbits(global.nbproc); |
| 7617 | if (curproxy->bind_proc) |
| 7618 | mask &= curproxy->bind_proc; |
| 7619 | /* mask cannot be null here thanks to the previous checks */ |
| 7620 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7621 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7622 | bind_conf->bind_proc &= mask; |
| 7623 | |
| 7624 | if (!bind_conf->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7625 | ha_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", |
| 7626 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7627 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7628 | } |
| 7629 | else if (!bind_conf->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7630 | ha_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", |
| 7631 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7632 | bind_conf->bind_proc = 0; |
| 7633 | } |
| 7634 | } |
| 7635 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7636 | switch (curproxy->mode) { |
| 7637 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7638 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7639 | if (!(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7640 | ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7641 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7642 | cfgerr++; |
| 7643 | } |
| 7644 | |
| 7645 | if (curproxy->srv != NULL) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7646 | ha_warning("config : servers will be ignored for %s '%s'.\n", |
| 7647 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7648 | break; |
| 7649 | |
| 7650 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7651 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7652 | break; |
| 7653 | |
| 7654 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7655 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7656 | break; |
| 7657 | } |
| 7658 | |
Willy Tarreau | 58aa5cc | 2018-02-08 09:55:09 +0100 | [diff] [blame] | 7659 | if (curproxy != global.stats_fe && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7660 | ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7661 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7662 | err_code |= ERR_WARN; |
| 7663 | } |
| 7664 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7665 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7666 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7667 | if (curproxy->options & PR_O_TRANSP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7668 | ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7669 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7670 | cfgerr++; |
| 7671 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7672 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7673 | else if (curproxy->srv == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7674 | ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7675 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7676 | cfgerr++; |
| 7677 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7678 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7679 | else if (curproxy->options & PR_O_DISPATCH) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7680 | ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7681 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7682 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7683 | } |
| 7684 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7685 | 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] | 7686 | /* If no LB algo is set in a backend, and we're not in |
| 7687 | * transparent mode, dispatch mode nor proxy mode, we |
| 7688 | * want to use balance roundrobin by default. |
| 7689 | */ |
| 7690 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7691 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7692 | } |
| 7693 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7694 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7695 | if (curproxy->options & PR_O_DISPATCH) |
| 7696 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7697 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7698 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7699 | else if (curproxy->options & PR_O_TRANSP) |
| 7700 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7701 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7702 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7703 | if (curproxy->options & PR_O_DISABLE404) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7704 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7705 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7706 | err_code |= ERR_WARN; |
| 7707 | curproxy->options &= ~PR_O_DISABLE404; |
| 7708 | } |
| 7709 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7710 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7711 | "send-state", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7712 | err_code |= ERR_WARN; |
| 7713 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7714 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7715 | } |
| 7716 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7717 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7718 | if (!global.external_check) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7719 | ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7720 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7721 | cfgerr++; |
| 7722 | } |
| 7723 | if (!curproxy->check_command) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7724 | ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7725 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7726 | cfgerr++; |
| 7727 | } |
| 7728 | } |
| 7729 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7730 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7731 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7732 | ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of " |
| 7733 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7734 | "'email-alert myhostname', or 'email-alert to' " |
| 7735 | "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' " |
| 7736 | "to be present).\n", |
| 7737 | proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7738 | err_code |= ERR_WARN; |
| 7739 | free_email_alert(curproxy); |
| 7740 | } |
| 7741 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7742 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7743 | } |
| 7744 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7745 | if (curproxy->check_command) { |
| 7746 | int clear = 0; |
| 7747 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7748 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7749 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7750 | err_code |= ERR_WARN; |
| 7751 | clear = 1; |
| 7752 | } |
| 7753 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7754 | ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n", |
| 7755 | curproxy->id, "external-check command"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7756 | cfgerr++; |
| 7757 | } |
| 7758 | if (clear) { |
| 7759 | free(curproxy->check_command); |
| 7760 | curproxy->check_command = NULL; |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | if (curproxy->check_path) { |
| 7765 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7766 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7767 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7768 | err_code |= ERR_WARN; |
| 7769 | free(curproxy->check_path); |
| 7770 | curproxy->check_path = NULL; |
| 7771 | } |
| 7772 | } |
| 7773 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7774 | /* if a default backend was specified, let's find it */ |
| 7775 | if (curproxy->defbe.name) { |
| 7776 | struct proxy *target; |
| 7777 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7778 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7779 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7780 | ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7781 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7782 | cfgerr++; |
| 7783 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7784 | ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7785 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7786 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7787 | } else if (target->mode != curproxy->mode && |
| 7788 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7789 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7790 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7791 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7792 | curproxy->conf.file, curproxy->conf.line, |
| 7793 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7794 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7795 | cfgerr++; |
Willy Tarreau | 68ad3a4 | 2018-10-22 11:49:15 +0200 | [diff] [blame] | 7796 | } else if ((curproxy->options2 ^ target->options2) & PR_O2_USE_HTX) { |
| 7797 | ha_alert("%s %s '%s' (%s:%d) tries to use %s %s '%s' (%s:%d) as its default backend, both of which disagree on 'option http-use-htx'.\n", |
| 7798 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7799 | curproxy->conf.file, curproxy->conf.line, |
| 7800 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7801 | target->conf.file, target->conf.line); |
| 7802 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7803 | } else { |
| 7804 | free(curproxy->defbe.name); |
| 7805 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7806 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7807 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7808 | /* Emit a warning if this proxy also has some servers */ |
| 7809 | if (curproxy->srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7810 | ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7811 | curproxy->id); |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7812 | err_code |= ERR_WARN; |
| 7813 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7814 | } |
| 7815 | } |
| 7816 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7817 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7818 | /* Case of listen without default backend |
| 7819 | * The curproxy will be its own default backend |
| 7820 | * so we update tot_fe_maxconn for a further |
| 7821 | * fullconn's computation */ |
| 7822 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7823 | } |
| 7824 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7825 | /* find the target proxy for 'use_backend' rules */ |
| 7826 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7827 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7828 | struct logformat_node *node; |
| 7829 | char *pxname; |
| 7830 | |
| 7831 | /* Try to parse the string as a log format expression. If the result |
| 7832 | * of the parsing is only one entry containing a simple string, then |
| 7833 | * it's a standard string corresponding to a static rule, thus the |
| 7834 | * parsing is cancelled and be.name is restored to be resolved. |
| 7835 | */ |
| 7836 | pxname = rule->be.name; |
| 7837 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7838 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7839 | curproxy->conf.args.file = rule->file; |
| 7840 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7841 | err = NULL; |
| 7842 | if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7843 | ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7844 | rule->file, rule->line, pxname, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7845 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7846 | cfgerr++; |
| 7847 | continue; |
| 7848 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7849 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7850 | |
| 7851 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7852 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7853 | rule->dynamic = 1; |
| 7854 | free(pxname); |
| 7855 | continue; |
| 7856 | } |
| 7857 | /* simple string: free the expression and fall back to static rule */ |
| 7858 | free(node->arg); |
| 7859 | free(node); |
| 7860 | } |
| 7861 | |
| 7862 | rule->dynamic = 0; |
| 7863 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7864 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7865 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7866 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7867 | ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7868 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7869 | cfgerr++; |
| 7870 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7871 | ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7872 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7873 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7874 | } else if (target->mode != curproxy->mode && |
| 7875 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7876 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7877 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7878 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7879 | curproxy->conf.file, curproxy->conf.line, |
| 7880 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7881 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7882 | cfgerr++; |
Willy Tarreau | 68ad3a4 | 2018-10-22 11:49:15 +0200 | [diff] [blame] | 7883 | } else if ((curproxy->options2 ^ target->options2) & PR_O2_USE_HTX) { |
| 7884 | ha_alert("%s %s '%s' (%s:%d) tries to use %s %s '%s' (%s:%d) in a 'use_backend' rule, both of which disagree on 'option http-use-htx'.\n", |
| 7885 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7886 | curproxy->conf.file, curproxy->conf.line, |
| 7887 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7888 | target->conf.file, target->conf.line); |
| 7889 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7890 | } else { |
| 7891 | free((void *)rule->be.name); |
| 7892 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7893 | /* For each target of switching rules, we update |
| 7894 | * their tot_fe_maxconn, except if a previous rule point |
| 7895 | * on the same backend or on the default backend */ |
| 7896 | if (rule->be.backend != curproxy->defbe.be) { |
| 7897 | struct switching_rule *swrule; |
| 7898 | |
| 7899 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7900 | if (rule == swrule) { |
| 7901 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7902 | break; |
| 7903 | } |
| 7904 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7905 | /* there is multiple ref of this backend */ |
| 7906 | break; |
| 7907 | } |
| 7908 | } |
| 7909 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7910 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7911 | } |
| 7912 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7913 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7914 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7915 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7916 | |
| 7917 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7918 | ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7919 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7920 | cfgerr++; |
| 7921 | continue; |
| 7922 | } |
| 7923 | free((void *)srule->srv.name); |
| 7924 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7925 | } |
| 7926 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7927 | /* find the target table for 'stick' rules */ |
| 7928 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7929 | struct proxy *target; |
| 7930 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7931 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7932 | if (mrule->flags & STK_IS_STORE) |
| 7933 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7934 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7935 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7936 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7937 | else |
| 7938 | target = curproxy; |
| 7939 | |
| 7940 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7941 | ha_alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7942 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7943 | cfgerr++; |
| 7944 | } |
| 7945 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7946 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7947 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7948 | cfgerr++; |
| 7949 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7950 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7951 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7952 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7953 | cfgerr++; |
| 7954 | } |
| 7955 | else { |
| 7956 | free((void *)mrule->table.name); |
| 7957 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7958 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7959 | } |
| 7960 | } |
| 7961 | |
| 7962 | /* find the target table for 'store response' rules */ |
| 7963 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7964 | struct proxy *target; |
| 7965 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7966 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7967 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7968 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7969 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7970 | else |
| 7971 | target = curproxy; |
| 7972 | |
| 7973 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7974 | ha_alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7975 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7976 | cfgerr++; |
| 7977 | } |
| 7978 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7979 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7980 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7981 | cfgerr++; |
| 7982 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7983 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7984 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7985 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7986 | cfgerr++; |
| 7987 | } |
| 7988 | else { |
| 7989 | free((void *)mrule->table.name); |
| 7990 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7991 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7992 | } |
| 7993 | } |
| 7994 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7995 | /* check validity for 'tcp-request' layer 4 rules */ |
| 7996 | list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) { |
| 7997 | err = NULL; |
| 7998 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7999 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8000 | free(err); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 8001 | cfgerr++; |
| 8002 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 8003 | } |
| 8004 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8005 | /* check validity for 'tcp-request' layer 5 rules */ |
| 8006 | list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) { |
| 8007 | err = NULL; |
| 8008 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8009 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8010 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8011 | cfgerr++; |
| 8012 | } |
| 8013 | } |
| 8014 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8015 | /* check validity for 'tcp-request' layer 6 rules */ |
| 8016 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8017 | err = NULL; |
| 8018 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8019 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8020 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8021 | cfgerr++; |
| 8022 | } |
| 8023 | } |
| 8024 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8025 | /* check validity for 'http-request' layer 7 rules */ |
| 8026 | list_for_each_entry(arule, &curproxy->http_req_rules, list) { |
| 8027 | err = NULL; |
| 8028 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8029 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8030 | free(err); |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8031 | cfgerr++; |
| 8032 | } |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8033 | } |
| 8034 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8035 | /* check validity for 'http-response' layer 7 rules */ |
| 8036 | list_for_each_entry(arule, &curproxy->http_res_rules, list) { |
| 8037 | err = NULL; |
| 8038 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8039 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8040 | free(err); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8041 | cfgerr++; |
| 8042 | } |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8043 | } |
| 8044 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8045 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8046 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8047 | /* insert block_rules into http_req_rules at the beginning */ |
| 8048 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8049 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8050 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8051 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8052 | LIST_INIT(&curproxy->block_rules); |
| 8053 | } |
| 8054 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8055 | if (curproxy->table.peers.name) { |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8056 | struct peers *curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8057 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8058 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8059 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8060 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8061 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8062 | break; |
| 8063 | } |
| 8064 | } |
| 8065 | |
| 8066 | if (!curpeers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8067 | ha_alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8068 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8069 | free((void *)curproxy->table.peers.name); |
| 8070 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8071 | cfgerr++; |
| 8072 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8073 | else if (curpeers->state == PR_STSTOPPED) { |
| 8074 | /* silently disable this peers section */ |
| 8075 | curproxy->table.peers.p = NULL; |
| 8076 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8077 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8078 | ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8079 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8080 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8081 | cfgerr++; |
| 8082 | } |
| 8083 | } |
| 8084 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8085 | |
| 8086 | if (curproxy->email_alert.mailers.name) { |
| 8087 | struct mailers *curmailers = mailers; |
| 8088 | |
| 8089 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8090 | if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name)) |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8091 | break; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8092 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8093 | if (!curmailers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8094 | ha_alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8095 | curproxy->id, curproxy->email_alert.mailers.name); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8096 | free_email_alert(curproxy); |
| 8097 | cfgerr++; |
| 8098 | } |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8099 | else { |
| 8100 | err = NULL; |
| 8101 | if (init_email_alert(curmailers, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8102 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8103 | free(err); |
| 8104 | cfgerr++; |
| 8105 | } |
| 8106 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8107 | } |
| 8108 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8109 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8110 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8111 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8112 | ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8113 | "proxy", curproxy->id); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8114 | cfgerr++; |
| 8115 | goto out_uri_auth_compat; |
| 8116 | } |
| 8117 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8118 | 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] | 8119 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8120 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8121 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8122 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8123 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8124 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8125 | |
| 8126 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8127 | uri_auth_compat_req[i++] = "realm"; |
| 8128 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8129 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8130 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8131 | uri_auth_compat_req[i++] = "unless"; |
| 8132 | uri_auth_compat_req[i++] = "{"; |
| 8133 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8134 | uri_auth_compat_req[i++] = "}"; |
| 8135 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8136 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8137 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8138 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8139 | cfgerr++; |
| 8140 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8141 | } |
| 8142 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8143 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8144 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8145 | if (curproxy->uri_auth->auth_realm) { |
| 8146 | free(curproxy->uri_auth->auth_realm); |
| 8147 | curproxy->uri_auth->auth_realm = NULL; |
| 8148 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8149 | |
| 8150 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8151 | } |
| 8152 | out_uri_auth_compat: |
| 8153 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8154 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8155 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8156 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8157 | if (!curproxy->conf.logformat_sd_string) { |
| 8158 | /* set the default logformat_sd_string */ |
| 8159 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8160 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8161 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8162 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8163 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8164 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8165 | /* compile the log format */ |
| 8166 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8167 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8168 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8169 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8170 | free(curproxy->conf.logformat_string); |
| 8171 | curproxy->conf.logformat_string = NULL; |
| 8172 | free(curproxy->conf.lfs_file); |
| 8173 | curproxy->conf.lfs_file = NULL; |
| 8174 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8175 | |
| 8176 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8177 | free(curproxy->conf.logformat_sd_string); |
| 8178 | curproxy->conf.logformat_sd_string = NULL; |
| 8179 | free(curproxy->conf.lfsd_file); |
| 8180 | curproxy->conf.lfsd_file = NULL; |
| 8181 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8182 | } |
| 8183 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8184 | if (curproxy->conf.logformat_string) { |
| 8185 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8186 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8187 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8188 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8189 | if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8190 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8191 | ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8192 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8193 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8194 | cfgerr++; |
| 8195 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8196 | curproxy->conf.args.file = NULL; |
| 8197 | curproxy->conf.args.line = 0; |
| 8198 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8199 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8200 | if (curproxy->conf.logformat_sd_string) { |
| 8201 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8202 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8203 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8204 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8205 | if (!parse_logformat_string(curproxy->conf.logformat_sd_string, curproxy, &curproxy->logformat_sd, LOG_OPT_MANDATORY, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8206 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8207 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8208 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8209 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8210 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8211 | } else if (!add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8212 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8213 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8214 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8215 | cfgerr++; |
| 8216 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8217 | curproxy->conf.args.file = NULL; |
| 8218 | curproxy->conf.args.line = 0; |
| 8219 | } |
| 8220 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8221 | if (curproxy->conf.uniqueid_format_string) { |
| 8222 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8223 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8224 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8225 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8226 | if (!parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP, |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8227 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8228 | ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8229 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8230 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8231 | cfgerr++; |
| 8232 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8233 | curproxy->conf.args.file = NULL; |
| 8234 | curproxy->conf.args.line = 0; |
| 8235 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8236 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8237 | /* only now we can check if some args remain unresolved. |
| 8238 | * This must be done after the users and groups resolution. |
| 8239 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8240 | cfgerr += smp_resolve_args(curproxy); |
| 8241 | if (!cfgerr) |
| 8242 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8243 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8244 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8245 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8246 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8247 | (!curproxy->timeout.connect || |
| 8248 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8249 | ha_warning("config : missing timeouts for %s '%s'.\n" |
| 8250 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8251 | " | with such a configuration. To fix this, please ensure that all following\n" |
| 8252 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
| 8253 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8254 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8255 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8256 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8257 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8258 | * We must still support older configurations, so let's find out whether those |
| 8259 | * parameters have been set or must be copied from contimeouts. |
| 8260 | */ |
| 8261 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8262 | if (!curproxy->timeout.tarpit || |
| 8263 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8264 | /* tarpit timeout not set. We search in the following order: |
| 8265 | * default.tarpit, curr.connect, default.connect. |
| 8266 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8267 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8268 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8269 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8270 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8271 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8272 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8273 | } |
| 8274 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8275 | (!curproxy->timeout.queue || |
| 8276 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8277 | /* queue timeout not set. We search in the following order: |
| 8278 | * default.queue, curr.connect, default.connect. |
| 8279 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8280 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8281 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8282 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8283 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8284 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8285 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8286 | } |
| 8287 | } |
| 8288 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8289 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8290 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8291 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8292 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8293 | } |
| 8294 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8295 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8296 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8297 | ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8298 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8299 | err_code |= ERR_WARN; |
| 8300 | } |
| 8301 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8302 | /* ensure that cookie capture length is not too large */ |
| 8303 | if (curproxy->capture_len >= global.tune.cookie_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8304 | ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8305 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8306 | err_code |= ERR_WARN; |
| 8307 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8308 | } |
| 8309 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8310 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8311 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8312 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8313 | curproxy->nb_req_cap * sizeof(char *), |
| 8314 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8315 | } |
| 8316 | |
| 8317 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8318 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8319 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8320 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8321 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8322 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8323 | switch (curproxy->load_server_state_from_file) { |
| 8324 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8325 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8326 | break; |
| 8327 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8328 | if (!global.server_state_file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8329 | ha_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", |
| 8330 | curproxy->id); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8331 | err_code |= ERR_WARN; |
| 8332 | } |
| 8333 | break; |
| 8334 | } |
| 8335 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8336 | /* first, we will invert the servers list order */ |
| 8337 | newsrv = NULL; |
| 8338 | while (curproxy->srv) { |
| 8339 | struct server *next; |
| 8340 | |
| 8341 | next = curproxy->srv->next; |
| 8342 | curproxy->srv->next = newsrv; |
| 8343 | newsrv = curproxy->srv; |
| 8344 | if (!next) |
| 8345 | break; |
| 8346 | curproxy->srv = next; |
| 8347 | } |
| 8348 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8349 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8350 | * We only emit a warning for the first conflict affecting each server, |
| 8351 | * in order to avoid combinatory explosion if all servers have the same |
| 8352 | * name. We do that only for servers which do not have an explicit ID, |
| 8353 | * because these IDs were made also for distinguishing them and we don't |
| 8354 | * want to annoy people who correctly manage them. |
| 8355 | */ |
| 8356 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8357 | struct server *other_srv; |
| 8358 | |
| 8359 | if (newsrv->puid) |
| 8360 | continue; |
| 8361 | |
| 8362 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8363 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8364 | ha_warning("parsing [%s:%d] : %s '%s', another server named '%s' was defined without an explicit ID at line %d, this is not recommended.\n", |
| 8365 | newsrv->conf.file, newsrv->conf.line, |
| 8366 | proxy_type_str(curproxy), curproxy->id, |
| 8367 | newsrv->id, other_srv->conf.line); |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8368 | break; |
| 8369 | } |
| 8370 | } |
| 8371 | } |
| 8372 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8373 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8374 | next_id = 1; |
| 8375 | newsrv = curproxy->srv; |
| 8376 | while (newsrv != NULL) { |
| 8377 | if (!newsrv->puid) { |
| 8378 | /* server ID not set, use automatic numbering with first |
| 8379 | * spare entry starting with next_svid. |
| 8380 | */ |
| 8381 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8382 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8383 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8384 | } |
| 8385 | next_id++; |
| 8386 | newsrv = newsrv->next; |
| 8387 | } |
| 8388 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8389 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8390 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8391 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8392 | /* |
| 8393 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8394 | * tasks to fill the emptied slots when a connection leaves. |
| 8395 | * Also, resolve deferred tracking dependency if needed. |
| 8396 | */ |
| 8397 | newsrv = curproxy->srv; |
| 8398 | while (newsrv != NULL) { |
| 8399 | if (newsrv->minconn > newsrv->maxconn) { |
| 8400 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8401 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8402 | * this will avoid further useless expensive computations. |
| 8403 | */ |
| 8404 | newsrv->maxconn = newsrv->minconn; |
| 8405 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8406 | /* minconn was not specified, so we set it to maxconn */ |
| 8407 | newsrv->minconn = newsrv->maxconn; |
| 8408 | } |
| 8409 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8410 | /* this will also properly set the transport layer for prod and checks */ |
| 8411 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8412 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8413 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8414 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8415 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8416 | /* set the check type on the server */ |
| 8417 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8418 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8419 | if (newsrv->trackit) { |
| 8420 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8421 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8422 | char *pname, *sname; |
| 8423 | |
| 8424 | pname = newsrv->trackit; |
| 8425 | sname = strrchr(pname, '/'); |
| 8426 | |
| 8427 | if (sname) |
| 8428 | *sname++ = '\0'; |
| 8429 | else { |
| 8430 | sname = pname; |
| 8431 | pname = NULL; |
| 8432 | } |
| 8433 | |
| 8434 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8435 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8436 | if (!px) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8437 | ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8438 | proxy_type_str(curproxy), curproxy->id, |
| 8439 | newsrv->id, pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8440 | cfgerr++; |
| 8441 | goto next_srv; |
| 8442 | } |
| 8443 | } else |
| 8444 | px = curproxy; |
| 8445 | |
| 8446 | srv = findserver(px, sname); |
| 8447 | if (!srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8448 | ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8449 | proxy_type_str(curproxy), curproxy->id, |
| 8450 | newsrv->id, sname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8451 | cfgerr++; |
| 8452 | goto next_srv; |
| 8453 | } |
| 8454 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8455 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8456 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8457 | !srv->track && !srv->trackit) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8458 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 8459 | "tracking as it does not have any check nor agent enabled.\n", |
| 8460 | proxy_type_str(curproxy), curproxy->id, |
| 8461 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8462 | cfgerr++; |
| 8463 | goto next_srv; |
| 8464 | } |
| 8465 | |
| 8466 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8467 | |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8468 | if (newsrv == srv || loop) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8469 | ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8470 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8471 | proxy_type_str(curproxy), curproxy->id, |
| 8472 | newsrv->id, px->id, srv->id, px->id, |
| 8473 | newsrv == srv ? srv->id : loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8474 | cfgerr++; |
| 8475 | goto next_srv; |
| 8476 | } |
| 8477 | |
| 8478 | if (curproxy != px && |
| 8479 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8480 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8481 | "tracking: disable-on-404 option inconsistency.\n", |
| 8482 | proxy_type_str(curproxy), curproxy->id, |
| 8483 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8484 | cfgerr++; |
| 8485 | goto next_srv; |
| 8486 | } |
| 8487 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8488 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8489 | newsrv->tracknext = srv->trackers; |
| 8490 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8491 | |
| 8492 | free(newsrv->trackit); |
| 8493 | newsrv->trackit = NULL; |
| 8494 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8495 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8496 | next_srv: |
| 8497 | newsrv = newsrv->next; |
| 8498 | } |
| 8499 | |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 8500 | /* |
| 8501 | * Try to generate dynamic cookies for servers now. |
| 8502 | * It couldn't be done earlier, since at the time we parsed |
| 8503 | * the server line, we may not have known yet that we |
| 8504 | * should use dynamic cookies, or the secret key may not |
| 8505 | * have been provided yet. |
| 8506 | */ |
| 8507 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
| 8508 | newsrv = curproxy->srv; |
| 8509 | while (newsrv != NULL) { |
| 8510 | srv_set_dyncookie(newsrv); |
| 8511 | newsrv = newsrv->next; |
| 8512 | } |
| 8513 | |
| 8514 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8515 | /* We have to initialize the server lookup mechanism depending |
| 8516 | * on what LB algorithm was choosen. |
| 8517 | */ |
| 8518 | |
| 8519 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8520 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8521 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8522 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8523 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8524 | init_server_map(curproxy); |
Willy Tarreau | 760e81d | 2018-05-03 07:20:40 +0200 | [diff] [blame] | 8525 | } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) { |
| 8526 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8527 | chash_init_server_tree(curproxy); |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8528 | } else { |
| 8529 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8530 | fwrr_init_server_groups(curproxy); |
| 8531 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8532 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8533 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8534 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8535 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8536 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8537 | fwlc_init_server_tree(curproxy); |
| 8538 | } else { |
| 8539 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8540 | fas_init_server_tree(curproxy); |
| 8541 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8542 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8543 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8544 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8545 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8546 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8547 | chash_init_server_tree(curproxy); |
| 8548 | } else { |
| 8549 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8550 | init_server_map(curproxy); |
| 8551 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8552 | break; |
| 8553 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 8554 | HA_SPIN_INIT(&curproxy->lbprm.lock); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8555 | |
| 8556 | if (curproxy->options & PR_O_LOGASAP) |
| 8557 | curproxy->to_log &= ~LW_BYTES; |
| 8558 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8559 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8560 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8561 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8562 | ha_warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8563 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8564 | err_code |= ERR_WARN; |
| 8565 | } |
| 8566 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8567 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8568 | int optnum; |
| 8569 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8570 | if (curproxy->uri_auth) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8571 | ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8572 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8573 | err_code |= ERR_WARN; |
| 8574 | curproxy->uri_auth = NULL; |
| 8575 | } |
| 8576 | |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8577 | if (curproxy->capture_name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8578 | ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8579 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8580 | err_code |= ERR_WARN; |
| 8581 | } |
| 8582 | |
| 8583 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8584 | ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8585 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8586 | err_code |= ERR_WARN; |
| 8587 | } |
| 8588 | |
| 8589 | if (!LIST_ISEMPTY(&curproxy->http_res_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8590 | ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8591 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8592 | err_code |= ERR_WARN; |
| 8593 | } |
| 8594 | |
| 8595 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8596 | ha_warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8597 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8598 | err_code |= ERR_WARN; |
| 8599 | } |
| 8600 | |
| 8601 | if (!LIST_ISEMPTY(&curproxy->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8602 | ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8603 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8604 | err_code |= ERR_WARN; |
| 8605 | } |
| 8606 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8607 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8608 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8609 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8610 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8611 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8612 | } |
| 8613 | |
| 8614 | if (curproxy->options & PR_O_ORGTO) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8615 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8616 | "originalto", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8617 | err_code |= ERR_WARN; |
| 8618 | curproxy->options &= ~PR_O_ORGTO; |
| 8619 | } |
| 8620 | |
| 8621 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8622 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8623 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8624 | (curproxy->options & cfg_opts[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8625 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8626 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8627 | err_code |= ERR_WARN; |
| 8628 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8629 | } |
| 8630 | } |
| 8631 | |
| 8632 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8633 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8634 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8635 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8636 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8637 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8638 | err_code |= ERR_WARN; |
| 8639 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8640 | } |
| 8641 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8642 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8643 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8644 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8645 | curproxy->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8646 | ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 8647 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8648 | err_code |= ERR_WARN; |
| 8649 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8650 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8651 | } |
| 8652 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8653 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8654 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8655 | */ |
| 8656 | newsrv = curproxy->srv; |
| 8657 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8658 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8659 | ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8660 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8661 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8662 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8663 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8664 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8665 | ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8666 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8667 | err_code |= ERR_WARN; |
| 8668 | } |
| 8669 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8670 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8671 | ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8672 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8673 | err_code |= ERR_WARN; |
| 8674 | } |
| 8675 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8676 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8677 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8678 | newsrv->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8679 | ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 8680 | 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] | 8681 | err_code |= ERR_WARN; |
| 8682 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8683 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8684 | |
Willy Tarreau | 46deab6 | 2018-04-28 07:18:15 +0200 | [diff] [blame] | 8685 | if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) |
| 8686 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 8687 | |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8688 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8689 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8690 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8691 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8692 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8693 | ha_warning("config : %s '%s' : connections to server '%s' use the client's IP address as the source while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'usesrc' and to use the 'forwardfor' option instead.\n", |
| 8694 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8695 | err_code |= ERR_WARN; |
| 8696 | } |
| 8697 | |
| 8698 | |
| 8699 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8700 | ha_warning("config : %s '%s' : connections to server '%s' will have a PROXY protocol header announcing the first client's IP address while http-reuse is enabled and allows the same connection to be shared between multiple clients. It is strongly advised to disable 'send-proxy' and to use the 'forwardfor' option instead.\n", |
| 8701 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8702 | err_code |= ERR_WARN; |
| 8703 | } |
| 8704 | } |
| 8705 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8706 | newsrv = newsrv->next; |
| 8707 | } |
| 8708 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8709 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8710 | * with no inspect-delay |
| 8711 | */ |
| 8712 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8713 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8714 | if (arule->action == ACT_TCP_CAPTURE && |
| 8715 | !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8716 | break; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8717 | if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) && |
| 8718 | !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8719 | break; |
| 8720 | } |
| 8721 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8722 | if (&arule->list != &curproxy->tcp_req.inspect_rules) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8723 | ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8724 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8725 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8726 | " setting the tcp-request inspect-delay.\n", |
| 8727 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8728 | err_code |= ERR_WARN; |
| 8729 | } |
| 8730 | } |
| 8731 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8732 | /* Check filter configuration, if any */ |
| 8733 | cfgerr += flt_check(curproxy); |
| 8734 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8735 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8736 | if (!curproxy->accept) |
| 8737 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8738 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8739 | if (curproxy->tcp_req.inspect_delay || |
| 8740 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8741 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8742 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8743 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8744 | 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] | 8745 | 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] | 8746 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8747 | |
| 8748 | /* both TCP and HTTP must check switching rules */ |
| 8749 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8750 | |
| 8751 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8752 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8753 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8754 | curproxy->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8755 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8756 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8757 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8758 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8759 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8760 | } |
| 8761 | |
| 8762 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8763 | if (curproxy->tcp_req.inspect_delay || |
| 8764 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8765 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8766 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8767 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8768 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8769 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8770 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8771 | 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] | 8772 | 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] | 8773 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8774 | |
| 8775 | /* If the backend does requires RDP cookie persistence, we have to |
| 8776 | * enable the corresponding analyser. |
| 8777 | */ |
| 8778 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8779 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8780 | |
| 8781 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8782 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8783 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8784 | curproxy->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8785 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8786 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8787 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8788 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8789 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8790 | } |
Christopher Faulet | a717b99 | 2018-04-10 14:43:00 +0200 | [diff] [blame] | 8791 | |
Christopher Faulet | 8ed0a3e | 2018-04-10 14:45:45 +0200 | [diff] [blame] | 8792 | /* Check the mux protocols, if any, for each listener and server |
Christopher Faulet | a717b99 | 2018-04-10 14:43:00 +0200 | [diff] [blame] | 8793 | * attached to the current proxy */ |
| 8794 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8795 | int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); |
| 8796 | |
| 8797 | if (!bind_conf->mux_proto) |
| 8798 | continue; |
| 8799 | if (!(bind_conf->mux_proto->mode & mode)) { |
| 8800 | ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n", |
| 8801 | proxy_type_str(curproxy), curproxy->id, |
| 8802 | (int)bind_conf->mux_proto->token.len, |
| 8803 | bind_conf->mux_proto->token.ptr, |
| 8804 | bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8805 | cfgerr++; |
| 8806 | } |
| 8807 | } |
Christopher Faulet | 8ed0a3e | 2018-04-10 14:45:45 +0200 | [diff] [blame] | 8808 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8809 | int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); |
| 8810 | |
| 8811 | if (!newsrv->mux_proto) |
| 8812 | continue; |
| 8813 | if (!(newsrv->mux_proto->mode & mode)) { |
| 8814 | ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n", |
| 8815 | proxy_type_str(curproxy), curproxy->id, |
| 8816 | (int)newsrv->mux_proto->token.len, |
| 8817 | newsrv->mux_proto->token.ptr, |
| 8818 | newsrv->id, newsrv->conf.file, newsrv->conf.line); |
| 8819 | cfgerr++; |
| 8820 | } |
| 8821 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8822 | } |
| 8823 | |
| 8824 | /***********************************************************/ |
| 8825 | /* At this point, target names have already been resolved. */ |
| 8826 | /***********************************************************/ |
| 8827 | |
| 8828 | /* Check multi-process mode compatibility */ |
| 8829 | |
| 8830 | if (global.nbproc > 1 && global.stats_fe) { |
| 8831 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8832 | unsigned long mask; |
| 8833 | |
| 8834 | mask = nbits(global.nbproc); |
| 8835 | if (global.stats_fe->bind_proc) |
| 8836 | mask &= global.stats_fe->bind_proc; |
| 8837 | |
| 8838 | if (bind_conf->bind_proc) |
| 8839 | mask &= bind_conf->bind_proc; |
| 8840 | |
| 8841 | /* stop here if more than one process is used */ |
Willy Tarreau | 9504dd6 | 2018-10-15 09:37:03 +0200 | [diff] [blame] | 8842 | if (atleast2(mask)) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8843 | break; |
| 8844 | } |
| 8845 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8846 | ha_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"); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8847 | } |
| 8848 | } |
| 8849 | |
| 8850 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8851 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8852 | if (curproxy->bind_proc) |
| 8853 | continue; |
| 8854 | |
| 8855 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8856 | unsigned long mask; |
| 8857 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8858 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8859 | curproxy->bind_proc |= mask; |
| 8860 | } |
| 8861 | |
| 8862 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8863 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | if (global.stats_fe) { |
| 8867 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8868 | unsigned long mask; |
| 8869 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8870 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8871 | global.stats_fe->bind_proc |= mask; |
| 8872 | } |
| 8873 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8874 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8875 | } |
| 8876 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8877 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8878 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8879 | */ |
| 8880 | if (!cfgerr) { |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8881 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8882 | if (curproxy->cap & PR_CAP_FE) |
| 8883 | propagate_processes(curproxy, NULL); |
| 8884 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8885 | } |
| 8886 | |
| 8887 | /* Bind each unbound backend to all processes when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8888 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8889 | if (curproxy->bind_proc) |
| 8890 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8891 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8892 | } |
| 8893 | |
| 8894 | /*******************************************************/ |
| 8895 | /* At this step, all proxies have a non-null bind_proc */ |
| 8896 | /*******************************************************/ |
| 8897 | |
| 8898 | /* perform the final checks before creating tasks */ |
| 8899 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8900 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8901 | struct listener *listener; |
| 8902 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8903 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8904 | /* Configure SSL for each bind line. |
| 8905 | * Note: if configuration fails at some point, the ->ctx member |
| 8906 | * remains NULL so that listeners can later detach. |
| 8907 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8908 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8909 | if (bind_conf->xprt->prepare_bind_conf && |
| 8910 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8911 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8912 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8913 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8914 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8915 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8916 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8917 | int nbproc; |
| 8918 | |
| 8919 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8920 | (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] | 8921 | nbits(global.nbproc)); |
| 8922 | |
| 8923 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8924 | nbproc = 1; |
| 8925 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8926 | if (!listener->luid) { |
| 8927 | /* listener ID not set, use automatic numbering with first |
| 8928 | * spare entry starting with next_luid. |
| 8929 | */ |
| 8930 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8931 | listener->conf.id.key = listener->luid = next_id; |
| 8932 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8933 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8934 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8935 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8936 | /* enable separate counters */ |
| 8937 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8938 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8939 | if (!listener->name) |
| 8940 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8941 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8942 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8943 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8944 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8945 | if (!listener->maxconn) |
| 8946 | listener->maxconn = curproxy->maxconn; |
| 8947 | if (!listener->backlog) |
| 8948 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8949 | if (!listener->maxaccept) |
| 8950 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8951 | |
| 8952 | /* we want to have an optimal behaviour on single process mode to |
| 8953 | * maximize the work at once, but in multi-process we want to keep |
| 8954 | * some fairness between processes, so we target half of the max |
| 8955 | * number of events to be balanced over all the processes the proxy |
| 8956 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8957 | * used to disable the limit. |
| 8958 | */ |
| 8959 | if (listener->maxaccept > 0) { |
| 8960 | if (nbproc > 1) |
| 8961 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8962 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8963 | } |
| 8964 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8965 | listener->accept = session_accept_fd; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8966 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8967 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8968 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8969 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8970 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8971 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8972 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8973 | listener->options |= LI_O_TCP_L5_RULES; |
| 8974 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8975 | if (curproxy->mon_mask.s_addr) |
| 8976 | listener->options |= LI_O_CHK_MONNET; |
| 8977 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8978 | /* smart accept mode is automatic in HTTP mode */ |
| 8979 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8980 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8981 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8982 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8983 | } |
| 8984 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8985 | /* Release unused SSL configs */ |
| 8986 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 8987 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 8988 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8989 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8990 | |
Willy Tarreau | 9504dd6 | 2018-10-15 09:37:03 +0200 | [diff] [blame] | 8991 | if (atleast2(curproxy->bind_proc & nbits(global.nbproc))) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8992 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8993 | int count, maxproc = 0; |
| 8994 | |
| 8995 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8996 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8997 | if (count > maxproc) |
| 8998 | maxproc = count; |
| 8999 | } |
| 9000 | /* backends have 0, frontends have 1 or more */ |
| 9001 | if (maxproc != 1) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9002 | ha_warning("Proxy '%s': in multi-process mode, stats will be" |
| 9003 | " limited to process assigned to the current request.\n", |
| 9004 | curproxy->id); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 9005 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9006 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9007 | ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 9008 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9009 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9010 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9011 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9012 | ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 9013 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9014 | } |
| 9015 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9016 | |
| 9017 | /* create the task associated with the proxy */ |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 9018 | curproxy->task = task_new(MAX_THREADS_MASK); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9019 | if (curproxy->task) { |
| 9020 | curproxy->task->context = curproxy; |
| 9021 | curproxy->task->process = manage_proxy; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9022 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9023 | ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 9024 | curproxy->id); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9025 | cfgerr++; |
| 9026 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 9027 | } |
| 9028 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9029 | /* automatically compute fullconn if not set. We must not do it in the |
| 9030 | * loop above because cross-references are not yet fully resolved. |
| 9031 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9032 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9033 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9034 | * the possible incoming frontend's maxconns. |
| 9035 | */ |
| 9036 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9037 | /* we have the sum of the maxconns in <total>. We only |
| 9038 | * keep 10% of that sum to set the default fullconn, with |
| 9039 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9040 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 9041 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9042 | if (!curproxy->fullconn) |
| 9043 | curproxy->fullconn = 1; |
| 9044 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9045 | } |
| 9046 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9047 | /* |
| 9048 | * Recount currently required checks. |
| 9049 | */ |
| 9050 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9051 | for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) { |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9052 | int optnum; |
| 9053 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9054 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9055 | if (curproxy->options & cfg_opts[optnum].val) |
| 9056 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9057 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9058 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9059 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9060 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9061 | } |
| 9062 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9063 | /* compute the required process bindings for the peers */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9064 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9065 | if (curproxy->table.peers.p) |
| 9066 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9067 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9068 | if (cfg_peers) { |
| 9069 | struct peers *curpeers = cfg_peers, **last; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9070 | struct peer *p, *pb; |
| 9071 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9072 | /* Remove all peers sections which don't have a valid listener, |
| 9073 | * which are not used by any table, or which are bound to more |
| 9074 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9075 | */ |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9076 | last = &cfg_peers; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9077 | while (*last) { |
| 9078 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9079 | |
| 9080 | if (curpeers->state == PR_STSTOPPED) { |
| 9081 | /* the "disabled" keyword was present */ |
| 9082 | if (curpeers->peers_fe) |
| 9083 | stop_proxy(curpeers->peers_fe); |
| 9084 | curpeers->peers_fe = NULL; |
| 9085 | } |
| 9086 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9087 | ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9088 | curpeers->id, localpeer); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9089 | } |
Willy Tarreau | 9504dd6 | 2018-10-15 09:37:03 +0200 | [diff] [blame] | 9090 | else if (atleast2(curpeers->peers_fe->bind_proc)) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9091 | /* either it's totally stopped or too much used */ |
| 9092 | if (curpeers->peers_fe->bind_proc) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9093 | ha_alert("Peers section '%s': peers referenced by sections " |
| 9094 | "running in different processes (%d different ones). " |
| 9095 | "Check global.nbproc and all tables' bind-process " |
| 9096 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9097 | cfgerr++; |
| 9098 | } |
| 9099 | stop_proxy(curpeers->peers_fe); |
| 9100 | curpeers->peers_fe = NULL; |
| 9101 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9102 | else { |
Willy Tarreau | d944344 | 2018-10-15 11:18:03 +0200 | [diff] [blame] | 9103 | if (!peers_init_sync(curpeers)) { |
| 9104 | ha_alert("Peers section '%s': out of memory, giving up on peers.\n", |
| 9105 | curpeers->id); |
| 9106 | cfgerr++; |
| 9107 | break; |
| 9108 | } |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9109 | last = &curpeers->next; |
| 9110 | continue; |
| 9111 | } |
| 9112 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9113 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9114 | p = curpeers->remote; |
| 9115 | while (p) { |
| 9116 | pb = p->next; |
| 9117 | free(p->id); |
| 9118 | free(p); |
| 9119 | p = pb; |
| 9120 | } |
| 9121 | |
| 9122 | /* Destroy and unlink this curpeers section. |
| 9123 | * Note: curpeers is backed up into *last. |
| 9124 | */ |
| 9125 | free(curpeers->id); |
| 9126 | curpeers = curpeers->next; |
| 9127 | free(*last); |
| 9128 | *last = curpeers; |
| 9129 | } |
| 9130 | } |
| 9131 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9132 | /* initialize stick-tables on backend capable proxies. This must not |
| 9133 | * be done earlier because the data size may be discovered while parsing |
| 9134 | * other proxies. |
| 9135 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9136 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9137 | if (curproxy->state == PR_STSTOPPED) |
| 9138 | continue; |
| 9139 | |
| 9140 | if (!stktable_init(&curproxy->table)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9141 | ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9142 | cfgerr++; |
| 9143 | } |
| 9144 | } |
| 9145 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9146 | if (mailers) { |
| 9147 | struct mailers *curmailers = mailers, **last; |
| 9148 | struct mailer *m, *mb; |
| 9149 | |
| 9150 | /* Remove all mailers sections which don't have a valid listener. |
| 9151 | * This can happen when a mailers section is never referenced. |
| 9152 | */ |
| 9153 | last = &mailers; |
| 9154 | while (*last) { |
| 9155 | curmailers = *last; |
| 9156 | if (curmailers->users) { |
| 9157 | last = &curmailers->next; |
| 9158 | continue; |
| 9159 | } |
| 9160 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9161 | ha_warning("Removing incomplete section 'mailers %s'.\n", |
| 9162 | curmailers->id); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9163 | |
| 9164 | m = curmailers->mailer_list; |
| 9165 | while (m) { |
| 9166 | mb = m->next; |
| 9167 | free(m->id); |
| 9168 | free(m); |
| 9169 | m = mb; |
| 9170 | } |
| 9171 | |
| 9172 | /* Destroy and unlink this curmailers section. |
| 9173 | * Note: curmailers is backed up into *last. |
| 9174 | */ |
| 9175 | free(curmailers->id); |
| 9176 | curmailers = curmailers->next; |
| 9177 | free(*last); |
| 9178 | *last = curmailers; |
| 9179 | } |
| 9180 | } |
| 9181 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9182 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9183 | * a server-state file locally defined and none has been provided */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9184 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9185 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9186 | curproxy->server_state_file_name == NULL) |
| 9187 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9188 | } |
| 9189 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 9190 | pool_head_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9191 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9192 | MEM_F_SHARED); |
| 9193 | |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 9194 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 9195 | if (LIST_ISEMPTY(&curr_resolvers->nameservers)) { |
| 9196 | ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n", |
| 9197 | curr_resolvers->id, curr_resolvers->conf.file, |
| 9198 | curr_resolvers->conf.line); |
| 9199 | err_code |= ERR_WARN; |
| 9200 | } |
| 9201 | } |
| 9202 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9203 | list_for_each_entry(postparser, &postparsers, list) { |
| 9204 | if (postparser->func) |
| 9205 | cfgerr += postparser->func(); |
| 9206 | } |
| 9207 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9208 | if (cfgerr > 0) |
| 9209 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9210 | out: |
| 9211 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9212 | } |
| 9213 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9214 | /* |
| 9215 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9216 | * parsing sessions. |
| 9217 | */ |
| 9218 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9219 | { |
| 9220 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9221 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9222 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9223 | /* |
| 9224 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9225 | */ |
| 9226 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9227 | { |
| 9228 | LIST_DEL(&kwl->list); |
| 9229 | LIST_INIT(&kwl->list); |
| 9230 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9231 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9232 | /* this function register new section in the haproxy configuration file. |
| 9233 | * <section_name> is the name of this new section and <section_parser> |
| 9234 | * is the called parser. If two section declaration have the same name, |
| 9235 | * only the first declared is used. |
| 9236 | */ |
| 9237 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9238 | int (*section_parser)(const char *, int, char **, int), |
| 9239 | int (*post_section_parser)()) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9240 | { |
| 9241 | struct cfg_section *cs; |
| 9242 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9243 | list_for_each_entry(cs, §ions, list) { |
| 9244 | if (strcmp(cs->section_name, section_name) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9245 | ha_alert("register section '%s': already registered.\n", section_name); |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9246 | return 0; |
| 9247 | } |
| 9248 | } |
| 9249 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9250 | cs = calloc(1, sizeof(*cs)); |
| 9251 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9252 | ha_alert("register section '%s': out of memory.\n", section_name); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9253 | return 0; |
| 9254 | } |
| 9255 | |
| 9256 | cs->section_name = section_name; |
| 9257 | cs->section_parser = section_parser; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9258 | cs->post_section_parser = post_section_parser; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9259 | |
| 9260 | LIST_ADDQ(§ions, &cs->list); |
| 9261 | |
| 9262 | return 1; |
| 9263 | } |
| 9264 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9265 | /* this function register a new function which will be called once the haproxy |
| 9266 | * configuration file has been parsed. It's useful to check dependencies |
| 9267 | * between sections or to resolve items once everything is parsed. |
| 9268 | */ |
| 9269 | int cfg_register_postparser(char *name, int (*func)()) |
| 9270 | { |
| 9271 | struct cfg_postparser *cp; |
| 9272 | |
| 9273 | cp = calloc(1, sizeof(*cp)); |
| 9274 | if (!cp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9275 | ha_alert("register postparser '%s': out of memory.\n", name); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9276 | return 0; |
| 9277 | } |
| 9278 | cp->name = name; |
| 9279 | cp->func = func; |
| 9280 | |
| 9281 | LIST_ADDQ(&postparsers, &cp->list); |
| 9282 | |
| 9283 | return 1; |
| 9284 | } |
| 9285 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9286 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9287 | * free all config section entries |
| 9288 | */ |
| 9289 | void cfg_unregister_sections(void) |
| 9290 | { |
| 9291 | struct cfg_section *cs, *ics; |
| 9292 | |
| 9293 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9294 | LIST_DEL(&cs->list); |
| 9295 | free(cs); |
| 9296 | } |
| 9297 | } |
| 9298 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9299 | void cfg_backup_sections(struct list *backup_sections) |
| 9300 | { |
| 9301 | struct cfg_section *cs, *ics; |
| 9302 | |
| 9303 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9304 | LIST_DEL(&cs->list); |
| 9305 | LIST_ADDQ(backup_sections, &cs->list); |
| 9306 | } |
| 9307 | } |
| 9308 | |
| 9309 | void cfg_restore_sections(struct list *backup_sections) |
| 9310 | { |
| 9311 | struct cfg_section *cs, *ics; |
| 9312 | |
| 9313 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9314 | LIST_DEL(&cs->list); |
| 9315 | LIST_ADDQ(§ions, &cs->list); |
| 9316 | } |
| 9317 | } |
| 9318 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9319 | __attribute__((constructor)) |
| 9320 | static void cfgparse_init(void) |
| 9321 | { |
| 9322 | /* Register internal sections */ |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9323 | cfg_register_section("listen", cfg_parse_listen, NULL); |
| 9324 | cfg_register_section("frontend", cfg_parse_listen, NULL); |
| 9325 | cfg_register_section("backend", cfg_parse_listen, NULL); |
| 9326 | cfg_register_section("defaults", cfg_parse_listen, NULL); |
| 9327 | cfg_register_section("global", cfg_parse_global, NULL); |
| 9328 | cfg_register_section("userlist", cfg_parse_users, NULL); |
| 9329 | cfg_register_section("peers", cfg_parse_peers, NULL); |
| 9330 | cfg_register_section("mailers", cfg_parse_mailers, NULL); |
| 9331 | cfg_register_section("namespace_list", cfg_parse_netns, NULL); |
| 9332 | cfg_register_section("resolvers", cfg_parse_resolvers, NULL); |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9333 | } |
| 9334 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9335 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9336 | * Local variables: |
| 9337 | * c-indent-level: 8 |
| 9338 | * c-basic-offset: 8 |
| 9339 | * End: |
| 9340 | */ |