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 | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 69 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 70 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 71 | #include <proto/lb_fwlc.h> |
| 72 | #include <proto/lb_fwrr.h> |
| 73 | #include <proto/lb_map.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 74 | #include <proto/listener.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 76 | #include <proto/protocol.h> |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 77 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 78 | #include <proto/proxy.h> |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 79 | #include <proto/peers.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 80 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 81 | #include <proto/session.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 82 | #include <proto/server.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 83 | #include <proto/stream.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 84 | #include <proto/stick_table.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 85 | #include <proto/task.h> |
| 86 | #include <proto/tcp_rules.h> |
Olivier Houchard | 673867c | 2018-05-25 16:58:52 +0200 | [diff] [blame] | 87 | #include <proto/connection.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 88 | |
| 89 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 90 | /* This is the SSLv3 CLIENT HELLO packet used in conjunction with the |
| 91 | * ssl-hello-chk option to ensure that the remote server speaks SSL. |
| 92 | * |
| 93 | * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details. |
| 94 | */ |
| 95 | const char sslv3_client_hello_pkt[] = { |
| 96 | "\x16" /* ContentType : 0x16 = Hanshake */ |
| 97 | "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */ |
| 98 | "\x00\x79" /* ContentLength : 0x79 bytes after this one */ |
| 99 | "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */ |
| 100 | "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */ |
| 101 | "\x03\x00" /* Hello Version : 0x0300 = v3 */ |
| 102 | "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */ |
| 103 | "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */ |
| 104 | "\x00" /* Session ID length : empty (no session ID) */ |
| 105 | "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */ |
| 106 | "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */ |
| 107 | "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */ |
| 108 | "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */ |
| 109 | "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */ |
| 110 | "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */ |
| 111 | "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18" |
| 112 | "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F" |
| 113 | "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33" |
| 114 | "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37" |
| 115 | "\x00\x38" "\x00\x39" "\x00\x3A" |
| 116 | "\x01" /* Compression Length : 0x01 = 1 byte for types */ |
| 117 | "\x00" /* Compression Type : 0x00 = NULL compression */ |
| 118 | }; |
| 119 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 120 | /* various keyword modifiers */ |
| 121 | enum kw_mod { |
| 122 | KWM_STD = 0, /* normal */ |
| 123 | KWM_NO, /* "no" prefixed before the keyword */ |
| 124 | KWM_DEF, /* "default" prefixed before the keyword */ |
| 125 | }; |
| 126 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 127 | /* permit to store configuration section */ |
| 128 | struct cfg_section { |
| 129 | struct list list; |
| 130 | char *section_name; |
| 131 | int (*section_parser)(const char *, int, char **, int); |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 132 | int (*post_section_parser)(); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /* Used to chain configuration sections definitions. This list |
| 136 | * stores struct cfg_section |
| 137 | */ |
| 138 | struct list sections = LIST_HEAD_INIT(sections); |
| 139 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 140 | /* store post configuration parsing */ |
| 141 | |
| 142 | struct cfg_postparser { |
| 143 | struct list list; |
| 144 | char *name; |
| 145 | int (*func)(); |
| 146 | }; |
| 147 | |
| 148 | struct list postparsers = LIST_HEAD_INIT(postparsers); |
| 149 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 150 | /* 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] | 151 | struct cfg_opt { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 152 | const char *name; |
| 153 | unsigned int val; |
| 154 | unsigned int cap; |
Willy Tarreau | 4fee4e9 | 2007-01-06 21:09:17 +0100 | [diff] [blame] | 155 | unsigned int checks; |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 156 | unsigned int mode; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | /* proxy->options */ |
| 160 | static const struct cfg_opt cfg_opts[] = |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 161 | { |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 162 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 163 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 164 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 165 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 166 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 167 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 168 | { "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] | 169 | { "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] | 170 | { "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] | 171 | { "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] | 172 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 173 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 174 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 175 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 176 | #ifdef TPROXY |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 177 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 178 | #else |
| 179 | { "transparent", 0, 0, 0, 0 }, |
Willy Tarreau | 8f922fc | 2007-01-06 21:11:49 +0100 | [diff] [blame] | 180 | #endif |
| 181 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 182 | { NULL, 0, 0, 0, 0 } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 183 | }; |
| 184 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 185 | /* proxy->options2 */ |
| 186 | static const struct cfg_opt cfg_opts2[] = |
| 187 | { |
| 188 | #ifdef CONFIG_HAP_LINUX_SPLICE |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 189 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 190 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 191 | { "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] | 192 | #else |
| 193 | { "splice-request", 0, 0, 0, 0 }, |
| 194 | { "splice-response", 0, 0, 0, 0 }, |
| 195 | { "splice-auto", 0, 0, 0, 0 }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 196 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 197 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 198 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 199 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 200 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 201 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 202 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 203 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 204 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
| 205 | { "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] | 206 | { "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] | 207 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | e52564c | 2010-04-27 22:19:14 +0200 | [diff] [blame] | 208 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 209 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 210 | { NULL, 0, 0, 0 } |
| 211 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 212 | |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 213 | static char *cursection = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 214 | static struct proxy defproxy; /* fake proxy used to assign default values on all instances */ |
| 215 | int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */ |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 216 | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 217 | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 218 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 219 | /* List head of all known configuration keywords */ |
| 220 | static struct cfg_kw_list cfg_keywords = { |
| 221 | .list = LIST_HEAD_INIT(cfg_keywords.list) |
| 222 | }; |
| 223 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 224 | /* |
| 225 | * converts <str> to a list of listeners which are dynamically allocated. |
| 226 | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
| 227 | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
| 228 | * - <port> is a numerical port from 1 to 65535 ; |
| 229 | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
| 230 | * 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] | 231 | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
| 232 | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
| 233 | * will be replaced with an error message. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 234 | */ |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 235 | 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] | 236 | { |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 237 | char *next, *dupstr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | int port, end; |
| 239 | |
| 240 | next = dupstr = strdup(str); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 241 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 242 | while (next && *next) { |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 243 | int inherited = 0; |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 244 | struct sockaddr_storage *ss2; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 245 | int fd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 246 | |
| 247 | str = next; |
| 248 | /* 1) look for the end of the first address */ |
Krzysztof Piotr Oledzki | 52d522b | 2009-01-27 16:57:08 +0100 | [diff] [blame] | 249 | if ((next = strchr(str, ',')) != NULL) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 250 | *next++ = 0; |
| 251 | } |
| 252 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 253 | ss2 = str2sa_range(str, NULL, &port, &end, err, |
Willy Tarreau | 72b8c1f | 2015-09-08 15:50:19 +0200 | [diff] [blame] | 254 | curproxy == global.stats_fe ? NULL : global.unix_bind.prefix, |
Thierry FOURNIER | 7fe3be7 | 2015-09-26 20:03:36 +0200 | [diff] [blame] | 255 | NULL, 1); |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 256 | if (!ss2) |
| 257 | goto fail; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 258 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 259 | if (ss2->ss_family == AF_INET || ss2->ss_family == AF_INET6) { |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 260 | if (!port && !end) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 261 | memprintf(err, "missing port number: '%s'\n", str); |
Willy Tarreau | 2dff0c2 | 2011-03-04 15:43:13 +0100 | [diff] [blame] | 262 | goto fail; |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 263 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 264 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 265 | if (!port || !end) { |
| 266 | memprintf(err, "port offsets are not allowed in 'bind': '%s'\n", str); |
| 267 | goto fail; |
| 268 | } |
| 269 | |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 270 | if (port < 1 || port > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 271 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", port, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 272 | goto fail; |
| 273 | } |
| 274 | |
| 275 | if (end < 1 || end > 65535) { |
Willy Tarreau | 4fbb228 | 2012-09-20 20:01:39 +0200 | [diff] [blame] | 276 | memprintf(err, "invalid port '%d' specified for address '%s'.\n", end, str); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 277 | goto fail; |
| 278 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 279 | } |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 280 | else if (ss2->ss_family == AF_UNSPEC) { |
| 281 | socklen_t addr_len; |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 282 | inherited = 1; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 283 | |
| 284 | /* We want to attach to an already bound fd whose number |
| 285 | * is in the addr part of ss2 when cast to sockaddr_in. |
| 286 | * Note that by definition there is a single listener. |
| 287 | * We still have to determine the address family to |
| 288 | * register the correct protocol. |
| 289 | */ |
| 290 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 291 | addr_len = sizeof(*ss2); |
| 292 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 293 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 294 | goto fail; |
| 295 | } |
| 296 | |
| 297 | port = end = get_host_port(ss2); |
William Lallemand | 2fe7dd0 | 2018-09-11 16:51:29 +0200 | [diff] [blame] | 298 | |
| 299 | } else if (ss2->ss_family == AF_CUST_SOCKPAIR) { |
| 300 | socklen_t addr_len; |
| 301 | inherited = 1; |
| 302 | |
| 303 | fd = ((struct sockaddr_in *)ss2)->sin_addr.s_addr; |
| 304 | addr_len = sizeof(*ss2); |
| 305 | if (getsockname(fd, (struct sockaddr *)ss2, &addr_len) == -1) { |
| 306 | memprintf(err, "cannot use file descriptor '%d' : %s.\n", fd, strerror(errno)); |
| 307 | goto fail; |
| 308 | } |
| 309 | |
| 310 | ss2->ss_family = AF_CUST_SOCKPAIR; /* reassign AF_CUST_SOCKPAIR because of getsockname */ |
| 311 | port = end = 0; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 312 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 313 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 314 | /* OK the address looks correct */ |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 315 | if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) { |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 316 | memprintf(err, "%s for address '%s'.\n", *err, str); |
| 317 | goto fail; |
| 318 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 319 | } /* end while(next) */ |
| 320 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 321 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 322 | fail: |
| 323 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 324 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 325 | } |
| 326 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 327 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 328 | * Report an error in <msg> when there are too many arguments. This version is |
| 329 | * intended to be used by keyword parsers so that the message will be included |
| 330 | * into the general error message. The index is the current keyword in args. |
| 331 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 332 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 333 | * message may also be null, it will simply not be produced (useful to check only). |
| 334 | * <msg> and <err_code> are only affected on error. |
| 335 | */ |
| 336 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 337 | { |
| 338 | int i; |
| 339 | |
| 340 | if (!*args[index + maxarg + 1]) |
| 341 | return 0; |
| 342 | |
| 343 | if (msg) { |
| 344 | *msg = NULL; |
| 345 | memprintf(msg, "%s", args[0]); |
| 346 | for (i = 1; i <= index; i++) |
| 347 | memprintf(msg, "%s %s", *msg, args[i]); |
| 348 | |
| 349 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 350 | } |
| 351 | if (err_code) |
| 352 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 353 | |
| 354 | return 1; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * same as too_many_args_idx with a 0 index |
| 359 | */ |
| 360 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 361 | { |
| 362 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 363 | } |
| 364 | |
| 365 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 366 | * Report a fatal Alert when there is too much arguments |
| 367 | * The index is the current keyword in args |
| 368 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 369 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 370 | */ |
| 371 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 372 | { |
| 373 | char *kw = NULL; |
| 374 | int i; |
| 375 | |
| 376 | if (!*args[index + maxarg + 1]) |
| 377 | return 0; |
| 378 | |
| 379 | memprintf(&kw, "%s", args[0]); |
| 380 | for (i = 1; i <= index; i++) { |
| 381 | memprintf(&kw, "%s %s", kw, args[i]); |
| 382 | } |
| 383 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 384 | 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] | 385 | free(kw); |
| 386 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 387 | return 1; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * same as alertif_too_many_args_idx with a 0 index |
| 392 | */ |
| 393 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 394 | { |
| 395 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 396 | } |
| 397 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 398 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 399 | * Return 1 if the warning has been emitted, otherwise 0. |
| 400 | */ |
| 401 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 402 | { |
| 403 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 404 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 405 | file, line, arg); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 406 | return 1; |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 411 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 412 | * Return 1 if the warning has been emitted, otherwise 0. |
| 413 | */ |
| 414 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 415 | { |
| 416 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 417 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 418 | file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 419 | return 1; |
| 420 | } |
| 421 | return 0; |
| 422 | } |
| 423 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 424 | /* Report a warning if a rule is placed after a 'monitor fail' rule. |
| 425 | * Return 1 if the warning has been emitted, otherwise 0. |
| 426 | */ |
| 427 | int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
| 428 | { |
| 429 | if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { |
| 430 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", |
| 431 | file, line, arg); |
| 432 | return 1; |
| 433 | } |
| 434 | return 0; |
| 435 | } |
| 436 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 437 | /* Report a warning if a rule is placed after a 'block' rule. |
| 438 | * Return 1 if the warning has been emitted, otherwise 0. |
| 439 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 440 | 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] | 441 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 442 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 443 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 444 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 445 | return 1; |
| 446 | } |
| 447 | return 0; |
| 448 | } |
| 449 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 450 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 451 | * Return 1 if the warning has been emitted, otherwise 0. |
| 452 | */ |
| 453 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 454 | { |
| 455 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 456 | ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 457 | file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 458 | return 1; |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 463 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 464 | * Return 1 if the warning has been emitted, otherwise 0. |
| 465 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 466 | 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] | 467 | { |
| 468 | if (proxy->req_exp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 469 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 470 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 471 | return 1; |
| 472 | } |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | /* Report a warning if a rule is placed after a reqadd rule. |
| 477 | * Return 1 if the warning has been emitted, otherwise 0. |
| 478 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 479 | 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] | 480 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 481 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 482 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 483 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 484 | return 1; |
| 485 | } |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | /* Report a warning if a rule is placed after a redirect rule. |
| 490 | * Return 1 if the warning has been emitted, otherwise 0. |
| 491 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 492 | 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] | 493 | { |
| 494 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 495 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 496 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 497 | return 1; |
| 498 | } |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 503 | * Return 1 if the warning has been emitted, otherwise 0. |
| 504 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 505 | 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] | 506 | { |
| 507 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 508 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 509 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 510 | return 1; |
| 511 | } |
| 512 | return 0; |
| 513 | } |
| 514 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 515 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 516 | * Return 1 if the warning has been emitted, otherwise 0. |
| 517 | */ |
| 518 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 519 | { |
| 520 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 521 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 522 | file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 523 | return 1; |
| 524 | } |
| 525 | return 0; |
| 526 | } |
| 527 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 528 | /* report a warning if a redirect rule is dangerously placed */ |
| 529 | 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] | 530 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 531 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 532 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 533 | } |
| 534 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 535 | /* report a warning if a reqadd rule is dangerously placed */ |
| 536 | 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] | 537 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 538 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 539 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 540 | } |
| 541 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 542 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 543 | 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] | 544 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 545 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 546 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /* report a warning if an http-request rule is dangerously placed */ |
| 550 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 551 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 552 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 553 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 556 | /* report a warning if a block rule is dangerously placed */ |
| 557 | 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] | 558 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 559 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 560 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 563 | /* report a warning if a block rule is dangerously placed */ |
| 564 | 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] | 565 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 566 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 567 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 570 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 571 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 572 | { |
| 573 | return warnif_rule_after_monitor(proxy, file, line, arg) || |
| 574 | warnif_misplaced_monitor(proxy, file, line, arg); |
| 575 | } |
| 576 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 577 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 578 | 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] | 579 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 580 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 581 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 582 | } |
| 583 | |
| 584 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 585 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 586 | { |
| 587 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 588 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 589 | } |
| 590 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 591 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 592 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 593 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 594 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 595 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 596 | 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] | 597 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 598 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 599 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 600 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 601 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 602 | return 0; |
| 603 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 604 | acl = acl_cond_conflicts(cond, where); |
| 605 | if (acl) { |
| 606 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 607 | ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 608 | file, line, acl->name, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 609 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 610 | ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
| 611 | 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] | 612 | return ERR_WARN; |
| 613 | } |
| 614 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 615 | return 0; |
| 616 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 617 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 618 | ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
| 619 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 620 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 621 | ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
| 622 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 623 | return ERR_WARN; |
| 624 | } |
| 625 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 626 | /* 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] | 627 | * 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] | 628 | * two such numbers delimited by a dash ('-'). On success, it returns |
| 629 | * 0. otherwise it returns 1 with an error message in <err>. |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 630 | * |
| 631 | * Note: this function can also be used to parse a thread number or a set of |
| 632 | * threads. |
| 633 | */ |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 634 | 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] | 635 | { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 636 | if (autoinc) { |
| 637 | *autoinc = 0; |
| 638 | if (strncmp(arg, "auto:", 5) == 0) { |
| 639 | arg += 5; |
| 640 | *autoinc = 1; |
| 641 | } |
| 642 | } |
| 643 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 644 | if (strcmp(arg, "all") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 645 | *proc |= ~0UL; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 646 | else if (strcmp(arg, "odd") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 647 | *proc |= ~0UL/3UL; /* 0x555....555 */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 648 | else if (strcmp(arg, "even") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 649 | *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 650 | else { |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 651 | char *dash; |
| 652 | unsigned int low, high; |
| 653 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 654 | if (!isdigit((int)*arg)) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 655 | memprintf(err, "'%s' is not a valid number.\n", arg); |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 656 | return -1; |
| 657 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 658 | |
| 659 | low = high = str2uic(arg); |
| 660 | if ((dash = strchr(arg, '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 661 | high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1)); |
| 662 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 663 | if (high < low) { |
| 664 | unsigned int swap = low; |
| 665 | low = high; |
| 666 | high = swap; |
| 667 | } |
| 668 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 669 | if (low < 1 || low > LONGBITS || high > LONGBITS) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 670 | memprintf(err, "'%s' is not a valid number/range." |
| 671 | " It supports numbers from 1 to %d.\n", |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 672 | arg, LONGBITS); |
| 673 | return 1; |
| 674 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 675 | |
| 676 | for (;low <= high; low++) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 677 | *proc |= 1UL << (low-1); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 678 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 679 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 680 | return 0; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 681 | } |
| 682 | |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 683 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 684 | /* Parse cpu sets. Each CPU set is either a unique number between 0 and |
| 685 | * <LONGBITS> or a range with two such numbers delimited by a dash |
| 686 | * ('-'). Multiple CPU numbers or ranges may be specified. On success, it |
| 687 | * returns 0. otherwise it returns 1 with an error message in <err>. |
| 688 | */ |
| 689 | static unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err) |
| 690 | { |
| 691 | int cur_arg = 0; |
| 692 | |
| 693 | *cpu_set = 0; |
| 694 | while (*args[cur_arg]) { |
| 695 | char *dash; |
| 696 | unsigned int low, high; |
| 697 | |
| 698 | if (!isdigit((int)*args[cur_arg])) { |
| 699 | memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]); |
| 700 | return -1; |
| 701 | } |
| 702 | |
| 703 | low = high = str2uic(args[cur_arg]); |
| 704 | if ((dash = strchr(args[cur_arg], '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 705 | high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1)); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 706 | |
| 707 | if (high < low) { |
| 708 | unsigned int swap = low; |
| 709 | low = high; |
| 710 | high = swap; |
| 711 | } |
| 712 | |
| 713 | if (high >= LONGBITS) { |
| 714 | memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1); |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | while (low <= high) |
| 719 | *cpu_set |= 1UL << low++; |
| 720 | |
| 721 | cur_arg++; |
| 722 | } |
| 723 | return 0; |
| 724 | } |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 725 | #endif |
| 726 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 727 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 728 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 729 | * any combination of : |
| 730 | * - ERR_ABORT: must abort ASAP |
| 731 | * - ERR_FATAL: we can continue parsing but not start the service |
| 732 | * - ERR_WARN: a warning has been emitted |
| 733 | * - ERR_ALERT: an alert has been emitted |
| 734 | * Only the two first ones can stop processing, the two others are just |
| 735 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 736 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 737 | 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] | 738 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 739 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 740 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 741 | |
| 742 | if (!strcmp(args[0], "global")) { /* new section */ |
| 743 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 744 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 745 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 746 | } |
| 747 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 748 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 749 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 750 | global.mode |= MODE_DAEMON; |
| 751 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 752 | else if (!strcmp(args[0], "master-worker")) { |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 753 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 754 | goto out; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 755 | if (*args[1]) { |
William Lallemand | 4cfede8 | 2017-11-24 22:02:34 +0100 | [diff] [blame] | 756 | if (!strcmp(args[1], "no-exit-on-failure")) { |
| 757 | global.tune.options |= GTUNE_NOEXIT_ONFAILURE; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 758 | } else { |
Tim Duesterhus | c578d9a | 2017-12-05 18:14:12 +0100 | [diff] [blame] | 759 | 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] | 760 | err_code |= ERR_ALERT | ERR_FATAL; |
| 761 | goto out; |
| 762 | } |
| 763 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 764 | global.mode |= MODE_MWORKER; |
| 765 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 766 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 767 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 768 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 769 | global.mode |= MODE_DEBUG; |
| 770 | } |
| 771 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 772 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 773 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 774 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 775 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 776 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 777 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 778 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 779 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 780 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 781 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 782 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 783 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 784 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 785 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 786 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 787 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 788 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 789 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 790 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 791 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 792 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 793 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 794 | global.tune.options &= ~GTUNE_USE_GAI; |
| 795 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 796 | else if (!strcmp(args[0], "noreuseport")) { |
| 797 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 798 | goto out; |
| 799 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 800 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 801 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 802 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 803 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 804 | global.mode |= MODE_QUIET; |
| 805 | } |
Olivier Houchard | 1599b80 | 2018-05-24 18:59:04 +0200 | [diff] [blame] | 806 | else if (!strcmp(args[0], "tune.runqueue-depth")) { |
| 807 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 808 | goto out; |
| 809 | if (global.tune.runqueue_depth != 0) { |
| 810 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 811 | err_code |= ERR_ALERT; |
| 812 | goto out; |
| 813 | } |
| 814 | if (*(args[1]) == 0) { |
| 815 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 817 | goto out; |
| 818 | } |
| 819 | global.tune.runqueue_depth = atol(args[1]); |
| 820 | |
| 821 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 822 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 823 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 824 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 825 | if (global.tune.maxpollevents != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 826 | 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] | 827 | err_code |= ERR_ALERT; |
| 828 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 829 | } |
| 830 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 831 | 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] | 832 | err_code |= ERR_ALERT | ERR_FATAL; |
| 833 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 834 | } |
| 835 | global.tune.maxpollevents = atol(args[1]); |
| 836 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 837 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 838 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 839 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 840 | if (global.tune.maxaccept != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 841 | 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] | 842 | err_code |= ERR_ALERT; |
| 843 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 844 | } |
| 845 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 846 | 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] | 847 | err_code |= ERR_ALERT | ERR_FATAL; |
| 848 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 849 | } |
| 850 | global.tune.maxaccept = atol(args[1]); |
| 851 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 852 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 853 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 854 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 855 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 856 | 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] | 857 | err_code |= ERR_ALERT | ERR_FATAL; |
| 858 | goto out; |
| 859 | } |
| 860 | global.tune.chksize = atol(args[1]); |
| 861 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 862 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 863 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 864 | goto out; |
| 865 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 866 | 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] | 867 | err_code |= ERR_ALERT | ERR_FATAL; |
| 868 | goto out; |
| 869 | } |
| 870 | global.tune.recv_enough = atol(args[1]); |
| 871 | } |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 872 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 873 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 874 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 875 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 876 | 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] | 877 | err_code |= ERR_ALERT | ERR_FATAL; |
| 878 | goto out; |
| 879 | } |
| 880 | global.tune.buf_limit = atol(args[1]); |
| 881 | if (global.tune.buf_limit) { |
| 882 | if (global.tune.buf_limit < 3) |
| 883 | global.tune.buf_limit = 3; |
| 884 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 885 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 886 | } |
| 887 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 888 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 889 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 890 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 891 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 892 | 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] | 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
| 896 | global.tune.reserved_bufs = atol(args[1]); |
| 897 | if (global.tune.reserved_bufs < 2) |
| 898 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 899 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 900 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 901 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 902 | else if (!strcmp(args[0], "tune.bufsize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 903 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 904 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 905 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 906 | 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] | 907 | err_code |= ERR_ALERT | ERR_FATAL; |
| 908 | goto out; |
| 909 | } |
| 910 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 911 | if (global.tune.bufsize <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 912 | 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] | 913 | err_code |= ERR_ALERT | ERR_FATAL; |
| 914 | goto out; |
| 915 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 916 | } |
| 917 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 918 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 919 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 920 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 921 | 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] | 922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 923 | goto out; |
| 924 | } |
| 925 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 926 | if (global.tune.maxrewrite < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 927 | 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] | 928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 929 | goto out; |
| 930 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 931 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 932 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 933 | unsigned int idle; |
| 934 | const char *res; |
| 935 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 936 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 937 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 938 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 939 | 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] | 940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 941 | goto out; |
| 942 | } |
| 943 | |
| 944 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 945 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 946 | 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] | 947 | file, linenum, *res, args[0]); |
| 948 | err_code |= ERR_ALERT | ERR_FATAL; |
| 949 | goto out; |
| 950 | } |
| 951 | |
| 952 | if (idle > 65535) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 953 | 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] | 954 | err_code |= ERR_ALERT | ERR_FATAL; |
| 955 | goto out; |
| 956 | } |
| 957 | global.tune.idle_timer = idle; |
| 958 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 959 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 960 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 961 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 962 | if (global.tune.client_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 963 | 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] | 964 | err_code |= ERR_ALERT; |
| 965 | goto out; |
| 966 | } |
| 967 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 968 | 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] | 969 | err_code |= ERR_ALERT | ERR_FATAL; |
| 970 | goto out; |
| 971 | } |
| 972 | global.tune.client_rcvbuf = atol(args[1]); |
| 973 | } |
| 974 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 975 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 976 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 977 | if (global.tune.server_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 978 | 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] | 979 | err_code |= ERR_ALERT; |
| 980 | goto out; |
| 981 | } |
| 982 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 983 | 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] | 984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 985 | goto out; |
| 986 | } |
| 987 | global.tune.server_rcvbuf = atol(args[1]); |
| 988 | } |
| 989 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 990 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 991 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 992 | if (global.tune.client_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 993 | 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] | 994 | err_code |= ERR_ALERT; |
| 995 | goto out; |
| 996 | } |
| 997 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 998 | 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] | 999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | global.tune.client_sndbuf = atol(args[1]); |
| 1003 | } |
| 1004 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1005 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1006 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 1007 | if (global.tune.server_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1008 | 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] | 1009 | err_code |= ERR_ALERT; |
| 1010 | goto out; |
| 1011 | } |
| 1012 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1013 | 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] | 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1015 | goto out; |
| 1016 | } |
| 1017 | global.tune.server_sndbuf = atol(args[1]); |
| 1018 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1019 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1020 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1021 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1022 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1023 | 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] | 1024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | global.tune.pipesize = atol(args[1]); |
| 1028 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1029 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1030 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1031 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1032 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1033 | 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] | 1034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1035 | goto out; |
| 1036 | } |
| 1037 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1038 | } |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 1039 | else if (!strcmp(args[0], "tune.http.logurilen")) { |
| 1040 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1041 | goto out; |
| 1042 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1043 | 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] | 1044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1045 | goto out; |
| 1046 | } |
| 1047 | global.tune.requri_len = atol(args[1]) + 1; |
| 1048 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1049 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1050 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1051 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1052 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1053 | 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] | 1054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1055 | goto out; |
| 1056 | } |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1057 | global.tune.max_http_hdr = atoi(args[1]); |
| 1058 | 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] | 1059 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 1060 | file, linenum, args[0]); |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1062 | goto out; |
| 1063 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1064 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1065 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1066 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1067 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1068 | if (*args[1]) { |
| 1069 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1070 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1071 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1072 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1073 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1077 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1078 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1079 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1080 | goto out; |
| 1081 | } |
| 1082 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1083 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1084 | if (*args[1]) { |
| 1085 | global.tune.pattern_cache = atoi(args[1]); |
| 1086 | if (global.tune.pattern_cache < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1087 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1088 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1089 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1090 | goto out; |
| 1091 | } |
| 1092 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1093 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1094 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
| 1097 | } |
| 1098 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1099 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1100 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1101 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1102 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1103 | 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] | 1104 | err_code |= ERR_ALERT; |
| 1105 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1106 | } |
| 1107 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1108 | 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] | 1109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1110 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1111 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1112 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1113 | 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] | 1114 | err_code |= ERR_WARN; |
| 1115 | goto out; |
| 1116 | } |
| 1117 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1118 | } |
| 1119 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1120 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1121 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1122 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1123 | 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] | 1124 | err_code |= ERR_ALERT; |
| 1125 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1126 | } |
| 1127 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1128 | 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] | 1129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1130 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1131 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1132 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1133 | 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] | 1134 | err_code |= ERR_WARN; |
| 1135 | goto out; |
| 1136 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1137 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1138 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1139 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1140 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1141 | global.external_check = 1; |
| 1142 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1143 | /* user/group name handling */ |
| 1144 | else if (!strcmp(args[0], "user")) { |
| 1145 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1146 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1147 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1148 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1149 | 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] | 1150 | err_code |= ERR_ALERT; |
| 1151 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1152 | } |
| 1153 | errno = 0; |
| 1154 | ha_user = getpwnam(args[1]); |
| 1155 | if (ha_user != NULL) { |
| 1156 | global.uid = (int)ha_user->pw_uid; |
| 1157 | } |
| 1158 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1159 | 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] | 1160 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | else if (!strcmp(args[0], "group")) { |
| 1164 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1165 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1166 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1167 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1168 | 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] | 1169 | err_code |= ERR_ALERT; |
| 1170 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1171 | } |
| 1172 | errno = 0; |
| 1173 | ha_group = getgrnam(args[1]); |
| 1174 | if (ha_group != NULL) { |
| 1175 | global.gid = (int)ha_group->gr_gid; |
| 1176 | } |
| 1177 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1178 | 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] | 1179 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1183 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1184 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1186 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1187 | 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] | 1188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1189 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1190 | } |
| 1191 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1192 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1193 | ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1194 | file, linenum, args[0], LONGBITS, global.nbproc); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1195 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1196 | goto out; |
| 1197 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1198 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1199 | else if (!strcmp(args[0], "nbthread")) { |
| 1200 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1201 | goto out; |
| 1202 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1203 | 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] | 1204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1205 | goto out; |
| 1206 | } |
Willy Tarreau | 0ccd322 | 2018-07-30 10:34:35 +0200 | [diff] [blame] | 1207 | global.nbthread = parse_nbthread(args[1], &errmsg); |
| 1208 | if (!global.nbthread) { |
| 1209 | ha_alert("parsing [%s:%d] : '%s' %s.\n", |
| 1210 | file, linenum, args[0], errmsg); |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1211 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1212 | goto out; |
| 1213 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1214 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1215 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1216 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1217 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1218 | if (global.maxconn != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1219 | 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] | 1220 | err_code |= ERR_ALERT; |
| 1221 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1222 | } |
| 1223 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1224 | 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] | 1225 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1226 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1227 | } |
| 1228 | global.maxconn = atol(args[1]); |
| 1229 | #ifdef SYSTEM_MAXCONN |
| 1230 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1231 | 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] | 1232 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1233 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1234 | } |
| 1235 | #endif /* SYSTEM_MAXCONN */ |
| 1236 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1237 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1238 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1239 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1240 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1241 | 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] | 1242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1243 | goto out; |
| 1244 | } |
| 1245 | if (strcmp(args[1],"none") == 0) |
| 1246 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1247 | else if (strcmp(args[1],"required") == 0) |
| 1248 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1249 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1250 | 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] | 1251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1252 | goto out; |
| 1253 | } |
| 1254 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1255 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1256 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1257 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1258 | if (global.cps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1259 | 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] | 1260 | err_code |= ERR_ALERT; |
| 1261 | goto out; |
| 1262 | } |
| 1263 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1264 | 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] | 1265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1266 | goto out; |
| 1267 | } |
| 1268 | global.cps_lim = atol(args[1]); |
| 1269 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1270 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1271 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1272 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1273 | if (global.sps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1274 | 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] | 1275 | err_code |= ERR_ALERT; |
| 1276 | goto out; |
| 1277 | } |
| 1278 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1279 | 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] | 1280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1281 | goto out; |
| 1282 | } |
| 1283 | global.sps_lim = atol(args[1]); |
| 1284 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1285 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1286 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1287 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1288 | if (global.ssl_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1289 | 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] | 1290 | err_code |= ERR_ALERT; |
| 1291 | goto out; |
| 1292 | } |
| 1293 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1294 | 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] | 1295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1296 | goto out; |
| 1297 | } |
| 1298 | global.ssl_lim = atol(args[1]); |
| 1299 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1300 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1301 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1302 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1303 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1304 | 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] | 1305 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1306 | goto out; |
| 1307 | } |
| 1308 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1309 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1310 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1311 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1312 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1313 | if (global.maxpipes != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1314 | 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] | 1315 | err_code |= ERR_ALERT; |
| 1316 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1317 | } |
| 1318 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1319 | 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] | 1320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1321 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1322 | } |
| 1323 | global.maxpipes = atol(args[1]); |
| 1324 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1325 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1326 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1327 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1328 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1329 | 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] | 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1331 | goto out; |
| 1332 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1333 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1334 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1335 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1336 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1337 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1338 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1339 | 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] | 1340 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1341 | goto out; |
| 1342 | } |
| 1343 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1344 | if (compress_min_idle > 100) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1345 | 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] | 1346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1347 | goto out; |
| 1348 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1349 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1350 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1351 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1352 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1353 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1354 | if (global.rlimit_nofile != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1355 | 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] | 1356 | err_code |= ERR_ALERT; |
| 1357 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1358 | } |
| 1359 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1360 | 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] | 1361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1362 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1363 | } |
| 1364 | global.rlimit_nofile = atol(args[1]); |
| 1365 | } |
| 1366 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1367 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1368 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1369 | if (global.chroot != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1370 | 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] | 1371 | err_code |= ERR_ALERT; |
| 1372 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1373 | } |
| 1374 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1375 | 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] | 1376 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1377 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1378 | } |
| 1379 | global.chroot = strdup(args[1]); |
| 1380 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1381 | else if (!strcmp(args[0], "description")) { |
| 1382 | int i, len=0; |
| 1383 | char *d; |
| 1384 | |
| 1385 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1386 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1387 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1388 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1389 | goto out; |
| 1390 | } |
| 1391 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1392 | for (i = 1; *args[i]; i++) |
| 1393 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1394 | |
| 1395 | if (global.desc) |
| 1396 | free(global.desc); |
| 1397 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1398 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1399 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1400 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1401 | for (i = 2; *args[i]; i++) |
| 1402 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1403 | } |
| 1404 | else if (!strcmp(args[0], "node")) { |
| 1405 | int i; |
| 1406 | char c; |
| 1407 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1408 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1409 | goto out; |
| 1410 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1411 | for (i=0; args[1][i]; i++) { |
| 1412 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1413 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1414 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1415 | break; |
| 1416 | } |
| 1417 | |
| 1418 | if (!i || args[1][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1419 | ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1420 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1421 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1422 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1423 | goto out; |
| 1424 | } |
| 1425 | |
| 1426 | if (global.node) |
| 1427 | free(global.node); |
| 1428 | |
| 1429 | global.node = strdup(args[1]); |
| 1430 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1431 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1432 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1433 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1434 | if (global.pidfile != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1435 | 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] | 1436 | err_code |= ERR_ALERT; |
| 1437 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1438 | } |
| 1439 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1440 | 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] | 1441 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1442 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1443 | } |
| 1444 | global.pidfile = strdup(args[1]); |
| 1445 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1446 | else if (!strcmp(args[0], "unix-bind")) { |
| 1447 | int cur_arg = 1; |
| 1448 | while (*(args[cur_arg])) { |
| 1449 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1450 | if (global.unix_bind.prefix != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1451 | 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] | 1452 | err_code |= ERR_ALERT; |
| 1453 | cur_arg += 2; |
| 1454 | continue; |
| 1455 | } |
| 1456 | |
| 1457 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1458 | 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] | 1459 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1460 | goto out; |
| 1461 | } |
| 1462 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1463 | cur_arg += 2; |
| 1464 | continue; |
| 1465 | } |
| 1466 | |
| 1467 | if (!strcmp(args[cur_arg], "mode")) { |
| 1468 | |
| 1469 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1470 | cur_arg += 2; |
| 1471 | continue; |
| 1472 | } |
| 1473 | |
| 1474 | if (!strcmp(args[cur_arg], "uid")) { |
| 1475 | |
| 1476 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1477 | cur_arg += 2; |
| 1478 | continue; |
| 1479 | } |
| 1480 | |
| 1481 | if (!strcmp(args[cur_arg], "gid")) { |
| 1482 | |
| 1483 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1484 | cur_arg += 2; |
| 1485 | continue; |
| 1486 | } |
| 1487 | |
| 1488 | if (!strcmp(args[cur_arg], "user")) { |
| 1489 | struct passwd *user; |
| 1490 | |
| 1491 | user = getpwnam(args[cur_arg + 1]); |
| 1492 | if (!user) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1493 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1494 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1496 | goto out; |
| 1497 | } |
| 1498 | |
| 1499 | global.unix_bind.ux.uid = user->pw_uid; |
| 1500 | cur_arg += 2; |
| 1501 | continue; |
| 1502 | } |
| 1503 | |
| 1504 | if (!strcmp(args[cur_arg], "group")) { |
| 1505 | struct group *group; |
| 1506 | |
| 1507 | group = getgrnam(args[cur_arg + 1]); |
| 1508 | if (!group) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1509 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1510 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
| 1515 | global.unix_bind.ux.gid = group->gr_gid; |
| 1516 | cur_arg += 2; |
| 1517 | continue; |
| 1518 | } |
| 1519 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1520 | ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
| 1521 | file, linenum, args[0]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1523 | goto out; |
| 1524 | } |
| 1525 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 1526 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 1527 | if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 1528 | 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] | 1529 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1530 | goto out; |
| 1531 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1532 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1533 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1534 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1535 | |
| 1536 | if (global.log_send_hostname != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1537 | 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] | 1538 | err_code |= ERR_ALERT; |
| 1539 | goto out; |
| 1540 | } |
| 1541 | |
| 1542 | if (*(args[1])) |
| 1543 | name = args[1]; |
| 1544 | else |
| 1545 | name = hostname; |
| 1546 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1547 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1548 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1549 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1550 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1551 | if (global.server_state_base != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1552 | 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] | 1553 | err_code |= ERR_ALERT; |
| 1554 | goto out; |
| 1555 | } |
| 1556 | |
| 1557 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1558 | 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] | 1559 | err_code |= ERR_FATAL; |
| 1560 | goto out; |
| 1561 | } |
| 1562 | |
| 1563 | global.server_state_base = strdup(args[1]); |
| 1564 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1565 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1566 | if (global.server_state_file != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1567 | 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] | 1568 | err_code |= ERR_ALERT; |
| 1569 | goto out; |
| 1570 | } |
| 1571 | |
| 1572 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1573 | 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] | 1574 | err_code |= ERR_FATAL; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | global.server_state_file = strdup(args[1]); |
| 1579 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1580 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1581 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1582 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1583 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1584 | 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] | 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1586 | goto out; |
| 1587 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1588 | chunk_destroy(&global.log_tag); |
| 1589 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1590 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1591 | 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] | 1592 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1593 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1594 | if (global.spread_checks != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1595 | 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] | 1596 | err_code |= ERR_ALERT; |
| 1597 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1598 | } |
| 1599 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1600 | 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] | 1601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1602 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1603 | } |
| 1604 | global.spread_checks = atol(args[1]); |
| 1605 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1606 | 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] | 1607 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1608 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1609 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1610 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1611 | const char *err; |
| 1612 | unsigned int val; |
| 1613 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1614 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1615 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1616 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1617 | 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] | 1618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1619 | goto out; |
| 1620 | } |
| 1621 | |
| 1622 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1623 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1624 | 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] | 1625 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1626 | } |
| 1627 | global.max_spread_checks = val; |
| 1628 | if (global.max_spread_checks < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1629 | 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] | 1630 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1631 | } |
| 1632 | } |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1633 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 1634 | /* map a process list to a CPU set */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1635 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1636 | char *slash; |
| 1637 | unsigned long proc = 0, thread = 0, cpus; |
| 1638 | int i, j, n, autoinc; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1639 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1640 | if (!*args[1] || !*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1641 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 1642 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 1643 | " followed by a list of CPU ranges with numbers from 0 to %d.\n", |
| 1644 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1645 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1646 | goto out; |
| 1647 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1648 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1649 | if ((slash = strchr(args[1], '/')) != NULL) |
| 1650 | *slash = 0; |
| 1651 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1652 | if (parse_process_number(args[1], &proc, &autoinc, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1653 | 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] | 1654 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1655 | goto out; |
| 1656 | } |
| 1657 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1658 | if (slash) { |
| 1659 | if (parse_process_number(slash+1, &thread, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1660 | 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] | 1661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1662 | goto out; |
| 1663 | } |
| 1664 | *slash = '/'; |
| 1665 | |
| 1666 | if (autoinc && my_popcountl(proc) != 1 && my_popcountl(thread) != 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1667 | ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind " |
| 1668 | "a process range _AND_ a thread range\n", |
| 1669 | file, linenum, args[0], args[1]); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1671 | goto out; |
| 1672 | } |
| 1673 | } |
| 1674 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1675 | if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1676 | 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] | 1677 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1678 | goto out; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1679 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1680 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1681 | if (autoinc && |
| 1682 | my_popcountl(proc) != my_popcountl(cpus) && |
| 1683 | my_popcountl(thread) != my_popcountl(cpus)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1684 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1685 | "must have the same size to be automatically bound\n", |
| 1686 | file, linenum, args[0]); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1687 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1688 | goto out; |
| 1689 | } |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1690 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1691 | for (i = n = 0; i < LONGBITS; i++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1692 | /* No mapping for this process */ |
| 1693 | if (!(proc & (1UL << i))) |
| 1694 | continue; |
| 1695 | |
| 1696 | /* Mapping at the process level */ |
| 1697 | if (!thread) { |
| 1698 | if (!autoinc) |
| 1699 | global.cpu_map.proc[i] = cpus; |
| 1700 | else { |
| 1701 | n += my_ffsl(cpus >> n); |
| 1702 | global.cpu_map.proc[i] = (1UL << (n-1)); |
| 1703 | } |
| 1704 | continue; |
| 1705 | } |
| 1706 | |
| 1707 | /* Mapping at the thread level */ |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1708 | for (j = 0; j < MAX_THREADS; j++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1709 | /* Np mapping for this thread */ |
| 1710 | if (!(thread & (1UL << j))) |
| 1711 | continue; |
| 1712 | |
| 1713 | if (!autoinc) |
| 1714 | global.cpu_map.thread[i][j] = cpus; |
| 1715 | else { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1716 | n += my_ffsl(cpus >> n); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1717 | global.cpu_map.thread[i][j] = (1UL << (n-1)); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1718 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1719 | } |
| 1720 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1721 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1722 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1723 | file, linenum, args[0]); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1724 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1725 | goto out; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1726 | #endif /* ! USE_CPU_AFFINITY */ |
| 1727 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1728 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1729 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1730 | goto out; |
| 1731 | |
| 1732 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1733 | 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] | 1734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1735 | goto out; |
| 1736 | } |
| 1737 | |
| 1738 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1739 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1740 | 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] | 1741 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1742 | goto out; |
| 1743 | } |
| 1744 | } |
| 1745 | else if (!strcmp(args[0], "unsetenv")) { |
| 1746 | int arg; |
| 1747 | |
| 1748 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1749 | 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] | 1750 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1751 | goto out; |
| 1752 | } |
| 1753 | |
| 1754 | for (arg = 1; *args[arg]; arg++) { |
| 1755 | if (unsetenv(args[arg]) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1756 | 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] | 1757 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1758 | goto out; |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | else if (!strcmp(args[0], "resetenv")) { |
| 1763 | extern char **environ; |
| 1764 | char **env = environ; |
| 1765 | |
| 1766 | /* args contain variable names to keep, one per argument */ |
| 1767 | while (*env) { |
| 1768 | int arg; |
| 1769 | |
| 1770 | /* look for current variable in among all those we want to keep */ |
| 1771 | for (arg = 1; *args[arg]; arg++) { |
| 1772 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1773 | (*env)[strlen(args[arg])] == '=') |
| 1774 | break; |
| 1775 | } |
| 1776 | |
| 1777 | /* delete this variable */ |
| 1778 | if (!*args[arg]) { |
| 1779 | char *delim = strchr(*env, '='); |
| 1780 | |
| 1781 | if (!delim || delim - *env >= trash.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1782 | 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] | 1783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1784 | goto out; |
| 1785 | } |
| 1786 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1787 | memcpy(trash.area, *env, delim - *env); |
| 1788 | trash.area[delim - *env] = 0; |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1789 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1790 | if (unsetenv(trash.area) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1791 | 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] | 1792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1793 | goto out; |
| 1794 | } |
| 1795 | } |
| 1796 | else |
| 1797 | env++; |
| 1798 | } |
| 1799 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1800 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1801 | struct cfg_kw_list *kwl; |
| 1802 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1803 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1804 | |
| 1805 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1806 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1807 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1808 | continue; |
| 1809 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1810 | 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] | 1811 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1812 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1813 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1814 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1815 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1816 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1817 | err_code |= ERR_WARN; |
| 1818 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1819 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1820 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1825 | 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] | 1826 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1827 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1828 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1829 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1830 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1831 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1834 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1835 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1836 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1837 | defproxy.mode = PR_MODE_TCP; |
| 1838 | defproxy.state = PR_STNEW; |
| 1839 | defproxy.maxconn = cfg_maxpconn; |
| 1840 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1841 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1842 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1843 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1844 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1845 | defproxy.defsrv.check.fastinter = 0; |
| 1846 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1847 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1848 | defproxy.defsrv.agent.fastinter = 0; |
| 1849 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1850 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1851 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1852 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1853 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1854 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1855 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1856 | defproxy.defsrv.maxqueue = 0; |
| 1857 | defproxy.defsrv.minconn = 0; |
| 1858 | defproxy.defsrv.maxconn = 0; |
| 1859 | defproxy.defsrv.slowstart = 0; |
| 1860 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1861 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1862 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1863 | |
| 1864 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1865 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1868 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1869 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1870 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1871 | * ERR_FATAL in case of error. |
| 1872 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1873 | static int create_cond_regex_rule(const char *file, int line, |
| 1874 | struct proxy *px, int dir, int action, int flags, |
| 1875 | const char *cmd, const char *reg, const char *repl, |
| 1876 | const char **cond_start) |
| 1877 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1878 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1879 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1880 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1881 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1882 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1883 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1884 | int cs; |
| 1885 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1886 | |
| 1887 | if (px == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1888 | 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] | 1889 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1890 | goto err; |
| 1891 | } |
| 1892 | |
| 1893 | if (*reg == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1894 | 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] | 1895 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1896 | goto err; |
| 1897 | } |
| 1898 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1899 | 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] | 1900 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1901 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1902 | if (cond_start && |
| 1903 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 1904 | 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] | 1905 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1906 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1907 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1908 | goto err; |
| 1909 | } |
| 1910 | } |
| 1911 | else if (cond_start && **cond_start) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1912 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1913 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1914 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1915 | goto err; |
| 1916 | } |
| 1917 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1918 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1919 | (dir == SMP_OPT_DIR_REQ) ? |
| 1920 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1921 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1922 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1923 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1924 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1925 | if (!preg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1926 | 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] | 1927 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1928 | goto err; |
| 1929 | } |
| 1930 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1931 | cs = !(flags & REG_ICASE); |
| 1932 | cap = !(flags & REG_NOSUB); |
| 1933 | error = NULL; |
| 1934 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1935 | 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] | 1936 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1937 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1938 | goto err; |
| 1939 | } |
| 1940 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1941 | 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] | 1942 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1943 | if (repl && err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1944 | ha_alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1945 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1946 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1947 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1950 | 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] | 1951 | ret_code |= ERR_WARN; |
| 1952 | |
| 1953 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1954 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1955 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1956 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1957 | err: |
| 1958 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1959 | free(errmsg); |
| 1960 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1963 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1964 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1965 | * Returns the error code, 0 if OK, or any combination of : |
| 1966 | * - ERR_ABORT: must abort ASAP |
| 1967 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1968 | * - ERR_WARN: a warning has been emitted |
| 1969 | * - ERR_ALERT: an alert has been emitted |
| 1970 | * Only the two first ones can stop processing, the two others are just |
| 1971 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1972 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1973 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1974 | { |
| 1975 | static struct peers *curpeers = NULL; |
| 1976 | struct peer *newpeer = NULL; |
| 1977 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1978 | struct bind_conf *bind_conf; |
| 1979 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1980 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1981 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1982 | |
| 1983 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1984 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1985 | 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] | 1986 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1987 | goto out; |
| 1988 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1989 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1990 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1991 | goto out; |
| 1992 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1993 | err = invalid_char(args[1]); |
| 1994 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1995 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1996 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1997 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1998 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2001 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2002 | /* |
| 2003 | * If there are two proxies with the same name only following |
| 2004 | * combinations are allowed: |
| 2005 | */ |
| 2006 | if (strcmp(curpeers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2007 | ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", |
| 2008 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2009 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2013 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2014 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2015 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2016 | goto out; |
| 2017 | } |
| 2018 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2019 | curpeers->next = cfg_peers; |
| 2020 | cfg_peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2021 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2022 | curpeers->conf.line = linenum; |
| 2023 | curpeers->last_change = now.tv_sec; |
| 2024 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2025 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2026 | } |
| 2027 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2028 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2029 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2030 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2031 | |
| 2032 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2033 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2034 | file, linenum, args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2036 | goto out; |
| 2037 | } |
| 2038 | |
| 2039 | err = invalid_char(args[1]); |
| 2040 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2041 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2042 | file, linenum, *err, args[1]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2043 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2044 | goto out; |
| 2045 | } |
| 2046 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2047 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2048 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2049 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | |
| 2053 | /* the peers are linked backwards first */ |
| 2054 | curpeers->count++; |
| 2055 | newpeer->next = curpeers->remote; |
| 2056 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2057 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2058 | newpeer->conf.line = linenum; |
| 2059 | |
| 2060 | newpeer->last_change = now.tv_sec; |
| 2061 | newpeer->id = strdup(args[1]); |
| 2062 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2063 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2064 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2065 | 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] | 2066 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2067 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2068 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2069 | |
| 2070 | proto = protocol_by_family(sk->ss_family); |
| 2071 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2072 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2073 | file, linenum, args[0], args[1]); |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2074 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2075 | goto out; |
| 2076 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2077 | |
| 2078 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2079 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2080 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2082 | goto out; |
| 2083 | } |
| 2084 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2085 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2086 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2087 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2089 | goto out; |
| 2090 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2091 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2092 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2093 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2094 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2095 | newpeer->sock_init_arg = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2096 | HA_SPIN_INIT(&newpeer->lock); |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2097 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2098 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2099 | /* Current is local peer, it define a frontend */ |
| 2100 | newpeer->local = 1; |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2101 | cfg_peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2102 | |
| 2103 | if (!curpeers->peers_fe) { |
| 2104 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2105 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2106 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2107 | goto out; |
| 2108 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2109 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2110 | init_new_proxy(curpeers->peers_fe); |
| 2111 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2112 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2113 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2114 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2115 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2116 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2117 | 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] | 2118 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2119 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2120 | if (errmsg && *errmsg) { |
| 2121 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2122 | 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] | 2123 | } |
| 2124 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2125 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2126 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2127 | err_code |= ERR_FATAL; |
| 2128 | goto out; |
| 2129 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2130 | |
| 2131 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2132 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2133 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2134 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2135 | l->accept = session_accept_fd; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2136 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2137 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2138 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2139 | global.maxsock += l->maxconn; |
| 2140 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2141 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2142 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2143 | ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2144 | file, linenum, args[0], args[1], |
| 2145 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2146 | err_code |= ERR_FATAL; |
| 2147 | goto out; |
| 2148 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2149 | } |
| 2150 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2151 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2152 | curpeers->state = PR_STSTOPPED; |
| 2153 | } |
| 2154 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2155 | curpeers->state = PR_STNEW; |
| 2156 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2157 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2158 | 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] | 2159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2160 | goto out; |
| 2161 | } |
| 2162 | |
| 2163 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2164 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2165 | return err_code; |
| 2166 | } |
| 2167 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2168 | /* |
| 2169 | * Parse a <resolvers> section. |
| 2170 | * Returns the error code, 0 if OK, or any combination of : |
| 2171 | * - ERR_ABORT: must abort ASAP |
| 2172 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2173 | * - ERR_WARN: a warning has been emitted |
| 2174 | * - ERR_ALERT: an alert has been emitted |
| 2175 | * Only the two first ones can stop processing, the two others are just |
| 2176 | * indicators. |
| 2177 | */ |
| 2178 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2179 | { |
| 2180 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2181 | struct dns_nameserver *newnameserver = NULL; |
| 2182 | const char *err; |
| 2183 | int err_code = 0; |
| 2184 | char *errmsg = NULL; |
| 2185 | |
| 2186 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2187 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2188 | 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] | 2189 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2190 | goto out; |
| 2191 | } |
| 2192 | |
| 2193 | err = invalid_char(args[1]); |
| 2194 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2195 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2196 | file, linenum, *err, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2197 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2198 | goto out; |
| 2199 | } |
| 2200 | |
| 2201 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2202 | /* Error if two resolvers owns the same name */ |
| 2203 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2204 | ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2205 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2206 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2207 | } |
| 2208 | } |
| 2209 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2210 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2211 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2212 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2213 | goto out; |
| 2214 | } |
| 2215 | |
| 2216 | /* default values */ |
| 2217 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2218 | curr_resolvers->conf.file = strdup(file); |
| 2219 | curr_resolvers->conf.line = linenum; |
| 2220 | curr_resolvers->id = strdup(args[1]); |
| 2221 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2222 | /* default maximum response size */ |
| 2223 | curr_resolvers->accepted_payload_size = 512; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2224 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2225 | curr_resolvers->hold.nx = 30000; |
| 2226 | curr_resolvers->hold.other = 30000; |
| 2227 | curr_resolvers->hold.refused = 30000; |
| 2228 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 686408b | 2017-08-18 10:15:42 +0200 | [diff] [blame] | 2229 | curr_resolvers->hold.obsolete = 0; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2230 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2231 | curr_resolvers->hold.valid = 10000; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2232 | curr_resolvers->timeout.resolve = 1000; |
| 2233 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2234 | curr_resolvers->resolve_retries = 3; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2235 | curr_resolvers->nb_nameservers = 0; |
| 2236 | LIST_INIT(&curr_resolvers->nameservers); |
| 2237 | LIST_INIT(&curr_resolvers->resolutions.curr); |
| 2238 | LIST_INIT(&curr_resolvers->resolutions.wait); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2239 | HA_SPIN_INIT(&curr_resolvers->lock); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2240 | } |
| 2241 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2242 | struct sockaddr_storage *sk; |
| 2243 | int port1, port2; |
| 2244 | struct protocol *proto; |
| 2245 | |
| 2246 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2247 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2248 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2250 | goto out; |
| 2251 | } |
| 2252 | |
| 2253 | err = invalid_char(args[1]); |
| 2254 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2255 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2256 | file, linenum, *err, args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2258 | goto out; |
| 2259 | } |
| 2260 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2261 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2262 | /* Error if two resolvers owns the same name */ |
| 2263 | if (strcmp(newnameserver->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2264 | 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] | 2265 | file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line); |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2266 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2267 | } |
| 2268 | } |
| 2269 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2270 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2271 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2272 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2273 | goto out; |
| 2274 | } |
| 2275 | |
| 2276 | /* the nameservers are linked backward first */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2277 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2278 | newnameserver->resolvers = curr_resolvers; |
| 2279 | newnameserver->conf.file = strdup(file); |
| 2280 | newnameserver->conf.line = linenum; |
| 2281 | newnameserver->id = strdup(args[1]); |
| 2282 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2283 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2284 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2285 | 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] | 2286 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2287 | goto out; |
| 2288 | } |
| 2289 | |
| 2290 | proto = protocol_by_family(sk->ss_family); |
| 2291 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2292 | 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] | 2293 | file, linenum, args[0], args[1]); |
| 2294 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2295 | goto out; |
| 2296 | } |
| 2297 | |
| 2298 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2299 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2300 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2302 | goto out; |
| 2303 | } |
| 2304 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2305 | if (!port1 && !port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2306 | ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2307 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2309 | goto out; |
| 2310 | } |
| 2311 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2312 | newnameserver->addr = *sk; |
| 2313 | } |
Ben Draut | 44e609b | 2018-05-29 15:40:08 -0600 | [diff] [blame] | 2314 | else if (strcmp(args[0], "parse-resolv-conf") == 0) { |
| 2315 | const char *whitespace = "\r\n\t "; |
| 2316 | char *resolv_line = NULL; |
| 2317 | int resolv_linenum = 0; |
| 2318 | FILE *f = NULL; |
| 2319 | char *address = NULL; |
| 2320 | struct sockaddr_storage *sk = NULL; |
| 2321 | struct protocol *proto; |
| 2322 | int duplicate_name = 0; |
| 2323 | |
| 2324 | if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) { |
| 2325 | ha_alert("parsing [%s:%d] : out of memory.\n", |
| 2326 | file, linenum); |
| 2327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2328 | goto resolv_out; |
| 2329 | } |
| 2330 | |
| 2331 | if ((f = fopen("/etc/resolv.conf", "r")) == NULL) { |
| 2332 | ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n", |
| 2333 | file, linenum); |
| 2334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2335 | goto resolv_out; |
| 2336 | } |
| 2337 | |
| 2338 | sk = calloc(1, sizeof(*sk)); |
| 2339 | if (sk == NULL) { |
| 2340 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", |
| 2341 | resolv_linenum); |
| 2342 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2343 | goto resolv_out; |
| 2344 | } |
| 2345 | |
| 2346 | while (fgets(resolv_line, LINESIZE, f) != NULL) { |
| 2347 | resolv_linenum++; |
| 2348 | if (strncmp(resolv_line, "nameserver", 10) != 0) |
| 2349 | continue; |
| 2350 | |
| 2351 | address = strtok(resolv_line + 10, whitespace); |
| 2352 | if (address == resolv_line + 10) |
| 2353 | continue; |
| 2354 | |
| 2355 | if (address == NULL) { |
| 2356 | ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n", |
| 2357 | resolv_linenum); |
| 2358 | err_code |= ERR_WARN; |
| 2359 | continue; |
| 2360 | } |
| 2361 | |
| 2362 | duplicate_name = 0; |
| 2363 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
| 2364 | if (strcmp(newnameserver->id, address) == 0) { |
| 2365 | 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", |
| 2366 | resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line); |
| 2367 | err_code |= ERR_WARN; |
| 2368 | duplicate_name = 1; |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | if (duplicate_name) |
| 2373 | continue; |
| 2374 | |
| 2375 | memset(sk, 0, sizeof(*sk)); |
| 2376 | sk = str2ip2(address, sk, 1); |
| 2377 | if (!sk) { |
| 2378 | ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, namerserver will be excluded.\n", |
| 2379 | resolv_linenum, address); |
| 2380 | err_code |= ERR_WARN; |
| 2381 | continue; |
| 2382 | } |
| 2383 | |
| 2384 | set_host_port(sk, 53); |
| 2385 | |
| 2386 | proto = protocol_by_family(sk->ss_family); |
| 2387 | if (!proto || !proto->connect) { |
| 2388 | ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n", |
| 2389 | resolv_linenum, address); |
| 2390 | err_code |= ERR_WARN; |
| 2391 | continue; |
| 2392 | } |
| 2393 | |
| 2394 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
| 2395 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2397 | goto resolv_out; |
| 2398 | } |
| 2399 | |
| 2400 | newnameserver->conf.file = strdup("/etc/resolv.conf"); |
| 2401 | if (newnameserver->conf.file == NULL) { |
| 2402 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2403 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2404 | goto resolv_out; |
| 2405 | } |
| 2406 | |
| 2407 | newnameserver->id = strdup(address); |
| 2408 | if (newnameserver->id == NULL) { |
| 2409 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2411 | goto resolv_out; |
| 2412 | } |
| 2413 | |
| 2414 | newnameserver->resolvers = curr_resolvers; |
| 2415 | newnameserver->conf.line = resolv_linenum; |
| 2416 | newnameserver->addr = *sk; |
| 2417 | |
| 2418 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
| 2419 | } |
| 2420 | |
| 2421 | resolv_out: |
| 2422 | free(sk); |
| 2423 | free(resolv_line); |
| 2424 | if (f != NULL) |
| 2425 | fclose(f); |
| 2426 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2427 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2428 | const char *res; |
| 2429 | unsigned int time; |
| 2430 | |
| 2431 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2432 | ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2433 | file, linenum, args[0]); |
| 2434 | 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] | 2435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2436 | goto out; |
| 2437 | } |
| 2438 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2439 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2440 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2441 | file, linenum, *res, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2442 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2443 | goto out; |
| 2444 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2445 | if (strcmp(args[1], "nx") == 0) |
| 2446 | curr_resolvers->hold.nx = time; |
| 2447 | else if (strcmp(args[1], "other") == 0) |
| 2448 | curr_resolvers->hold.other = time; |
| 2449 | else if (strcmp(args[1], "refused") == 0) |
| 2450 | curr_resolvers->hold.refused = time; |
| 2451 | else if (strcmp(args[1], "timeout") == 0) |
| 2452 | curr_resolvers->hold.timeout = time; |
| 2453 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2454 | curr_resolvers->hold.valid = time; |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2455 | else if (strcmp(args[1], "obsolete") == 0) |
| 2456 | curr_resolvers->hold.obsolete = time; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2457 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2458 | ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n", |
| 2459 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2460 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2461 | goto out; |
| 2462 | } |
| 2463 | |
| 2464 | } |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2465 | else if (strcmp(args[0], "accepted_payload_size") == 0) { |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2466 | int i = 0; |
| 2467 | |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2468 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2469 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2470 | file, linenum, args[0]); |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2472 | goto out; |
| 2473 | } |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2474 | |
| 2475 | i = atoi(args[1]); |
Willy Tarreau | 0c219be | 2017-08-22 12:01:26 +0200 | [diff] [blame] | 2476 | if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2477 | ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n", |
| 2478 | 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] | 2479 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2480 | goto out; |
| 2481 | } |
| 2482 | |
| 2483 | curr_resolvers->accepted_payload_size = i; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2484 | } |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2485 | else if (strcmp(args[0], "resolution_pool_size") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2486 | ha_warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n", |
| 2487 | file, linenum, args[0]); |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2488 | err_code |= ERR_WARN; |
| 2489 | goto out; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2490 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2491 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2492 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2493 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2494 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2495 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2496 | goto out; |
| 2497 | } |
| 2498 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2499 | } |
| 2500 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2501 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2502 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n", |
| 2503 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2504 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2505 | goto out; |
| 2506 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2507 | else if (strcmp(args[1], "retry") == 0 || |
| 2508 | strcmp(args[1], "resolve") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2509 | const char *res; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2510 | unsigned int tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2511 | |
| 2512 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2513 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2514 | file, linenum, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2515 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2516 | goto out; |
| 2517 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2518 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2519 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2520 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2521 | file, linenum, *res, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2523 | goto out; |
| 2524 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2525 | if (args[1][2] == 't') |
| 2526 | curr_resolvers->timeout.retry = tout; |
| 2527 | else |
| 2528 | curr_resolvers->timeout.resolve = tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2529 | } |
| 2530 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2531 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n", |
| 2532 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2534 | goto out; |
| 2535 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2536 | } /* neither "nameserver" nor "resolvers" */ |
| 2537 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2538 | 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] | 2539 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2540 | goto out; |
| 2541 | } |
| 2542 | |
| 2543 | out: |
| 2544 | free(errmsg); |
| 2545 | return err_code; |
| 2546 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2547 | |
| 2548 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2549 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2550 | * Returns the error code, 0 if OK, or any combination of : |
| 2551 | * - ERR_ABORT: must abort ASAP |
| 2552 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2553 | * - ERR_WARN: a warning has been emitted |
| 2554 | * - ERR_ALERT: an alert has been emitted |
| 2555 | * Only the two first ones can stop processing, the two others are just |
| 2556 | * indicators. |
| 2557 | */ |
| 2558 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2559 | { |
| 2560 | static struct mailers *curmailers = NULL; |
| 2561 | struct mailer *newmailer = NULL; |
| 2562 | const char *err; |
| 2563 | int err_code = 0; |
| 2564 | char *errmsg = NULL; |
| 2565 | |
| 2566 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2567 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2568 | 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] | 2569 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2570 | goto out; |
| 2571 | } |
| 2572 | |
| 2573 | err = invalid_char(args[1]); |
| 2574 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2575 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2576 | file, linenum, *err, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2577 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2578 | goto out; |
| 2579 | } |
| 2580 | |
| 2581 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2582 | /* |
| 2583 | * If there are two proxies with the same name only following |
| 2584 | * combinations are allowed: |
| 2585 | */ |
| 2586 | if (strcmp(curmailers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2587 | ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", |
| 2588 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2589 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2593 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2594 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2595 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2596 | goto out; |
| 2597 | } |
| 2598 | |
| 2599 | curmailers->next = mailers; |
| 2600 | mailers = curmailers; |
| 2601 | curmailers->conf.file = strdup(file); |
| 2602 | curmailers->conf.line = linenum; |
| 2603 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2604 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2605 | * But need enough time so that timeouts don't occur |
| 2606 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2607 | } |
| 2608 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2609 | struct sockaddr_storage *sk; |
| 2610 | int port1, port2; |
| 2611 | struct protocol *proto; |
| 2612 | |
| 2613 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2614 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2615 | file, linenum, args[0]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2616 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2617 | goto out; |
| 2618 | } |
| 2619 | |
| 2620 | err = invalid_char(args[1]); |
| 2621 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2622 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2623 | file, linenum, *err, args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2625 | goto out; |
| 2626 | } |
| 2627 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2628 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2629 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2630 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2631 | goto out; |
| 2632 | } |
| 2633 | |
| 2634 | /* the mailers are linked backwards first */ |
| 2635 | curmailers->count++; |
| 2636 | newmailer->next = curmailers->mailer_list; |
| 2637 | curmailers->mailer_list = newmailer; |
| 2638 | newmailer->mailers = curmailers; |
| 2639 | newmailer->conf.file = strdup(file); |
| 2640 | newmailer->conf.line = linenum; |
| 2641 | |
| 2642 | newmailer->id = strdup(args[1]); |
| 2643 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2644 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2645 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2646 | 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] | 2647 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2648 | goto out; |
| 2649 | } |
| 2650 | |
| 2651 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2652 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2653 | ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n", |
| 2654 | file, linenum, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2656 | goto out; |
| 2657 | } |
| 2658 | |
| 2659 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2660 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2661 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2663 | goto out; |
| 2664 | } |
| 2665 | |
| 2666 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2667 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2668 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2670 | goto out; |
| 2671 | } |
| 2672 | |
| 2673 | newmailer->addr = *sk; |
| 2674 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2675 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2676 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2677 | } |
| 2678 | else if (strcmp(args[0], "timeout") == 0) { |
| 2679 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2680 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2681 | file, linenum, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2683 | goto out; |
| 2684 | } |
| 2685 | else if (strcmp(args[1], "mail") == 0) { |
| 2686 | const char *res; |
| 2687 | unsigned int timeout_mail; |
| 2688 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2689 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2690 | file, linenum, args[0], args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2691 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2692 | goto out; |
| 2693 | } |
| 2694 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2695 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2696 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2697 | file, linenum, *res, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2698 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2699 | goto out; |
| 2700 | } |
| 2701 | if (timeout_mail <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2702 | 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] | 2703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2704 | goto out; |
| 2705 | } |
| 2706 | curmailers->timeout.mail = timeout_mail; |
| 2707 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2708 | 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] | 2709 | file, linenum, args[0], args[1]); |
| 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
| 2712 | } |
| 2713 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2714 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2715 | 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] | 2716 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2717 | goto out; |
| 2718 | } |
| 2719 | |
| 2720 | out: |
| 2721 | free(errmsg); |
| 2722 | return err_code; |
| 2723 | } |
| 2724 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2725 | static void free_email_alert(struct proxy *p) |
| 2726 | { |
| 2727 | free(p->email_alert.mailers.name); |
| 2728 | p->email_alert.mailers.name = NULL; |
| 2729 | free(p->email_alert.from); |
| 2730 | p->email_alert.from = NULL; |
| 2731 | free(p->email_alert.to); |
| 2732 | p->email_alert.to = NULL; |
| 2733 | free(p->email_alert.myhostname); |
| 2734 | p->email_alert.myhostname = NULL; |
| 2735 | } |
| 2736 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2737 | 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] | 2738 | { |
| 2739 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2740 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2741 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2742 | int rc; |
| 2743 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2744 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2745 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2746 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2747 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2748 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2749 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2750 | if (!strcmp(args[0], "listen")) |
| 2751 | rc = PR_CAP_LISTEN; |
| 2752 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2753 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2754 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2755 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2756 | else |
| 2757 | rc = PR_CAP_NONE; |
| 2758 | |
| 2759 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2760 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2761 | ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 2762 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 2763 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2764 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2765 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2766 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2767 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2768 | err = invalid_char(args[1]); |
| 2769 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2770 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2771 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2772 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2773 | } |
| 2774 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2775 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2776 | if (curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2777 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2778 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2779 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2780 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2781 | } |
| 2782 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2783 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2784 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2785 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2786 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2787 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2788 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2789 | init_new_proxy(curproxy); |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 2790 | curproxy->next = proxies_list; |
| 2791 | proxies_list = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2792 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2793 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2794 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2795 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2796 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2797 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2798 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2799 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2800 | if (curproxy->cap & PR_CAP_FE) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2801 | 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] | 2802 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2806 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2807 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2808 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2809 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2810 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2811 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2812 | curproxy->no_options = defproxy.no_options; |
| 2813 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2814 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2815 | curproxy->except_net = defproxy.except_net; |
| 2816 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2817 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2818 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2819 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2820 | if (defproxy.fwdfor_hdr_len) { |
| 2821 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2822 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2823 | } |
| 2824 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2825 | if (defproxy.orgto_hdr_len) { |
| 2826 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2827 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2828 | } |
| 2829 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2830 | if (defproxy.server_id_hdr_len) { |
| 2831 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2832 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2833 | } |
| 2834 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2835 | if (curproxy->cap & PR_CAP_FE) { |
| 2836 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2837 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2838 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2839 | |
| 2840 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2841 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2842 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2843 | |
| 2844 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2845 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2846 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2847 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2848 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2849 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2850 | curproxy->fullconn = defproxy.fullconn; |
| 2851 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2852 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2853 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2854 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2855 | if (defproxy.check_req) { |
| 2856 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2857 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2858 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2859 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2860 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2861 | if (defproxy.expect_str) { |
| 2862 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2863 | if (defproxy.expect_regex) { |
| 2864 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2865 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2866 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2870 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2871 | if (defproxy.cookie_name) |
| 2872 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2873 | curproxy->cookie_len = defproxy.cookie_len; |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2874 | |
| 2875 | if (defproxy.dyncookie_key) |
| 2876 | curproxy->dyncookie_key = strdup(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2877 | if (defproxy.cookie_domain) |
| 2878 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2879 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2880 | if (defproxy.cookie_maxidle) |
| 2881 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2882 | |
| 2883 | if (defproxy.cookie_maxlife) |
| 2884 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2885 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2886 | if (defproxy.rdp_cookie_name) |
| 2887 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2888 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2889 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2890 | if (defproxy.url_param_name) |
| 2891 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2892 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2893 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2894 | if (defproxy.hh_name) |
| 2895 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2896 | curproxy->hh_len = defproxy.hh_len; |
| 2897 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2898 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2899 | if (defproxy.conn_src.iface_name) |
| 2900 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2901 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2902 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2903 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2904 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2905 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2906 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2907 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2908 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2909 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2910 | if (defproxy.capture_name) |
| 2911 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2912 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2913 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2914 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2915 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2916 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2917 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2918 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2919 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2920 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2921 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2922 | curproxy->mon_net = defproxy.mon_net; |
| 2923 | curproxy->mon_mask = defproxy.mon_mask; |
| 2924 | if (defproxy.monitor_uri) |
| 2925 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2926 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2927 | if (defproxy.defbe.name) |
| 2928 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2929 | |
| 2930 | /* 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] | 2931 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2932 | if (curproxy->conf.logformat_string && |
| 2933 | curproxy->conf.logformat_string != default_http_log_format && |
| 2934 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2935 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2936 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2937 | |
| 2938 | if (defproxy.conf.lfs_file) { |
| 2939 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2940 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2941 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2942 | |
| 2943 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2944 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2945 | if (curproxy->conf.logformat_sd_string && |
| 2946 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2947 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2948 | |
| 2949 | if (defproxy.conf.lfsd_file) { |
| 2950 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2951 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2952 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2956 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2957 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2958 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2959 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2960 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2961 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2962 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2963 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2964 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2965 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2966 | } |
| 2967 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2968 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2969 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2970 | |
| 2971 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2972 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2973 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2974 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
Christopher Faulet | 28ac099 | 2018-03-26 16:09:19 +0200 | [diff] [blame] | 2975 | node->ref = tmplogsrv->ref; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2976 | LIST_INIT(&node->list); |
| 2977 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2978 | } |
| 2979 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2980 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2981 | if (curproxy->conf.uniqueid_format_string) |
| 2982 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2983 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2984 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2985 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2986 | if (defproxy.conf.uif_file) { |
| 2987 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2988 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2989 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2990 | |
| 2991 | /* copy default header unique id */ |
| 2992 | if (defproxy.header_unique_id) |
| 2993 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2994 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2995 | /* default compression options */ |
| 2996 | if (defproxy.comp != NULL) { |
| 2997 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2998 | curproxy->comp->algos = defproxy.comp->algos; |
| 2999 | curproxy->comp->types = defproxy.comp->types; |
| 3000 | } |
| 3001 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3002 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3003 | curproxy->conf.used_listener_id = EB_ROOT; |
| 3004 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3005 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3006 | if (defproxy.check_path) |
| 3007 | curproxy->check_path = strdup(defproxy.check_path); |
| 3008 | if (defproxy.check_command) |
| 3009 | curproxy->check_command = strdup(defproxy.check_command); |
| 3010 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3011 | if (defproxy.email_alert.mailers.name) |
| 3012 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3013 | if (defproxy.email_alert.from) |
| 3014 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3015 | if (defproxy.email_alert.to) |
| 3016 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3017 | if (defproxy.email_alert.myhostname) |
| 3018 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3019 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3020 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3021 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3022 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3023 | } |
| 3024 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3025 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3026 | /* FIXME-20070101: we should do this too at the end of the |
| 3027 | * config parsing to free all default values. |
| 3028 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3029 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3030 | err_code |= ERR_ABORT; |
| 3031 | goto out; |
| 3032 | } |
| 3033 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3034 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3035 | free(defproxy.check_command); |
| 3036 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3037 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3038 | free(defproxy.rdp_cookie_name); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3039 | free(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3040 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3041 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3042 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3043 | free(defproxy.capture_name); |
| 3044 | free(defproxy.monitor_uri); |
| 3045 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3046 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3047 | free(defproxy.fwdfor_hdr_name); |
| 3048 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3049 | free(defproxy.orgto_hdr_name); |
| 3050 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3051 | free(defproxy.server_id_hdr_name); |
| 3052 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3053 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3054 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3055 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3056 | free(defproxy.expect_regex); |
| 3057 | defproxy.expect_regex = NULL; |
| 3058 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3059 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3060 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3061 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3062 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3063 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3064 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3065 | free(defproxy.conf.uniqueid_format_string); |
| 3066 | free(defproxy.conf.lfs_file); |
| 3067 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3068 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3069 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3070 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3071 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3072 | free(defproxy.conf.logformat_sd_string); |
| 3073 | free(defproxy.conf.lfsd_file); |
| 3074 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3075 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3076 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3077 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3078 | /* we cannot free uri_auth because it might already be used */ |
| 3079 | init_default_instance(); |
| 3080 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3081 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3082 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3083 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3084 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3085 | } |
| 3086 | else if (curproxy == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3087 | ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3089 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3090 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3091 | |
| 3092 | /* update the current file and line being parsed */ |
| 3093 | curproxy->conf.args.file = curproxy->conf.file; |
| 3094 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3095 | |
| 3096 | /* Now let's parse the proxy-specific keywords */ |
Frédéric Lécaille | b82f742 | 2017-04-13 18:24:23 +0200 | [diff] [blame] | 3097 | if (!strcmp(args[0], "server") || |
| 3098 | !strcmp(args[0], "default-server") || |
| 3099 | !strcmp(args[0], "server-template")) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3100 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3101 | if (err_code & ERR_FATAL) |
| 3102 | goto out; |
| 3103 | } |
| 3104 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3105 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3106 | int cur_arg; |
| 3107 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3108 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3109 | 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] | 3110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3111 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3112 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3113 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3114 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3115 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3116 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3117 | ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
| 3118 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3120 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3121 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3122 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 3123 | 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] | 3124 | |
| 3125 | /* use default settings for unix sockets */ |
| 3126 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3127 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3128 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3129 | |
| 3130 | /* NOTE: the following line might create several listeners if there |
| 3131 | * are comma-separated IPs or port ranges. So all further processing |
| 3132 | * will have to be applied to all listeners created after last_listen. |
| 3133 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3134 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3135 | if (errmsg && *errmsg) { |
| 3136 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3137 | 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] | 3138 | } |
| 3139 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3140 | ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3141 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3142 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3143 | goto out; |
| 3144 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3145 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3146 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3147 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3148 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3149 | } |
| 3150 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3151 | cur_arg = 2; |
| 3152 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3153 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3154 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3155 | char *err; |
| 3156 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3157 | kw = bind_find_kw(args[cur_arg]); |
| 3158 | if (kw) { |
| 3159 | char *err = NULL; |
| 3160 | int code; |
| 3161 | |
| 3162 | if (!kw->parse) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3163 | ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3164 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3165 | cur_arg += 1 + kw->skip ; |
| 3166 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3167 | goto out; |
| 3168 | } |
| 3169 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3170 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3171 | err_code |= code; |
| 3172 | |
| 3173 | if (code) { |
| 3174 | if (err && *err) { |
| 3175 | indent_msg(&err, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3176 | 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] | 3177 | } |
| 3178 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3179 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3180 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3181 | if (code & ERR_FATAL) { |
| 3182 | free(err); |
| 3183 | cur_arg += 1 + kw->skip; |
| 3184 | goto out; |
| 3185 | } |
| 3186 | } |
| 3187 | free(err); |
| 3188 | cur_arg += 1 + kw->skip; |
| 3189 | continue; |
| 3190 | } |
| 3191 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3192 | err = NULL; |
| 3193 | if (!bind_dumped) { |
| 3194 | bind_dump_kws(&err); |
| 3195 | indent_msg(&err, 4); |
| 3196 | bind_dumped = 1; |
| 3197 | } |
| 3198 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3199 | ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3200 | file, linenum, args[0], args[1], args[cur_arg], |
| 3201 | err ? " Registered keywords :" : "", err ? err : ""); |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3202 | free(err); |
| 3203 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3204 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3205 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3206 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3207 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3208 | } |
| 3209 | 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] | 3210 | 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] | 3211 | ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3212 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3214 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3215 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3216 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3217 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3218 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3219 | /* flush useless bits */ |
| 3220 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3221 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3222 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3223 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3224 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3225 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3226 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3227 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3228 | goto out; |
| 3229 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3230 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3231 | ha_alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3232 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3233 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3234 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3235 | } |
| 3236 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3237 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3238 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3239 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3240 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3241 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3242 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3243 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3244 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3245 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3246 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3247 | goto out; |
| 3248 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3249 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3250 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3251 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3252 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3253 | 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] | 3254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3255 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3256 | } |
| 3257 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3258 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3259 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3260 | |
| 3261 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3262 | 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] | 3263 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3264 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3265 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3266 | } |
| 3267 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3268 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3269 | goto out; |
| 3270 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3271 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3272 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3273 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3275 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3279 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3280 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3281 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3282 | if (curproxy->uuid <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3283 | ha_alert("parsing [%s:%d]: custom id has to be > 0.\n", |
| 3284 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3286 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3287 | } |
| 3288 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3289 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3290 | if (node) { |
| 3291 | struct proxy *target = container_of(node, struct proxy, conf.id); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3292 | ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3293 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3294 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3296 | goto out; |
| 3297 | } |
| 3298 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3299 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3300 | else if (!strcmp(args[0], "description")) { |
| 3301 | int i, len=0; |
| 3302 | char *d; |
| 3303 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3304 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3305 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3306 | file, linenum, args[0]); |
| 3307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3308 | goto out; |
| 3309 | } |
| 3310 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3311 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3312 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3313 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3314 | return -1; |
| 3315 | } |
| 3316 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3317 | for (i = 1; *args[i]; i++) |
| 3318 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3319 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3320 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3321 | curproxy->desc = d; |
| 3322 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3323 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3324 | for (i = 2; *args[i]; i++) |
| 3325 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3326 | |
| 3327 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3328 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3329 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3330 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3331 | curproxy->state = PR_STSTOPPED; |
| 3332 | } |
| 3333 | 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] | 3334 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3335 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3336 | curproxy->state = PR_STNEW; |
| 3337 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3338 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3339 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3340 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3341 | |
| 3342 | while (*args[cur_arg]) { |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3343 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3344 | set = 0; |
| 3345 | break; |
| 3346 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 3347 | if (parse_process_number(args[cur_arg], &set, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3348 | 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] | 3349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3350 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3351 | } |
| 3352 | cur_arg++; |
| 3353 | } |
| 3354 | curproxy->bind_proc = set; |
| 3355 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3356 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3357 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3358 | 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] | 3359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3360 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3361 | } |
| 3362 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3363 | err = invalid_char(args[1]); |
| 3364 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3365 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3366 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3367 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1822e8c | 2017-04-12 18:54:00 +0200 | [diff] [blame] | 3368 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3369 | } |
| 3370 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3371 | 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] | 3372 | ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3373 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3375 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3376 | } |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3377 | } |
| 3378 | else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */ |
| 3379 | |
| 3380 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3381 | err_code |= ERR_WARN; |
| 3382 | |
| 3383 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3384 | ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 3385 | file, linenum, args[0]); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3386 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3387 | goto out; |
| 3388 | } |
| 3389 | free(curproxy->dyncookie_key); |
| 3390 | curproxy->dyncookie_key = strdup(args[1]); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3391 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3393 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3394 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3395 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3396 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3397 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3398 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3399 | ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3400 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3401 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3402 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3403 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3404 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3405 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3406 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3407 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3408 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3409 | curproxy->cookie_name = strdup(args[1]); |
| 3410 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3411 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3412 | cur_arg = 2; |
| 3413 | while (*(args[cur_arg])) { |
| 3414 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3415 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3416 | } |
| 3417 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3418 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3419 | } |
| 3420 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3421 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3422 | } |
| 3423 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3424 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3425 | } |
| 3426 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3427 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3428 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3429 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3430 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3431 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3432 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3433 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3434 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3435 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3436 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3437 | } |
| 3438 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3439 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3440 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3441 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3442 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3443 | ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3444 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3446 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3447 | } |
| 3448 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3449 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3450 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3451 | ha_warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3452 | " dots nor does not start with a dot." |
| 3453 | " RFC forbids it, this configuration may not work properly.\n", |
| 3454 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3455 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3459 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3460 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3461 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3462 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3463 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3464 | } |
| 3465 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3466 | if (!curproxy->cookie_domain) { |
| 3467 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3468 | } else { |
| 3469 | /* one domain was already specified, add another one by |
| 3470 | * building the string which will be returned along with |
| 3471 | * the cookie. |
| 3472 | */ |
| 3473 | char *new_ptr; |
| 3474 | int new_len = strlen(curproxy->cookie_domain) + |
| 3475 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3476 | new_ptr = malloc(new_len); |
| 3477 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3478 | free(curproxy->cookie_domain); |
| 3479 | curproxy->cookie_domain = new_ptr; |
| 3480 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3481 | cur_arg++; |
| 3482 | } |
| 3483 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3484 | unsigned int maxidle; |
| 3485 | const char *res; |
| 3486 | |
| 3487 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3488 | ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3489 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3490 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3491 | goto out; |
| 3492 | } |
| 3493 | |
| 3494 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3495 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3496 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3497 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3499 | goto out; |
| 3500 | } |
| 3501 | curproxy->cookie_maxidle = maxidle; |
| 3502 | cur_arg++; |
| 3503 | } |
| 3504 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3505 | unsigned int maxlife; |
| 3506 | const char *res; |
| 3507 | |
| 3508 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3509 | ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3510 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3511 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3512 | goto out; |
| 3513 | } |
| 3514 | |
| 3515 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3516 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3517 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3518 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3519 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3520 | goto out; |
| 3521 | } |
| 3522 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3523 | cur_arg++; |
| 3524 | } |
Olivier Houchard | a5938f7 | 2017-03-15 15:12:06 +0100 | [diff] [blame] | 3525 | else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */ |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3526 | |
| 3527 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 3528 | err_code |= ERR_WARN; |
| 3529 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 3530 | } |
| 3531 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3532 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3533 | ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n", |
| 3534 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3537 | } |
| 3538 | cur_arg++; |
| 3539 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3540 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3541 | ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3542 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3543 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3544 | } |
| 3545 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3546 | 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] | 3547 | ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 3548 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3549 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3550 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3551 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3552 | 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] | 3553 | ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3554 | file, linenum); |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3555 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3556 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3557 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3558 | else if (!strcmp(args[0], "email-alert")) { |
| 3559 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3560 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3561 | file, linenum, args[0]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3562 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3563 | goto out; |
| 3564 | } |
| 3565 | |
| 3566 | if (!strcmp(args[1], "from")) { |
| 3567 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3568 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3569 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3571 | goto out; |
| 3572 | } |
| 3573 | free(curproxy->email_alert.from); |
| 3574 | curproxy->email_alert.from = strdup(args[2]); |
| 3575 | } |
| 3576 | else if (!strcmp(args[1], "mailers")) { |
| 3577 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3578 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3579 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3581 | goto out; |
| 3582 | } |
| 3583 | free(curproxy->email_alert.mailers.name); |
| 3584 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3585 | } |
| 3586 | else if (!strcmp(args[1], "myhostname")) { |
| 3587 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3588 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3589 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3591 | goto out; |
| 3592 | } |
| 3593 | free(curproxy->email_alert.myhostname); |
| 3594 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3595 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3596 | else if (!strcmp(args[1], "level")) { |
| 3597 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3598 | if (curproxy->email_alert.level < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3599 | ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3600 | file, linenum, args[1], args[2]); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3601 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3602 | goto out; |
| 3603 | } |
| 3604 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3605 | else if (!strcmp(args[1], "to")) { |
| 3606 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3607 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3608 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3610 | goto out; |
| 3611 | } |
| 3612 | free(curproxy->email_alert.to); |
| 3613 | curproxy->email_alert.to = strdup(args[2]); |
| 3614 | } |
| 3615 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3616 | ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3617 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3619 | goto out; |
| 3620 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3621 | /* Indicate that the email_alert is at least partially configured */ |
| 3622 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3623 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3624 | else if (!strcmp(args[0], "external-check")) { |
| 3625 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3626 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3627 | file, linenum, args[0]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3628 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3629 | goto out; |
| 3630 | } |
| 3631 | |
| 3632 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3633 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3634 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3635 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3636 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3637 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3638 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3639 | goto out; |
| 3640 | } |
| 3641 | free(curproxy->check_command); |
| 3642 | curproxy->check_command = strdup(args[2]); |
| 3643 | } |
| 3644 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3645 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3646 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3647 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3648 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3649 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3650 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3651 | goto out; |
| 3652 | } |
| 3653 | free(curproxy->check_path); |
| 3654 | curproxy->check_path = strdup(args[2]); |
| 3655 | } |
| 3656 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3657 | ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3658 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3660 | goto out; |
| 3661 | } |
| 3662 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3663 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3664 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3665 | ha_alert("parsing [%s:%d] : missing persist method.\n", |
| 3666 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3667 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3668 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3672 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3673 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3674 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3675 | const char *beg, *end; |
| 3676 | |
| 3677 | beg = args[1] + 11; |
| 3678 | end = strchr(beg, ')'); |
| 3679 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3680 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3681 | goto out; |
| 3682 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3683 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3684 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3685 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3687 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | free(curproxy->rdp_cookie_name); |
| 3691 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3692 | curproxy->rdp_cookie_len = end-beg; |
| 3693 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3694 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3695 | free(curproxy->rdp_cookie_name); |
| 3696 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3697 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3698 | } |
| 3699 | else { /* syntax */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3700 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3701 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3702 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3703 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3704 | } |
| 3705 | } |
| 3706 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3707 | ha_alert("parsing [%s:%d] : unknown persist method.\n", |
| 3708 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3710 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3711 | } |
| 3712 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3713 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3714 | 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] | 3715 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3716 | goto out; |
| 3717 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3718 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3719 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3720 | err_code |= ERR_WARN; |
| 3721 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3722 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3723 | } |
| 3724 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3725 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3726 | } |
| 3727 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3728 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3729 | } |
| 3730 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3731 | ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3732 | file, linenum, args[0], args[1]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3734 | goto out; |
| 3735 | } |
| 3736 | } |
| 3737 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3738 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3739 | err_code |= ERR_WARN; |
| 3740 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3741 | ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3742 | file, linenum, args[0]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3744 | goto out; |
| 3745 | } |
| 3746 | else if (!strcmp(args[1], "use-backend-name")) |
| 3747 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3748 | else |
| 3749 | curproxy->server_state_file_name = strdup(args[1]); |
| 3750 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3751 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3752 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3753 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3754 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3755 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3756 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3757 | 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] | 3758 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3759 | goto out; |
| 3760 | } |
| 3761 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3762 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3763 | goto out; |
| 3764 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3765 | if (*(args[4]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3766 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3767 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3769 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3770 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3771 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3772 | curproxy->capture_name = strdup(args[2]); |
| 3773 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3774 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3775 | curproxy->to_log |= LW_COOKIE; |
| 3776 | } |
| 3777 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3778 | struct cap_hdr *hdr; |
| 3779 | |
| 3780 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3781 | 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] | 3782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3783 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3784 | } |
| 3785 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3786 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3787 | goto out; |
| 3788 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3789 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3790 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3791 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3793 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3794 | } |
| 3795 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3796 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3797 | hdr->next = curproxy->req_cap; |
| 3798 | hdr->name = strdup(args[3]); |
| 3799 | hdr->namelen = strlen(args[3]); |
| 3800 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3801 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3802 | hdr->index = curproxy->nb_req_cap++; |
| 3803 | curproxy->req_cap = hdr; |
| 3804 | curproxy->to_log |= LW_REQHDR; |
| 3805 | } |
| 3806 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3807 | struct cap_hdr *hdr; |
| 3808 | |
| 3809 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3810 | 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] | 3811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3812 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3813 | } |
| 3814 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3815 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3816 | goto out; |
| 3817 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3818 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3819 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3820 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3821 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3822 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3823 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3824 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3825 | hdr->next = curproxy->rsp_cap; |
| 3826 | hdr->name = strdup(args[3]); |
| 3827 | hdr->namelen = strlen(args[3]); |
| 3828 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3829 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3830 | hdr->index = curproxy->nb_rsp_cap++; |
| 3831 | curproxy->rsp_cap = hdr; |
| 3832 | curproxy->to_log |= LW_RSPHDR; |
| 3833 | } |
| 3834 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3835 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3836 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3837 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3838 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3839 | } |
| 3840 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3841 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3842 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3843 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3844 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3845 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3846 | goto out; |
| 3847 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3848 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3849 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3850 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3852 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3853 | } |
| 3854 | curproxy->conn_retries = atol(args[1]); |
| 3855 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3856 | 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] | 3857 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3858 | |
| 3859 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3860 | 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] | 3861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3862 | goto out; |
| 3863 | } |
| 3864 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3865 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3866 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3867 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3868 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3869 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3870 | 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] | 3871 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3872 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3873 | err_code |= ERR_WARN; |
| 3874 | } |
| 3875 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3876 | 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] | 3877 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3878 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3879 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3880 | goto out; |
| 3881 | } |
| 3882 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3883 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3884 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3885 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3886 | file, linenum); |
| 3887 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3888 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3889 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3890 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3891 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3892 | |
| 3893 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3894 | 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] | 3895 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3896 | goto out; |
| 3897 | } |
| 3898 | |
| 3899 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3900 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3901 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3902 | 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] | 3903 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3904 | file, linenum, args[0]); |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3905 | err_code |= ERR_WARN; |
| 3906 | } |
| 3907 | |
| 3908 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3909 | |
| 3910 | if (!rule) { |
| 3911 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3912 | goto out; |
| 3913 | } |
| 3914 | |
| 3915 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3916 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3917 | file, linenum); |
| 3918 | |
| 3919 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3920 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3921 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3922 | /* set the header name and length into the proxy structure */ |
| 3923 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3924 | err_code |= ERR_WARN; |
| 3925 | |
| 3926 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3927 | ha_alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3928 | file, linenum, args[0]); |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3929 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3930 | goto out; |
| 3931 | } |
| 3932 | |
| 3933 | /* set the desired header name */ |
| 3934 | free(curproxy->server_id_hdr_name); |
| 3935 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3936 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3937 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3938 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3939 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3940 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3941 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3942 | 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] | 3943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3944 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3947 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3948 | * be processed before all http-request rules, we put them into their own list |
| 3949 | * and will insert them at the end. |
| 3950 | */ |
| 3951 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3952 | if (!rule) { |
| 3953 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3954 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3955 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3956 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3957 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3958 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3959 | file, linenum); |
| 3960 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3961 | |
| 3962 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3963 | 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] | 3964 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3965 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3966 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3967 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3968 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3969 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3970 | 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] | 3971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3972 | goto out; |
| 3973 | } |
| 3974 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3975 | 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] | 3976 | ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3977 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3978 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3979 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3980 | } |
| 3981 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3982 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3983 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3984 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3985 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3986 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3987 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3988 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3989 | struct switching_rule *rule; |
| 3990 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3991 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3992 | 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] | 3993 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3994 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3995 | } |
| 3996 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3997 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3998 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3999 | |
| 4000 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4001 | 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] | 4002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4003 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4004 | } |
| 4005 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4006 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4007 | 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] | 4008 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4009 | file, linenum, errmsg); |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4011 | goto out; |
| 4012 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4013 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4014 | 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] | 4015 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4016 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4017 | ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 4018 | file, linenum, args[2]); |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4019 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4020 | goto out; |
| 4021 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4022 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4023 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4024 | if (!rule) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4025 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4026 | goto out; |
| 4027 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4028 | rule->cond = cond; |
| 4029 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4030 | rule->line = linenum; |
| 4031 | rule->file = strdup(file); |
| 4032 | if (!rule->file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4033 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4034 | goto out; |
| 4035 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4036 | LIST_INIT(&rule->list); |
| 4037 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4038 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4039 | else if (strcmp(args[0], "use-server") == 0) { |
| 4040 | struct server_rule *rule; |
| 4041 | |
| 4042 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4043 | 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] | 4044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
| 4048 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4049 | err_code |= ERR_WARN; |
| 4050 | |
| 4051 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4052 | 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] | 4053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4054 | goto out; |
| 4055 | } |
| 4056 | |
| 4057 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4058 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4059 | file, linenum, args[0]); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4061 | goto out; |
| 4062 | } |
| 4063 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4064 | 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] | 4065 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4066 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4068 | goto out; |
| 4069 | } |
| 4070 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4071 | 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] | 4072 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4073 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4074 | rule->cond = cond; |
| 4075 | rule->srv.name = strdup(args[1]); |
| 4076 | LIST_INIT(&rule->list); |
| 4077 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4078 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4079 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4080 | else if ((!strcmp(args[0], "force-persist")) || |
| 4081 | (!strcmp(args[0], "ignore-persist"))) { |
| 4082 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4083 | |
| 4084 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4085 | 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] | 4086 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4087 | goto out; |
| 4088 | } |
| 4089 | |
Cyril Bonté | 4288c5a | 2018-03-12 22:02:59 +0100 | [diff] [blame] | 4090 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4091 | err_code |= ERR_WARN; |
| 4092 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4093 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4094 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4095 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4096 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4097 | goto out; |
| 4098 | } |
| 4099 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4100 | 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] | 4101 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4102 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4104 | goto out; |
| 4105 | } |
| 4106 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4107 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4108 | * where force-persist is applied. |
| 4109 | */ |
| 4110 | 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] | 4111 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4112 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4113 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4114 | if (!strcmp(args[0], "force-persist")) { |
| 4115 | rule->type = PERSIST_TYPE_FORCE; |
| 4116 | } else { |
| 4117 | rule->type = PERSIST_TYPE_IGNORE; |
| 4118 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4119 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4120 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4121 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4122 | else if (!strcmp(args[0], "stick-table")) { |
| 4123 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4124 | struct proxy *other; |
| 4125 | |
Willy Tarreau | c786768 | 2018-07-27 10:26:22 +0200 | [diff] [blame] | 4126 | if (curproxy == &defproxy) { |
| 4127 | ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n", |
| 4128 | file, linenum); |
| 4129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4130 | goto out; |
| 4131 | } |
| 4132 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4133 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4134 | if (other) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4135 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4136 | 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] | 4137 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4138 | goto out; |
| 4139 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4140 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4141 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4142 | curproxy->table.type = (unsigned int)-1; |
| 4143 | while (*args[myidx]) { |
| 4144 | const char *err; |
| 4145 | |
| 4146 | if (strcmp(args[myidx], "size") == 0) { |
| 4147 | myidx++; |
| 4148 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4149 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4150 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4152 | goto out; |
| 4153 | } |
| 4154 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4155 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4156 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4157 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4158 | goto out; |
| 4159 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4160 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4161 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4162 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4163 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4164 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4165 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4166 | file, linenum, args[myidx-1]); |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4167 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4168 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4169 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4170 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4171 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4172 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4173 | myidx++; |
| 4174 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4175 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4176 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4178 | goto out; |
| 4179 | } |
| 4180 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4181 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4182 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4183 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4185 | goto out; |
| 4186 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4187 | if (val > INT_MAX) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4188 | ha_alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4189 | file, linenum, val); |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4191 | goto out; |
| 4192 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4193 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4194 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4195 | } |
| 4196 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4197 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4198 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4199 | } |
| 4200 | else if (strcmp(args[myidx], "type") == 0) { |
| 4201 | myidx++; |
| 4202 | 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] | 4203 | ha_alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4204 | file, linenum, args[myidx]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4206 | goto out; |
| 4207 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4208 | /* myidx already points to next arg */ |
| 4209 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4210 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4211 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4212 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4213 | |
| 4214 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4215 | nw = args[myidx]; |
| 4216 | while (*nw) { |
| 4217 | /* the "store" keyword supports a comma-separated list */ |
| 4218 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4219 | sa = NULL; /* store arg */ |
| 4220 | while (*nw && *nw != ',') { |
| 4221 | if (*nw == '(') { |
| 4222 | *nw = 0; |
| 4223 | sa = ++nw; |
| 4224 | while (*nw != ')') { |
| 4225 | if (!*nw) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4226 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4227 | file, linenum, args[0], cw); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4228 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4229 | goto out; |
| 4230 | } |
| 4231 | nw++; |
| 4232 | } |
| 4233 | *nw = '\0'; |
| 4234 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4235 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4236 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4237 | if (*nw) |
| 4238 | *nw++ = '\0'; |
| 4239 | type = stktable_get_data_type(cw); |
| 4240 | if (type < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4241 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4242 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4244 | goto out; |
| 4245 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4246 | |
| 4247 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4248 | switch (err) { |
| 4249 | case PE_NONE: break; |
| 4250 | case PE_EXIST: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4251 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4252 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4253 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4254 | break; |
| 4255 | |
| 4256 | case PE_ARG_MISSING: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4257 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4258 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4260 | goto out; |
| 4261 | |
| 4262 | case PE_ARG_NOT_USED: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4263 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4264 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4266 | goto out; |
| 4267 | |
| 4268 | default: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4269 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4270 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4271 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4272 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4273 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4274 | } |
| 4275 | myidx++; |
| 4276 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4277 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4278 | ha_alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4279 | file, linenum, args[myidx]); |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4281 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4282 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | if (!curproxy->table.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4286 | ha_alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4287 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4289 | goto out; |
| 4290 | } |
| 4291 | |
| 4292 | if (curproxy->table.type == (unsigned int)-1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4293 | ha_alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4294 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4296 | goto out; |
| 4297 | } |
| 4298 | } |
| 4299 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4300 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4301 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4302 | int myidx = 0; |
| 4303 | const char *name = NULL; |
| 4304 | int flags; |
| 4305 | |
| 4306 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4307 | 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] | 4308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4309 | goto out; |
| 4310 | } |
| 4311 | |
| 4312 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4313 | err_code |= ERR_WARN; |
| 4314 | goto out; |
| 4315 | } |
| 4316 | |
| 4317 | myidx++; |
| 4318 | if ((strcmp(args[myidx], "store") == 0) || |
| 4319 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4320 | myidx++; |
| 4321 | flags = STK_IS_STORE; |
| 4322 | } |
| 4323 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4324 | myidx++; |
| 4325 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4326 | } |
| 4327 | else if (strcmp(args[myidx], "match") == 0) { |
| 4328 | myidx++; |
| 4329 | flags = STK_IS_MATCH; |
| 4330 | } |
| 4331 | else if (strcmp(args[myidx], "on") == 0) { |
| 4332 | myidx++; |
| 4333 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4334 | } |
| 4335 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4336 | 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] | 4337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4338 | goto out; |
| 4339 | } |
| 4340 | |
| 4341 | if (*(args[myidx]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4342 | 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] | 4343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4344 | goto out; |
| 4345 | } |
| 4346 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4347 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4348 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4349 | if (!expr) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4350 | 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] | 4351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4352 | goto out; |
| 4353 | } |
| 4354 | |
| 4355 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4356 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4357 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4358 | 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] | 4359 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4360 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4361 | goto out; |
| 4362 | } |
| 4363 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4364 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4365 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4366 | 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] | 4367 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4368 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4369 | goto out; |
| 4370 | } |
| 4371 | } |
| 4372 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4373 | /* 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] | 4374 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4375 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4376 | if (strcmp(args[myidx], "table") == 0) { |
| 4377 | myidx++; |
| 4378 | name = args[myidx++]; |
| 4379 | } |
| 4380 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4381 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4382 | 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] | 4383 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4384 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4385 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4386 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4387 | goto out; |
| 4388 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4389 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4390 | else if (*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4391 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4392 | file, linenum, args[0], args[myidx]); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4393 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4394 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4395 | goto out; |
| 4396 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4397 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4398 | 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] | 4399 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4400 | 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] | 4401 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4402 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4403 | rule->cond = cond; |
| 4404 | rule->expr = expr; |
| 4405 | rule->flags = flags; |
| 4406 | rule->table.name = name ? strdup(name) : NULL; |
| 4407 | LIST_INIT(&rule->list); |
| 4408 | if (flags & STK_ON_RSP) |
| 4409 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4410 | else |
| 4411 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4412 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4413 | else if (!strcmp(args[0], "stats")) { |
| 4414 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4415 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4416 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4417 | if (!*args[1]) { |
| 4418 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4419 | } else if (!strcmp(args[1], "admin")) { |
| 4420 | struct stats_admin_rule *rule; |
| 4421 | |
| 4422 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4423 | 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] | 4424 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4425 | goto out; |
| 4426 | } |
| 4427 | |
| 4428 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4429 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4430 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4431 | goto out; |
| 4432 | } |
| 4433 | |
| 4434 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4435 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4436 | file, linenum, args[0], args[1]); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4438 | goto out; |
| 4439 | } |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4440 | 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] | 4441 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4442 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4443 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4444 | goto out; |
| 4445 | } |
| 4446 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4447 | err_code |= warnif_cond_conflicts(cond, |
| 4448 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4449 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4450 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4451 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4452 | rule->cond = cond; |
| 4453 | LIST_INIT(&rule->list); |
| 4454 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4455 | } else if (!strcmp(args[1], "uri")) { |
| 4456 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4457 | 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] | 4458 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4459 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4460 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4461 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4462 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4463 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4464 | } |
| 4465 | } else if (!strcmp(args[1], "realm")) { |
| 4466 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4467 | 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] | 4468 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4469 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4470 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4471 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4472 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4473 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4474 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4475 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4476 | unsigned interval; |
| 4477 | |
| 4478 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4479 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4480 | ha_alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4481 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4482 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4483 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4484 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4485 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4486 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4487 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4488 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4489 | } 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] | 4490 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4491 | |
| 4492 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4493 | 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] | 4494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4495 | goto out; |
| 4496 | } |
| 4497 | |
| 4498 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4499 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4500 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4501 | goto out; |
| 4502 | } |
| 4503 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4504 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4505 | !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] | 4506 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4507 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4508 | err_code |= ERR_WARN; |
| 4509 | } |
| 4510 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4511 | 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] | 4512 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4513 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4514 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4515 | goto out; |
| 4516 | } |
| 4517 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4518 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4519 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4520 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4521 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4522 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4523 | } else if (!strcmp(args[1], "auth")) { |
| 4524 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4525 | 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] | 4526 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4527 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4528 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4529 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4530 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4531 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4532 | } |
| 4533 | } else if (!strcmp(args[1], "scope")) { |
| 4534 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4535 | 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] | 4536 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4537 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4538 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4539 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4540 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4541 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4542 | } |
| 4543 | } else if (!strcmp(args[1], "enable")) { |
| 4544 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4545 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4546 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4547 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4548 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4549 | } else if (!strcmp(args[1], "hide-version")) { |
| 4550 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4551 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4552 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4553 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4554 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4555 | } else if (!strcmp(args[1], "show-legends")) { |
| 4556 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4557 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4558 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4559 | goto out; |
| 4560 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4561 | } else if (!strcmp(args[1], "show-node")) { |
| 4562 | |
| 4563 | if (*args[2]) { |
| 4564 | int i; |
| 4565 | char c; |
| 4566 | |
| 4567 | for (i=0; args[2][i]; i++) { |
| 4568 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4569 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4570 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4571 | break; |
| 4572 | } |
| 4573 | |
| 4574 | if (!i || args[2][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4575 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4576 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4577 | file, linenum, args[0], args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4578 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4579 | goto out; |
| 4580 | } |
| 4581 | } |
| 4582 | |
| 4583 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4584 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4585 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4586 | goto out; |
| 4587 | } |
| 4588 | } else if (!strcmp(args[1], "show-desc")) { |
| 4589 | char *desc = NULL; |
| 4590 | |
| 4591 | if (*args[2]) { |
| 4592 | int i, len=0; |
| 4593 | char *d; |
| 4594 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4595 | for (i = 2; *args[i]; i++) |
| 4596 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4597 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4598 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4599 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4600 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4601 | for (i = 3; *args[i]; i++) |
| 4602 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4603 | } |
| 4604 | |
| 4605 | if (!*args[2] && !global.desc) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4606 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4607 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4608 | else { |
| 4609 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4610 | free(desc); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4611 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4612 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4613 | goto out; |
| 4614 | } |
| 4615 | free(desc); |
| 4616 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4617 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4618 | stats_error_parsing: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4619 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 4620 | 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] | 4621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4622 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4626 | int optnum; |
| 4627 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4628 | if (*(args[1]) == '\0') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4629 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4630 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4631 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4632 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4633 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4634 | |
| 4635 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4636 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4637 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4638 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4639 | file, linenum, cfg_opts[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4641 | goto out; |
| 4642 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4643 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4644 | goto out; |
| 4645 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4646 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4647 | err_code |= ERR_WARN; |
| 4648 | goto out; |
| 4649 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4650 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4651 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4652 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4653 | |
| 4654 | switch (kwm) { |
| 4655 | case KWM_STD: |
| 4656 | curproxy->options |= cfg_opts[optnum].val; |
| 4657 | break; |
| 4658 | case KWM_NO: |
| 4659 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4660 | break; |
| 4661 | case KWM_DEF: /* already cleared */ |
| 4662 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4663 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4664 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4665 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4669 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4670 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4671 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4672 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4673 | file, linenum, cfg_opts2[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4674 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4675 | goto out; |
| 4676 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4677 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4678 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4679 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4680 | err_code |= ERR_WARN; |
| 4681 | goto out; |
| 4682 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4683 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4684 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4685 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4686 | |
| 4687 | switch (kwm) { |
| 4688 | case KWM_STD: |
| 4689 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4690 | break; |
| 4691 | case KWM_NO: |
| 4692 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4693 | break; |
| 4694 | case KWM_DEF: /* already cleared */ |
| 4695 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4696 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4697 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4701 | /* HTTP options override each other. They can be cancelled using |
| 4702 | * "no option xxx" which only switches to default mode if the mode |
| 4703 | * was this one (useful for cancelling options set in defaults |
| 4704 | * sections). |
| 4705 | */ |
| 4706 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4707 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4708 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4709 | if (kwm == KWM_STD) { |
| 4710 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4711 | curproxy->options |= PR_O_HTTP_PCL; |
| 4712 | goto out; |
| 4713 | } |
| 4714 | else if (kwm == KWM_NO) { |
| 4715 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4716 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4717 | goto out; |
| 4718 | } |
| 4719 | } |
| 4720 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4721 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4722 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4723 | if (kwm == KWM_STD) { |
| 4724 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4725 | curproxy->options |= PR_O_HTTP_FCL; |
| 4726 | goto out; |
| 4727 | } |
| 4728 | else if (kwm == KWM_NO) { |
| 4729 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4730 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4731 | goto out; |
| 4732 | } |
| 4733 | } |
| 4734 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4735 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4736 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4737 | if (kwm == KWM_STD) { |
| 4738 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4739 | curproxy->options |= PR_O_HTTP_SCL; |
| 4740 | goto out; |
| 4741 | } |
| 4742 | else if (kwm == KWM_NO) { |
| 4743 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4744 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4745 | goto out; |
| 4746 | } |
| 4747 | } |
| 4748 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4749 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4750 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4751 | if (kwm == KWM_STD) { |
| 4752 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4753 | curproxy->options |= PR_O_HTTP_KAL; |
| 4754 | goto out; |
| 4755 | } |
| 4756 | else if (kwm == KWM_NO) { |
| 4757 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4758 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4759 | goto out; |
| 4760 | } |
| 4761 | } |
| 4762 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4763 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4764 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4765 | if (kwm == KWM_STD) { |
| 4766 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4767 | curproxy->options |= PR_O_HTTP_TUN; |
| 4768 | goto out; |
| 4769 | } |
| 4770 | else if (kwm == KWM_NO) { |
| 4771 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4772 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4773 | goto out; |
| 4774 | } |
| 4775 | } |
| 4776 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4777 | /* Redispatch can take an integer argument that control when the |
| 4778 | * resispatch occurs. All values are relative to the retries option. |
| 4779 | * This can be cancelled using "no option xxx". |
| 4780 | */ |
| 4781 | if (strcmp(args[1], "redispatch") == 0) { |
| 4782 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4783 | err_code |= ERR_WARN; |
| 4784 | goto out; |
| 4785 | } |
| 4786 | |
| 4787 | curproxy->no_options &= ~PR_O_REDISP; |
| 4788 | curproxy->options &= ~PR_O_REDISP; |
| 4789 | |
| 4790 | switch (kwm) { |
| 4791 | case KWM_STD: |
| 4792 | curproxy->options |= PR_O_REDISP; |
| 4793 | curproxy->redispatch_after = -1; |
| 4794 | if(*args[2]) { |
| 4795 | curproxy->redispatch_after = atol(args[2]); |
| 4796 | } |
| 4797 | break; |
| 4798 | case KWM_NO: |
| 4799 | curproxy->no_options |= PR_O_REDISP; |
| 4800 | curproxy->redispatch_after = 0; |
| 4801 | break; |
| 4802 | case KWM_DEF: /* already cleared */ |
| 4803 | break; |
| 4804 | } |
| 4805 | goto out; |
| 4806 | } |
| 4807 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4808 | if (kwm != KWM_STD) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4809 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 4810 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4812 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4813 | } |
| 4814 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4815 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4816 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4817 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4818 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4819 | if (*(args[2]) != '\0') { |
| 4820 | if (!strcmp(args[2], "clf")) { |
| 4821 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4822 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4823 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4824 | 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] | 4825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4826 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4827 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4828 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4829 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4830 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4831 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4832 | char *oldlogformat = "log-format"; |
| 4833 | char *clflogformat = ""; |
| 4834 | |
| 4835 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4836 | oldlogformat = "option httplog"; |
| 4837 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4838 | oldlogformat = "option tcplog"; |
| 4839 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4840 | oldlogformat = "option httplog clf"; |
| 4841 | if (logformat == clf_http_log_format) |
| 4842 | clflogformat = " clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4843 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 4844 | file, linenum, clflogformat, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4845 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4846 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4847 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4848 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4849 | free(curproxy->conf.logformat_string); |
| 4850 | curproxy->conf.logformat_string = logformat; |
| 4851 | |
| 4852 | free(curproxy->conf.lfs_file); |
| 4853 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4854 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4855 | |
| 4856 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4857 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 4858 | file, linenum, curproxy->id); |
| 4859 | err_code |= ERR_WARN; |
| 4860 | } |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4861 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4862 | else if (!strcmp(args[1], "tcplog")) { |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4863 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4864 | char *oldlogformat = "log-format"; |
| 4865 | |
| 4866 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4867 | oldlogformat = "option httplog"; |
| 4868 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4869 | oldlogformat = "option tcplog"; |
| 4870 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4871 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4872 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 4873 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4874 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4875 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4876 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4877 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4878 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4879 | free(curproxy->conf.logformat_string); |
| 4880 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4881 | |
| 4882 | free(curproxy->conf.lfs_file); |
| 4883 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4884 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4885 | |
| 4886 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4887 | goto out; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4888 | |
| 4889 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4890 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 4891 | file, linenum, curproxy->id); |
| 4892 | err_code |= ERR_WARN; |
| 4893 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4894 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4895 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4896 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4897 | 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] | 4898 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4899 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4900 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4901 | goto out; |
| 4902 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4903 | if (curproxy->cap & PR_CAP_FE) |
| 4904 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4905 | if (curproxy->cap & PR_CAP_BE) |
| 4906 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4907 | } |
| 4908 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4909 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4910 | err_code |= ERR_WARN; |
| 4911 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4912 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4913 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4914 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4915 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4916 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4917 | if (!*args[2]) { /* no argument */ |
| 4918 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4919 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4920 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4921 | 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] | 4922 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4923 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4924 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4925 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4926 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4927 | if (*args[4]) |
| 4928 | reqlen += strlen(args[4]); |
| 4929 | else |
| 4930 | reqlen += strlen("HTTP/1.0"); |
| 4931 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4932 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4933 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4934 | "%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] | 4935 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4936 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4937 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4938 | } |
| 4939 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4940 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4941 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4942 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4943 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4944 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4945 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4946 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4947 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4948 | |
| 4949 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4950 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4951 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4952 | else if (!strcmp(args[1], "smtpchk")) { |
| 4953 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4954 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4955 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4956 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4957 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4958 | |
| 4959 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4960 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4961 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4962 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4963 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4964 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4965 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4966 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4967 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4968 | } else { |
| 4969 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4970 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4971 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4972 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4973 | } |
| 4974 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4975 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4976 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4977 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4978 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4979 | /* use PostgreSQL request to check servers' health */ |
| 4980 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4981 | err_code |= ERR_WARN; |
| 4982 | |
| 4983 | free(curproxy->check_req); |
| 4984 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4985 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4986 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4987 | |
| 4988 | if (*(args[2])) { |
| 4989 | int cur_arg = 2; |
| 4990 | |
| 4991 | while (*(args[cur_arg])) { |
| 4992 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4993 | char * packet; |
| 4994 | uint32_t packet_len; |
| 4995 | uint32_t pv; |
| 4996 | |
| 4997 | /* suboption header - needs additional argument for it */ |
| 4998 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4999 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5000 | file, linenum, args[0], args[1], args[cur_arg]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5002 | goto out; |
| 5003 | } |
| 5004 | |
| 5005 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 5006 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 5007 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 5008 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5009 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5010 | |
| 5011 | memcpy(packet + 4, &pv, 4); |
| 5012 | |
| 5013 | /* copy "user" */ |
| 5014 | memcpy(packet + 8, "user", 4); |
| 5015 | |
| 5016 | /* copy username */ |
| 5017 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 5018 | |
| 5019 | free(curproxy->check_req); |
| 5020 | curproxy->check_req = packet; |
| 5021 | curproxy->check_len = packet_len; |
| 5022 | |
| 5023 | packet_len = htonl(packet_len); |
| 5024 | memcpy(packet, &packet_len, 4); |
| 5025 | cur_arg += 2; |
| 5026 | } else { |
| 5027 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5028 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5029 | file, linenum, args[0], args[1]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5031 | goto out; |
| 5032 | } |
| 5033 | } /* end while loop */ |
| 5034 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5035 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 5036 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5039 | else if (!strcmp(args[1], "redis-check")) { |
| 5040 | /* use REDIS PING request to check servers' health */ |
| 5041 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5042 | err_code |= ERR_WARN; |
| 5043 | |
| 5044 | free(curproxy->check_req); |
| 5045 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5046 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5047 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 5048 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5049 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5050 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 5051 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5052 | |
| 5053 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5054 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5055 | } |
| 5056 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5057 | else if (!strcmp(args[1], "mysql-check")) { |
| 5058 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5059 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5060 | err_code |= ERR_WARN; |
| 5061 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5062 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 5063 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5064 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5065 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5066 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5067 | /* 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] | 5068 | * const char mysql40_client_auth_pkt[] = { |
| 5069 | * "\x0e\x00\x00" // packet length |
| 5070 | * "\x01" // packet number |
| 5071 | * "\x00\x00" // client capabilities |
| 5072 | * "\x00\x00\x01" // max packet |
| 5073 | * "haproxy\x00" // username (null terminated string) |
| 5074 | * "\x00" // filler (always 0x00) |
| 5075 | * "\x01\x00\x00" // packet length |
| 5076 | * "\x00" // packet number |
| 5077 | * "\x01" // COM_QUIT command |
| 5078 | * }; |
| 5079 | */ |
| 5080 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5081 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5082 | * const char mysql41_client_auth_pkt[] = { |
| 5083 | * "\x0e\x00\x00\" // packet length |
| 5084 | * "\x01" // packet number |
| 5085 | * "\x00\x00\x00\x00" // client capabilities |
| 5086 | * "\x00\x00\x00\x01" // max packet |
| 5087 | * "\x21" // character set (UTF-8) |
| 5088 | * char[23] // All zeroes |
| 5089 | * "haproxy\x00" // username (null terminated string) |
| 5090 | * "\x00" // filler (always 0x00) |
| 5091 | * "\x01\x00\x00" // packet length |
| 5092 | * "\x00" // packet number |
| 5093 | * "\x01" // COM_QUIT command |
| 5094 | * }; |
| 5095 | */ |
| 5096 | |
| 5097 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5098 | if (*(args[2])) { |
| 5099 | int cur_arg = 2; |
| 5100 | |
| 5101 | while (*(args[cur_arg])) { |
| 5102 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5103 | char *mysqluser; |
| 5104 | int packetlen, reqlen, userlen; |
| 5105 | |
| 5106 | /* suboption header - needs additional argument for it */ |
| 5107 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5108 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5109 | file, linenum, args[0], args[1], args[cur_arg]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5111 | goto out; |
| 5112 | } |
| 5113 | mysqluser = args[cur_arg + 1]; |
| 5114 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5115 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5116 | if (*(args[cur_arg+2])) { |
| 5117 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5118 | packetlen = userlen + 7 + 27; |
| 5119 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5120 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5121 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5122 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5123 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5124 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5125 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5126 | ((unsigned char) packetlen & 0xff), |
| 5127 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5128 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5129 | |
| 5130 | curproxy->check_req[3] = 1; |
| 5131 | curproxy->check_req[5] = 130; |
| 5132 | curproxy->check_req[11] = 1; |
| 5133 | curproxy->check_req[12] = 33; |
| 5134 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5135 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5136 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5137 | cur_arg += 3; |
| 5138 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5139 | 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] | 5140 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5141 | goto out; |
| 5142 | } |
| 5143 | } else { |
| 5144 | packetlen = userlen + 7; |
| 5145 | reqlen = packetlen + 9; |
| 5146 | |
| 5147 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5148 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5149 | curproxy->check_len = reqlen; |
| 5150 | |
| 5151 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5152 | ((unsigned char) packetlen & 0xff), |
| 5153 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5154 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5155 | |
| 5156 | curproxy->check_req[3] = 1; |
| 5157 | curproxy->check_req[5] = 128; |
| 5158 | curproxy->check_req[8] = 1; |
| 5159 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5160 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5161 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5162 | cur_arg += 2; |
| 5163 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5164 | } else { |
| 5165 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5166 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5167 | file, linenum, args[0], args[1]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5169 | goto out; |
| 5170 | } |
| 5171 | } /* end while loop */ |
| 5172 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5173 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5174 | else if (!strcmp(args[1], "ldap-check")) { |
| 5175 | /* use LDAP request to check servers' health */ |
| 5176 | free(curproxy->check_req); |
| 5177 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5178 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5179 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5180 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5181 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5182 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5183 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5184 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5185 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5186 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5187 | else if (!strcmp(args[1], "spop-check")) { |
| 5188 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5189 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5190 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5191 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5192 | goto out; |
| 5193 | } |
| 5194 | if (curproxy->cap & PR_CAP_FE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5195 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5196 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5198 | goto out; |
| 5199 | } |
| 5200 | |
| 5201 | /* use SPOE request to check servers' health */ |
| 5202 | free(curproxy->check_req); |
| 5203 | curproxy->check_req = NULL; |
| 5204 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5205 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5206 | |
Christopher Faulet | 8ef7525 | 2017-02-20 22:56:03 +0100 | [diff] [blame] | 5207 | if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5208 | 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] | 5209 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5210 | goto out; |
| 5211 | } |
| 5212 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5213 | goto out; |
| 5214 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5215 | else if (!strcmp(args[1], "tcp-check")) { |
| 5216 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5217 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5218 | err_code |= ERR_WARN; |
| 5219 | |
| 5220 | free(curproxy->check_req); |
| 5221 | curproxy->check_req = NULL; |
| 5222 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5223 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5224 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5225 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5226 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5227 | else if (!strcmp(args[1], "external-check")) { |
| 5228 | /* excute an external command to check servers' health */ |
| 5229 | free(curproxy->check_req); |
| 5230 | curproxy->check_req = NULL; |
| 5231 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5232 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5233 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5234 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5235 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5236 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5237 | int cur_arg; |
| 5238 | |
| 5239 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5240 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5241 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5242 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5243 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5244 | |
| 5245 | free(curproxy->fwdfor_hdr_name); |
| 5246 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5247 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5248 | |
| 5249 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5250 | cur_arg = 2; |
| 5251 | while (*(args[cur_arg])) { |
| 5252 | if (!strcmp(args[cur_arg], "except")) { |
| 5253 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5254 | 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] | 5255 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5256 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5257 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5258 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5259 | } |
| 5260 | /* flush useless bits */ |
| 5261 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5262 | cur_arg += 2; |
| 5263 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5264 | /* suboption header - needs additional argument for it */ |
| 5265 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5266 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5267 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5269 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5270 | } |
| 5271 | free(curproxy->fwdfor_hdr_name); |
| 5272 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5273 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5274 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5275 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5276 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5277 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5278 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5279 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5280 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 5281 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5283 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5284 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5285 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5286 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5287 | else if (!strcmp(args[1], "originalto")) { |
| 5288 | int cur_arg; |
| 5289 | |
| 5290 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5291 | * set default options (ie: bitfield, header name, etc) |
| 5292 | */ |
| 5293 | |
| 5294 | curproxy->options |= PR_O_ORGTO; |
| 5295 | |
| 5296 | free(curproxy->orgto_hdr_name); |
| 5297 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5298 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5299 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5300 | /* 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] | 5301 | cur_arg = 2; |
| 5302 | while (*(args[cur_arg])) { |
| 5303 | if (!strcmp(args[cur_arg], "except")) { |
| 5304 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5305 | 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] | 5306 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5307 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5309 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5310 | } |
| 5311 | /* flush useless bits */ |
| 5312 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5313 | cur_arg += 2; |
| 5314 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5315 | /* suboption header - needs additional argument for it */ |
| 5316 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5317 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5318 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5320 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5321 | } |
| 5322 | free(curproxy->orgto_hdr_name); |
| 5323 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5324 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5325 | cur_arg += 2; |
| 5326 | } else { |
| 5327 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5328 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5329 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5331 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5332 | } |
| 5333 | } /* end while loop */ |
| 5334 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5335 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5336 | 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] | 5337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5338 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5339 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5340 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5341 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5342 | else if (!strcmp(args[0], "default_backend")) { |
| 5343 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5344 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5345 | |
| 5346 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5347 | 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] | 5348 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5349 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5350 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5351 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5352 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5353 | |
| 5354 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5355 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5356 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5357 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5358 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5359 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5360 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5361 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5362 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n", |
| 5363 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5364 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5365 | /* enable reconnections to dispatch */ |
| 5366 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5367 | |
| 5368 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5370 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5371 | else if (!strcmp(args[0], "http-reuse")) { |
| 5372 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5373 | err_code |= ERR_WARN; |
| 5374 | |
| 5375 | if (strcmp(args[1], "never") == 0) { |
| 5376 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5377 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5378 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5379 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5380 | goto out; |
| 5381 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5382 | else if (strcmp(args[1], "safe") == 0) { |
| 5383 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5384 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5385 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5386 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5387 | goto out; |
| 5388 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5389 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5390 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5391 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5392 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5393 | goto out; |
| 5394 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5395 | else if (strcmp(args[1], "always") == 0) { |
| 5396 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5397 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5398 | curproxy->options |= PR_O_REUSE_ALWS; |
| 5399 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5400 | goto out; |
| 5401 | } |
| 5402 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5403 | 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] | 5404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5405 | goto out; |
| 5406 | } |
| 5407 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5408 | else if (!strcmp(args[0], "http-check")) { |
| 5409 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5410 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5411 | |
| 5412 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5413 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5414 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5415 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5416 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5417 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5418 | else if (strcmp(args[1], "send-state") == 0) { |
| 5419 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5420 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5421 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5422 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5423 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5424 | else if (strcmp(args[1], "expect") == 0) { |
| 5425 | const char *ptr_arg; |
| 5426 | int cur_arg; |
| 5427 | |
| 5428 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5429 | 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] | 5430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5431 | goto out; |
| 5432 | } |
| 5433 | |
| 5434 | cur_arg = 2; |
| 5435 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5436 | while (*(ptr_arg = args[cur_arg])) { |
| 5437 | while (*ptr_arg == '!') { |
| 5438 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5439 | ptr_arg++; |
| 5440 | } |
| 5441 | if (*ptr_arg) |
| 5442 | break; |
| 5443 | cur_arg++; |
| 5444 | } |
| 5445 | /* now ptr_arg points to the beginning of a word past any possible |
| 5446 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5447 | */ |
| 5448 | if (strcmp(ptr_arg, "status") == 0) { |
| 5449 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5450 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5451 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5453 | goto out; |
| 5454 | } |
| 5455 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5456 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5457 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5458 | } |
| 5459 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5460 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5461 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5462 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5463 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5464 | goto out; |
| 5465 | } |
| 5466 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5467 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5468 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5469 | } |
| 5470 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5471 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5472 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5473 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5474 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5475 | goto out; |
| 5476 | } |
| 5477 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5478 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5479 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5480 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5481 | free(curproxy->expect_regex); |
| 5482 | curproxy->expect_regex = NULL; |
| 5483 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5484 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5485 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5486 | error = NULL; |
| 5487 | 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] | 5488 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5489 | 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] | 5490 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5492 | goto out; |
| 5493 | } |
| 5494 | } |
| 5495 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5496 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5497 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5498 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5499 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5500 | goto out; |
| 5501 | } |
| 5502 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5503 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5504 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5505 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5506 | free(curproxy->expect_regex); |
| 5507 | curproxy->expect_regex = NULL; |
| 5508 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5509 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5510 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5511 | error = NULL; |
| 5512 | 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] | 5513 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5514 | 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] | 5515 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5517 | goto out; |
| 5518 | } |
| 5519 | } |
| 5520 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5521 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5522 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5524 | goto out; |
| 5525 | } |
| 5526 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5527 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5528 | 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] | 5529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5530 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5531 | } |
| 5532 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5533 | else if (!strcmp(args[0], "tcp-check")) { |
| 5534 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5535 | err_code |= ERR_WARN; |
| 5536 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5537 | if (strcmp(args[1], "comment") == 0) { |
| 5538 | int cur_arg; |
| 5539 | struct tcpcheck_rule *tcpcheck; |
| 5540 | |
| 5541 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5542 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5543 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5544 | |
| 5545 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5546 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5547 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5549 | goto out; |
| 5550 | } |
| 5551 | |
| 5552 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5553 | |
| 5554 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5555 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5556 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5557 | } |
| 5558 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5559 | const char *ptr_arg; |
| 5560 | int cur_arg; |
| 5561 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5562 | |
| 5563 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5564 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5565 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5566 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5567 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5568 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5569 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5570 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5571 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5572 | ha_alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5573 | file, linenum); |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5575 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5579 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5580 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5581 | |
| 5582 | /* parsing each parameters to fill up the rule */ |
| 5583 | while (*(ptr_arg = args[cur_arg])) { |
| 5584 | /* tcp port */ |
| 5585 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5586 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5587 | (atol(args[cur_arg + 1]) < 1) ){ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5588 | ha_alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5589 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5591 | goto out; |
| 5592 | } |
| 5593 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5594 | cur_arg += 2; |
| 5595 | } |
| 5596 | /* send proxy protocol */ |
| 5597 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5598 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5599 | cur_arg++; |
| 5600 | } |
| 5601 | #ifdef USE_OPENSSL |
| 5602 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5603 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5604 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5605 | cur_arg++; |
| 5606 | } |
| 5607 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5608 | /* comment for this tcpcheck line */ |
| 5609 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5610 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5611 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5612 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5614 | goto out; |
| 5615 | } |
| 5616 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5617 | cur_arg += 2; |
| 5618 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5619 | else { |
| 5620 | #ifdef USE_OPENSSL |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5621 | 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] | 5622 | #else /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5623 | 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] | 5624 | #endif /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5625 | file, linenum, args[0], args[1], args[cur_arg]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
| 5628 | } |
| 5629 | |
| 5630 | } |
| 5631 | |
| 5632 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5633 | } |
| 5634 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5635 | if (! *(args[2]) ) { |
| 5636 | /* SEND string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5637 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5638 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5640 | goto out; |
| 5641 | } else { |
| 5642 | struct tcpcheck_rule *tcpcheck; |
| 5643 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5644 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5645 | |
| 5646 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5647 | tcpcheck->string_len = strlen(args[2]); |
| 5648 | tcpcheck->string = strdup(args[2]); |
| 5649 | tcpcheck->expect_regex = NULL; |
| 5650 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5651 | /* comment for this tcpcheck line */ |
| 5652 | if (strcmp(args[3], "comment") == 0) { |
| 5653 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5654 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5655 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5657 | goto out; |
| 5658 | } |
| 5659 | tcpcheck->comment = strdup(args[4]); |
| 5660 | } |
| 5661 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5662 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5663 | } |
| 5664 | } |
| 5665 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5666 | if (! *(args[2]) ) { |
| 5667 | /* SEND binary string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5668 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5669 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5671 | goto out; |
| 5672 | } else { |
| 5673 | struct tcpcheck_rule *tcpcheck; |
| 5674 | char *err = NULL; |
| 5675 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5676 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5677 | |
| 5678 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5679 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5680 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5681 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5682 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5683 | goto out; |
| 5684 | } |
| 5685 | tcpcheck->expect_regex = NULL; |
| 5686 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5687 | /* comment for this tcpcheck line */ |
| 5688 | if (strcmp(args[3], "comment") == 0) { |
| 5689 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5690 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5691 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5693 | goto out; |
| 5694 | } |
| 5695 | tcpcheck->comment = strdup(args[4]); |
| 5696 | } |
| 5697 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5698 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5699 | } |
| 5700 | } |
| 5701 | else if (strcmp(args[1], "expect") == 0) { |
| 5702 | const char *ptr_arg; |
| 5703 | int cur_arg; |
| 5704 | int inverse = 0; |
| 5705 | |
| 5706 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5707 | 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] | 5708 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5709 | goto out; |
| 5710 | } |
| 5711 | |
| 5712 | cur_arg = 2; |
| 5713 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5714 | while (*(ptr_arg = args[cur_arg])) { |
| 5715 | while (*ptr_arg == '!') { |
| 5716 | inverse = !inverse; |
| 5717 | ptr_arg++; |
| 5718 | } |
| 5719 | if (*ptr_arg) |
| 5720 | break; |
| 5721 | cur_arg++; |
| 5722 | } |
| 5723 | /* now ptr_arg points to the beginning of a word past any possible |
| 5724 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5725 | */ |
| 5726 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5727 | struct tcpcheck_rule *tcpcheck; |
| 5728 | char *err = NULL; |
| 5729 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5730 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5731 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5732 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5733 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5734 | goto out; |
| 5735 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5736 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5737 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5738 | |
| 5739 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5740 | 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] | 5741 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5742 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5743 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5744 | goto out; |
| 5745 | } |
| 5746 | tcpcheck->expect_regex = NULL; |
| 5747 | tcpcheck->inverse = inverse; |
| 5748 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5749 | /* tcpcheck comment */ |
| 5750 | cur_arg += 2; |
| 5751 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5752 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5753 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5754 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5755 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5756 | goto out; |
| 5757 | } |
| 5758 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5759 | } |
| 5760 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5761 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5762 | } |
| 5763 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5764 | struct tcpcheck_rule *tcpcheck; |
| 5765 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5766 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5767 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5768 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5770 | goto out; |
| 5771 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5772 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5773 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5774 | |
| 5775 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5776 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5777 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5778 | tcpcheck->expect_regex = NULL; |
| 5779 | tcpcheck->inverse = inverse; |
| 5780 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5781 | /* tcpcheck comment */ |
| 5782 | cur_arg += 2; |
| 5783 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5784 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5785 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5786 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5787 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5788 | goto out; |
| 5789 | } |
| 5790 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5791 | } |
| 5792 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5793 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5794 | } |
| 5795 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5796 | struct tcpcheck_rule *tcpcheck; |
| 5797 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5798 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5799 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5800 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5801 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5802 | goto out; |
| 5803 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5804 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5805 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5806 | |
| 5807 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5808 | tcpcheck->string_len = 0; |
| 5809 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5810 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5811 | error = NULL; |
| 5812 | 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] | 5813 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5814 | 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] | 5815 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5816 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5817 | goto out; |
| 5818 | } |
| 5819 | tcpcheck->inverse = inverse; |
| 5820 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5821 | /* tcpcheck comment */ |
| 5822 | cur_arg += 2; |
| 5823 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5824 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5825 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5826 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5827 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5828 | goto out; |
| 5829 | } |
| 5830 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5831 | } |
| 5832 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5833 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5834 | } |
| 5835 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5836 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5837 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5839 | goto out; |
| 5840 | } |
| 5841 | } |
| 5842 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5843 | 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] | 5844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5845 | goto out; |
| 5846 | } |
| 5847 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5848 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5849 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5850 | 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] | 5851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5852 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5853 | } |
| 5854 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5855 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5856 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5857 | |
| 5858 | if (strcmp(args[1], "fail") == 0) { |
| 5859 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5860 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5861 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5862 | file, linenum, args[0], args[1]); |
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 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 5867 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 5868 | 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] | 5869 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5870 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5871 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5872 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5873 | } |
| 5874 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5875 | } |
| 5876 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5877 | 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] | 5878 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5879 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5880 | } |
| 5881 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5882 | #ifdef TPROXY |
| 5883 | else if (!strcmp(args[0], "transparent")) { |
| 5884 | /* enable transparent proxy connections */ |
| 5885 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5886 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5887 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5888 | } |
| 5889 | #endif |
| 5890 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5891 | 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] | 5892 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5893 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5894 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5895 | 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] | 5896 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5897 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5898 | } |
| 5899 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5900 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5901 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5902 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5903 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5904 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5905 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5906 | |
| 5907 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5908 | 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] | 5909 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5910 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5911 | } |
| 5912 | curproxy->backlog = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5913 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5914 | goto out; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5915 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5916 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5917 | 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] | 5918 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5919 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5920 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5921 | 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] | 5922 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5923 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5924 | } |
| 5925 | curproxy->fullconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5926 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5927 | goto out; |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5928 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5929 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5930 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5931 | 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] | 5932 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5933 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5934 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5935 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5936 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5937 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5938 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5939 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5940 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5941 | } |
| 5942 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5943 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5944 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5945 | } |
| 5946 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5947 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5948 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5949 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5950 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5951 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5952 | 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] | 5953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5954 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5955 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5956 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5957 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5958 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5959 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5960 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5961 | 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] | 5962 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5963 | goto out; |
| 5964 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5965 | |
| 5966 | proto = protocol_by_family(sk->ss_family); |
| 5967 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5968 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5969 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5971 | goto out; |
| 5972 | } |
| 5973 | |
| 5974 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5975 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5976 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5977 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5978 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5979 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5980 | |
| 5981 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5982 | ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5983 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5984 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5985 | goto out; |
| 5986 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5987 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5988 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5989 | goto out; |
| 5990 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5991 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5992 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5993 | } |
| 5994 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5995 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5996 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5997 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5998 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5999 | 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] | 6000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6001 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 6002 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6003 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6004 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6005 | /** |
| 6006 | * The syntax for hash-type config element is |
| 6007 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 6008 | * |
| 6009 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 6010 | */ |
| 6011 | 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] | 6012 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6013 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 6014 | err_code |= ERR_WARN; |
| 6015 | |
| 6016 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6017 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 6018 | } |
| 6019 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6020 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 6021 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6022 | else if (strcmp(args[1], "avalanche") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6023 | 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] | 6024 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6025 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 6026 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6027 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6028 | 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] | 6029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6030 | goto out; |
| 6031 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6032 | |
| 6033 | /* set the hash function to use */ |
| 6034 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6035 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6036 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6037 | |
| 6038 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 6039 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 6040 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6041 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6042 | /* set the hash function */ |
| 6043 | if (!strcmp(args[2], "sdbm")) { |
| 6044 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 6045 | } |
| 6046 | else if (!strcmp(args[2], "djb2")) { |
| 6047 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6048 | } |
| 6049 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 6050 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6051 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6052 | else if (!strcmp(args[2], "crc32")) { |
| 6053 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 6054 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6055 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6056 | 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] | 6057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6058 | goto out; |
| 6059 | } |
| 6060 | |
| 6061 | /* set the hash modifier */ |
| 6062 | if (!strcmp(args[3], "avalanche")) { |
| 6063 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 6064 | } |
| 6065 | else if (*args[3]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6066 | 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] | 6067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6068 | goto out; |
| 6069 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 6070 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6071 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6072 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 6073 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6074 | 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] | 6075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6076 | goto out; |
| 6077 | } |
| 6078 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 6079 | 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] | 6080 | 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] | 6081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6082 | goto out; |
| 6083 | } |
| 6084 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6085 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 6086 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6087 | 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] | 6088 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6089 | goto out; |
| 6090 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6091 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6092 | 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] | 6093 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6094 | goto out; |
| 6095 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6096 | free(curproxy->conf.uniqueid_format_string); |
| 6097 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6098 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6099 | free(curproxy->conf.uif_file); |
| 6100 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6101 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6102 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6103 | |
| 6104 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6105 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6106 | 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] | 6107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6108 | goto out; |
| 6109 | } |
| 6110 | free(curproxy->header_unique_id); |
| 6111 | curproxy->header_unique_id = strdup(args[1]); |
| 6112 | } |
| 6113 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6114 | else if (strcmp(args[0], "log-format") == 0) { |
| 6115 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6116 | 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] | 6117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6118 | goto out; |
| 6119 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6120 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6121 | 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] | 6122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6123 | goto out; |
| 6124 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6125 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 6126 | char *oldlogformat = "log-format"; |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6127 | |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6128 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 6129 | oldlogformat = "option httplog"; |
| 6130 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 6131 | oldlogformat = "option tcplog"; |
| 6132 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 6133 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6134 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 6135 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6136 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6137 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6138 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6139 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6140 | free(curproxy->conf.logformat_string); |
| 6141 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6142 | |
| 6143 | free(curproxy->conf.lfs_file); |
| 6144 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6145 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6146 | |
| 6147 | /* get a chance to improve log-format error reporting by |
| 6148 | * reporting the correct line-number when possible. |
| 6149 | */ |
| 6150 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6151 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6152 | file, linenum, curproxy->id); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6153 | err_code |= ERR_WARN; |
| 6154 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6155 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6156 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6157 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6158 | 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] | 6159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6160 | goto out; |
| 6161 | } |
| 6162 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6163 | 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] | 6164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6165 | goto out; |
| 6166 | } |
| 6167 | |
| 6168 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6169 | free(curproxy->conf.logformat_sd_string); |
| 6170 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6171 | |
| 6172 | free(curproxy->conf.lfsd_file); |
| 6173 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6174 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6175 | |
| 6176 | /* get a chance to improve log-format-sd error reporting by |
| 6177 | * reporting the correct line-number when possible. |
| 6178 | */ |
| 6179 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6180 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6181 | file, linenum, curproxy->id); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6182 | err_code |= ERR_WARN; |
| 6183 | } |
| 6184 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6185 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6186 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6187 | 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] | 6188 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6189 | goto out; |
| 6190 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6191 | chunk_destroy(&curproxy->log_tag); |
| 6192 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6193 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 6194 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 6195 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 6196 | 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] | 6197 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6198 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6199 | } |
| 6200 | } |
| 6201 | 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] | 6202 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6203 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6204 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6205 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6206 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6207 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6208 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6209 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6210 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6211 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6212 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6213 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6214 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6215 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6216 | |
| 6217 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6218 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6219 | free(curproxy->conn_src.iface_name); |
| 6220 | curproxy->conn_src.iface_name = NULL; |
| 6221 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6222 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6223 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6224 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6225 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6226 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6227 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6228 | goto out; |
| 6229 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6230 | |
| 6231 | proto = protocol_by_family(sk->ss_family); |
| 6232 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6233 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6234 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6235 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6236 | goto out; |
| 6237 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6238 | |
| 6239 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6240 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6241 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6243 | goto out; |
| 6244 | } |
| 6245 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6246 | curproxy->conn_src.source_addr = *sk; |
| 6247 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6248 | |
| 6249 | cur_arg = 2; |
| 6250 | while (*(args[cur_arg])) { |
| 6251 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6252 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6253 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6254 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6255 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6257 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6261 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6262 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6263 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6264 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6265 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6266 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6267 | char *name, *end; |
| 6268 | |
| 6269 | name = args[cur_arg+1] + 7; |
| 6270 | while (isspace(*name)) |
| 6271 | name++; |
| 6272 | |
| 6273 | end = name; |
| 6274 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6275 | end++; |
| 6276 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6277 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6278 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
| 6279 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6280 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6281 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6282 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6283 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6284 | |
| 6285 | /* now look for an occurrence number */ |
| 6286 | while (isspace(*end)) |
| 6287 | end++; |
| 6288 | if (*end == ',') { |
| 6289 | end++; |
| 6290 | name = end; |
| 6291 | if (*end == '-') |
| 6292 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6293 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6294 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6295 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6296 | } |
| 6297 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6298 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6299 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6300 | " occurrences values smaller than %d.\n", |
| 6301 | file, linenum, MAX_HDR_HISTORY); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6303 | goto out; |
| 6304 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6305 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6306 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6307 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6308 | 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] | 6309 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6310 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6311 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6312 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6313 | goto out; |
| 6314 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6315 | |
| 6316 | proto = protocol_by_family(sk->ss_family); |
| 6317 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6318 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6319 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6320 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6321 | goto out; |
| 6322 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6323 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6324 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6325 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6326 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6328 | goto out; |
| 6329 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6330 | curproxy->conn_src.tproxy_addr = *sk; |
| 6331 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6332 | } |
| 6333 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6334 | #else /* no TPROXY support */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6335 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 6336 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6337 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6338 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6339 | #endif |
| 6340 | cur_arg += 2; |
| 6341 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6342 | } |
| 6343 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6344 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6345 | #ifdef SO_BINDTODEVICE |
| 6346 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6347 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6348 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6349 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6350 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6351 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6352 | free(curproxy->conn_src.iface_name); |
| 6353 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6354 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6355 | global.last_checks |= LSTCHK_NETADM; |
| 6356 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6357 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6358 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6360 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6361 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6362 | cur_arg += 2; |
| 6363 | continue; |
| 6364 | } |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6365 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 6366 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6367 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6368 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6369 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6370 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6371 | 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] | 6372 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6373 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6374 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6375 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6376 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6377 | 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] | 6378 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6379 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6380 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6382 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6383 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6384 | |
| 6385 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6386 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6387 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6388 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6389 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6390 | } |
| 6391 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6392 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6393 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6394 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6395 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6396 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6397 | } |
| 6398 | 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] | 6399 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6400 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6401 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6402 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6403 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6404 | } |
| 6405 | 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] | 6406 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6407 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6408 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6409 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6410 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6411 | } |
| 6412 | 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] | 6413 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6414 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6415 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6416 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6417 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6418 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6419 | 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] | 6420 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6421 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6422 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6423 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6424 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6425 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6426 | 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] | 6427 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6428 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6429 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6431 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6432 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6433 | |
| 6434 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6435 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6436 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6437 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6438 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6439 | } |
| 6440 | 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] | 6441 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6442 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6443 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6444 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6445 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6446 | } |
| 6447 | 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] | 6448 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6449 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6450 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6451 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6452 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6453 | } |
| 6454 | 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] | 6455 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6456 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6457 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6458 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6459 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6460 | } |
| 6461 | 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] | 6462 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6463 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6464 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6465 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6466 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6467 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6468 | 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] | 6469 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6470 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6471 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6472 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6473 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6474 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6475 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6476 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6477 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6478 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6479 | 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] | 6480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6481 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6482 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6483 | 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] | 6484 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6485 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6486 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6487 | 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] | 6488 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6489 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6490 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6491 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6492 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6493 | 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] | 6494 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6495 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6497 | goto out; |
| 6498 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6499 | err_code |= warnif_cond_conflicts(cond, |
| 6500 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6501 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6502 | } |
| 6503 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6504 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6505 | file, linenum, args[0], args[2]); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6507 | goto out; |
| 6508 | } |
| 6509 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6510 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6511 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6512 | wl->s = strdup(args[1]); |
| 6513 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6514 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6515 | } |
| 6516 | 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] | 6517 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6518 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6519 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6521 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6522 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6523 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6524 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6525 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6526 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6527 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6528 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6529 | } |
| 6530 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6531 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6532 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6533 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6534 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6535 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6536 | } |
| 6537 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6538 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6539 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6540 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6541 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6542 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6543 | } |
| 6544 | 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] | 6545 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6546 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6547 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6548 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6549 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6550 | } |
| 6551 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6552 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6553 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6554 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6555 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6556 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6557 | } |
| 6558 | 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] | 6559 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6560 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6561 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6562 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6563 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6564 | } |
| 6565 | 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] | 6566 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6567 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6568 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6569 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6570 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6571 | } |
| 6572 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6573 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6574 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6575 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6576 | 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] | 6577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6578 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6579 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6580 | 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] | 6581 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6582 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6583 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6584 | 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] | 6585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6586 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6587 | } |
| 6588 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6589 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6590 | 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] | 6591 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6592 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6593 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6594 | goto out; |
| 6595 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6596 | err_code |= warnif_cond_conflicts(cond, |
| 6597 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6598 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6599 | } |
| 6600 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6601 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6602 | file, linenum, args[0], args[2]); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6604 | goto out; |
| 6605 | } |
| 6606 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6607 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6608 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6609 | wl->s = strdup(args[1]); |
| 6610 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6611 | } |
| 6612 | else if (!strcmp(args[0], "errorloc") || |
| 6613 | !strcmp(args[0], "errorloc302") || |
| 6614 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6615 | int errnum, errlen; |
| 6616 | char *err; |
| 6617 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6618 | 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] | 6619 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6620 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6621 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6622 | 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] | 6623 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6624 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6625 | } |
| 6626 | |
| 6627 | errnum = atol(args[1]); |
| 6628 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6629 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6630 | err = malloc(errlen); |
| 6631 | 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] | 6632 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6633 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6634 | err = malloc(errlen); |
| 6635 | 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] | 6636 | } |
| 6637 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6638 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6639 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6640 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6641 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6642 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6643 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6644 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6645 | |
| 6646 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6647 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6648 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6649 | free(err); |
| 6650 | } |
| 6651 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6652 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6653 | int errnum, errlen, fd; |
| 6654 | char *err; |
| 6655 | struct stat stat; |
| 6656 | |
| 6657 | 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] | 6658 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6659 | |
| 6660 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6661 | 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] | 6662 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6663 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | fd = open(args[2], O_RDONLY); |
| 6667 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6668 | ha_alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6669 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6670 | if (fd >= 0) |
| 6671 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6672 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6673 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6674 | } |
| 6675 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6676 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6677 | errlen = stat.st_size; |
| 6678 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6679 | ha_warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
| 6680 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6681 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6682 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6686 | errnum = read(fd, err, errlen); |
| 6687 | if (errnum != errlen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6688 | ha_alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6689 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6690 | close(fd); |
| 6691 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6693 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6694 | } |
| 6695 | close(fd); |
| 6696 | |
| 6697 | errnum = atol(args[1]); |
| 6698 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6699 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6700 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6701 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6702 | break; |
| 6703 | } |
| 6704 | } |
| 6705 | |
| 6706 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6707 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6708 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6709 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6710 | free(err); |
| 6711 | } |
| 6712 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6713 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6714 | struct cfg_kw_list *kwl; |
| 6715 | int index; |
| 6716 | |
| 6717 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6718 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6719 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6720 | continue; |
| 6721 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6722 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6723 | 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] | 6724 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6725 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6726 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6727 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6728 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6729 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6730 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6731 | err_code |= ERR_WARN; |
| 6732 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6733 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6734 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6735 | } |
| 6736 | } |
| 6737 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6738 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6739 | 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] | 6740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6741 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6742 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6743 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6744 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6745 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6746 | } |
| 6747 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6748 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6749 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6750 | { |
| 6751 | #ifdef CONFIG_HAP_NS |
| 6752 | const char *err; |
| 6753 | const char *item = args[0]; |
| 6754 | |
| 6755 | if (!strcmp(item, "namespace_list")) { |
| 6756 | return 0; |
| 6757 | } |
| 6758 | else if (!strcmp(item, "namespace")) { |
| 6759 | size_t idx = 1; |
| 6760 | const char *current; |
| 6761 | while (*(current = args[idx++])) { |
| 6762 | err = invalid_char(current); |
| 6763 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6764 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6765 | file, linenum, *err, item, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6766 | return ERR_ALERT | ERR_FATAL; |
| 6767 | } |
| 6768 | |
| 6769 | if (netns_store_lookup(current, strlen(current))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6770 | ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6771 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6772 | return ERR_ALERT | ERR_FATAL; |
| 6773 | } |
| 6774 | if (!netns_store_insert(current)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6775 | ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6776 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6777 | return ERR_ALERT | ERR_FATAL; |
| 6778 | } |
| 6779 | } |
| 6780 | } |
| 6781 | |
| 6782 | return 0; |
| 6783 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6784 | ha_alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6785 | file, linenum); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6786 | return ERR_ALERT | ERR_FATAL; |
| 6787 | #endif |
| 6788 | } |
| 6789 | |
| 6790 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6791 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6792 | { |
| 6793 | |
| 6794 | int err_code = 0; |
| 6795 | const char *err; |
| 6796 | |
| 6797 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6798 | struct userlist *newul; |
| 6799 | |
| 6800 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6801 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6802 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6804 | goto out; |
| 6805 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6806 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6807 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6808 | |
| 6809 | err = invalid_char(args[1]); |
| 6810 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6811 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6812 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6814 | goto out; |
| 6815 | } |
| 6816 | |
| 6817 | for (newul = userlist; newul; newul = newul->next) |
| 6818 | if (!strcmp(newul->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6819 | ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6820 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6821 | err_code |= ERR_WARN; |
| 6822 | goto out; |
| 6823 | } |
| 6824 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6825 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6826 | if (!newul) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6827 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6828 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6829 | goto out; |
| 6830 | } |
| 6831 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6832 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6833 | if (!newul->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6834 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6835 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6836 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6837 | goto out; |
| 6838 | } |
| 6839 | |
| 6840 | newul->next = userlist; |
| 6841 | userlist = newul; |
| 6842 | |
| 6843 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6844 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6845 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6846 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6847 | |
| 6848 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6849 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6850 | file, linenum, args[0]); |
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 | |
| 6855 | err = invalid_char(args[1]); |
| 6856 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6857 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6858 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6860 | goto out; |
| 6861 | } |
| 6862 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6863 | if (!userlist) |
| 6864 | goto out; |
| 6865 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6866 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6867 | if (!strcmp(ag->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6868 | ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6869 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6870 | err_code |= ERR_ALERT; |
| 6871 | goto out; |
| 6872 | } |
| 6873 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6874 | ag = calloc(1, sizeof(*ag)); |
| 6875 | if (!ag) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6876 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6877 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6878 | goto out; |
| 6879 | } |
| 6880 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6881 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6882 | if (!ag->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6883 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6884 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6885 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6886 | goto out; |
| 6887 | } |
| 6888 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6889 | cur_arg = 2; |
| 6890 | |
| 6891 | while (*args[cur_arg]) { |
| 6892 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6893 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6894 | cur_arg += 2; |
| 6895 | continue; |
| 6896 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6897 | ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6898 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6899 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6900 | free(ag->groupusers); |
| 6901 | free(ag->name); |
| 6902 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6903 | goto out; |
| 6904 | } |
| 6905 | } |
| 6906 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6907 | ag->next = userlist->groups; |
| 6908 | userlist->groups = ag; |
| 6909 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6910 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6911 | struct auth_users *newuser; |
| 6912 | int cur_arg; |
| 6913 | |
| 6914 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6915 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6916 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6917 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6918 | goto out; |
| 6919 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6920 | if (!userlist) |
| 6921 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6922 | |
| 6923 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6924 | if (!strcmp(newuser->user, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6925 | ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6926 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6927 | err_code |= ERR_ALERT; |
| 6928 | goto out; |
| 6929 | } |
| 6930 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6931 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6932 | if (!newuser) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6933 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6934 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6935 | goto out; |
| 6936 | } |
| 6937 | |
| 6938 | newuser->user = strdup(args[1]); |
| 6939 | |
| 6940 | newuser->next = userlist->users; |
| 6941 | userlist->users = newuser; |
| 6942 | |
| 6943 | cur_arg = 2; |
| 6944 | |
| 6945 | while (*args[cur_arg]) { |
| 6946 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6947 | #ifdef CONFIG_HAP_CRYPT |
| 6948 | if (!crypt("", args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6949 | ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6950 | file, linenum, newuser->user); |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6952 | goto out; |
| 6953 | } |
| 6954 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6955 | ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6956 | file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6957 | err_code |= ERR_ALERT; |
| 6958 | #endif |
| 6959 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6960 | cur_arg += 2; |
| 6961 | continue; |
| 6962 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6963 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6964 | newuser->flags |= AU_O_INSECURE; |
| 6965 | cur_arg += 2; |
| 6966 | continue; |
| 6967 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6968 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6969 | cur_arg += 2; |
| 6970 | continue; |
| 6971 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6972 | ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6973 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6975 | goto out; |
| 6976 | } |
| 6977 | } |
| 6978 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6979 | 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] | 6980 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6981 | } |
| 6982 | |
| 6983 | out: |
| 6984 | return err_code; |
| 6985 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6986 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6987 | int |
| 6988 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6989 | { |
| 6990 | char *beg, *end, *scope = NULL; |
| 6991 | int err_code = 0; |
| 6992 | const char *err; |
| 6993 | |
| 6994 | beg = line + 1; |
| 6995 | end = strchr(beg, ']'); |
| 6996 | |
| 6997 | /* Detect end of scope declaration */ |
| 6998 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6999 | ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 7000 | file, linenum); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7002 | goto out; |
| 7003 | } |
| 7004 | |
| 7005 | /* Get scope name and check its validity */ |
| 7006 | scope = my_strndup(beg, end-beg); |
| 7007 | err = invalid_char(scope); |
| 7008 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7009 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 7010 | file, linenum, *err); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7011 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7012 | goto out; |
| 7013 | } |
| 7014 | |
| 7015 | /* Be sure to have a scope declaration alone on its line */ |
| 7016 | line = end+1; |
| 7017 | while (isspace((unsigned char)*line)) |
| 7018 | line++; |
| 7019 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7020 | ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 7021 | file, linenum, *line); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7022 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7023 | goto out; |
| 7024 | } |
| 7025 | |
| 7026 | /* We have a valid scope declaration, save it */ |
| 7027 | free(cfg_scope); |
| 7028 | cfg_scope = scope; |
| 7029 | scope = NULL; |
| 7030 | |
| 7031 | out: |
| 7032 | free(scope); |
| 7033 | return err_code; |
| 7034 | } |
| 7035 | |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 7036 | int |
| 7037 | cfg_parse_track_sc_num(unsigned int *track_sc_num, |
| 7038 | const char *arg, const char *end, char **errmsg) |
| 7039 | { |
| 7040 | const char *p; |
| 7041 | unsigned int num; |
| 7042 | |
| 7043 | p = arg; |
| 7044 | num = read_uint64(&arg, end); |
| 7045 | |
| 7046 | if (arg != end) { |
| 7047 | memprintf(errmsg, "Wrong track-sc number '%s'", p); |
| 7048 | return -1; |
| 7049 | } |
| 7050 | |
| 7051 | if (num >= MAX_SESS_STKCTR) { |
| 7052 | memprintf(errmsg, "%u track-sc number exceeding " |
| 7053 | "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1); |
| 7054 | return -1; |
| 7055 | } |
| 7056 | |
| 7057 | *track_sc_num = num; |
| 7058 | return 0; |
| 7059 | } |
| 7060 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7061 | /* |
| 7062 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7063 | * Returns the error code, 0 if OK, or any combination of : |
| 7064 | * - ERR_ABORT: must abort ASAP |
| 7065 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7066 | * - ERR_WARN: a warning has been emitted |
| 7067 | * - ERR_ALERT: an alert has been emitted |
| 7068 | * Only the two first ones can stop processing, the two others are just |
| 7069 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7070 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7071 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7072 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7073 | char *thisline; |
| 7074 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7075 | FILE *f; |
| 7076 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7077 | int err_code = 0; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7078 | struct cfg_section *cs = NULL, *pcs = NULL; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7079 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7080 | int readbytes = 0; |
| 7081 | |
| 7082 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7083 | ha_alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7084 | return -1; |
| 7085 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7086 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7087 | if ((f=fopen(file,"r")) == NULL) { |
| 7088 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7089 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7090 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7091 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7092 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7093 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7094 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7095 | char *end; |
| 7096 | char *args[MAX_LINE_ARGS + 1]; |
| 7097 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7098 | int dquote = 0; /* double quote */ |
| 7099 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7100 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7101 | linenum++; |
| 7102 | |
| 7103 | end = line + strlen(line); |
| 7104 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7105 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7106 | /* Check if we reached the limit and the last char is not \n. |
| 7107 | * Watch out for the last line without the terminating '\n'! |
| 7108 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7109 | char *newline; |
| 7110 | int newlinesize = linesize * 2; |
| 7111 | |
| 7112 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7113 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7114 | ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7115 | file, linenum); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7116 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7117 | continue; |
| 7118 | } |
| 7119 | |
| 7120 | readbytes = linesize - 1; |
| 7121 | linesize = newlinesize; |
| 7122 | thisline = newline; |
| 7123 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7124 | } |
| 7125 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7126 | readbytes = 0; |
| 7127 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7128 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7129 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7130 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7131 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7132 | |
| 7133 | if (*line == '[') {/* This is the begining if a scope */ |
| 7134 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7135 | goto next_line; |
| 7136 | } |
| 7137 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7138 | arg = 0; |
| 7139 | args[arg] = line; |
| 7140 | |
| 7141 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7142 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7143 | if (dquote) |
| 7144 | dquote = 0; |
| 7145 | else |
| 7146 | dquote = 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 == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7151 | if (squote) |
| 7152 | squote = 0; |
| 7153 | else |
| 7154 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7155 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7156 | end--; |
| 7157 | } |
| 7158 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7159 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7160 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7161 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7162 | int skip = 0; |
| 7163 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7164 | *line = line[1]; |
| 7165 | skip = 1; |
| 7166 | } |
| 7167 | else if (line[1] == 'r') { |
| 7168 | *line = '\r'; |
| 7169 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7170 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7171 | else if (line[1] == 'n') { |
| 7172 | *line = '\n'; |
| 7173 | skip = 1; |
| 7174 | } |
| 7175 | else if (line[1] == 't') { |
| 7176 | *line = '\t'; |
| 7177 | skip = 1; |
| 7178 | } |
| 7179 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7180 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7181 | unsigned char hex1, hex2; |
| 7182 | hex1 = toupper(line[2]) - '0'; |
| 7183 | hex2 = toupper(line[3]) - '0'; |
| 7184 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7185 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7186 | *line = (hex1<<4) + hex2; |
| 7187 | skip = 3; |
| 7188 | } |
| 7189 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7190 | 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] | 7191 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7192 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7193 | } else if (line[1] == '"') { |
| 7194 | *line = '"'; |
| 7195 | skip = 1; |
| 7196 | } else if (line[1] == '\'') { |
| 7197 | *line = '\''; |
| 7198 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7199 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7200 | *line = '$'; |
| 7201 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7202 | } |
| 7203 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7204 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7205 | end -= skip; |
| 7206 | } |
| 7207 | line++; |
| 7208 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7209 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7210 | /* end of string, end of loop */ |
| 7211 | *line = 0; |
| 7212 | break; |
| 7213 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7214 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7215 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7216 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7217 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7218 | line++; |
| 7219 | args[++arg] = line; |
| 7220 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7221 | else if (dquote && *line == '$') { |
| 7222 | /* environment variables are evaluated inside double quotes */ |
| 7223 | char *var_beg; |
| 7224 | char *var_end; |
| 7225 | char save_char; |
| 7226 | char *value; |
| 7227 | int val_len; |
| 7228 | int newlinesize; |
| 7229 | int braces = 0; |
| 7230 | |
| 7231 | var_beg = line + 1; |
| 7232 | var_end = var_beg; |
| 7233 | |
| 7234 | if (*var_beg == '{') { |
| 7235 | var_beg++; |
| 7236 | var_end++; |
| 7237 | braces = 1; |
| 7238 | } |
| 7239 | |
| 7240 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7241 | 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] | 7242 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7243 | goto next_line; /* skip current line */ |
| 7244 | } |
| 7245 | |
| 7246 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7247 | var_end++; |
| 7248 | |
| 7249 | save_char = *var_end; |
| 7250 | *var_end = '\0'; |
| 7251 | value = getenv(var_beg); |
| 7252 | *var_end = save_char; |
| 7253 | val_len = value ? strlen(value) : 0; |
| 7254 | |
| 7255 | if (braces) { |
| 7256 | if (*var_end == '}') { |
| 7257 | var_end++; |
| 7258 | braces = 0; |
| 7259 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7260 | ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7262 | goto next_line; /* skip current line */ |
| 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7267 | |
| 7268 | /* if not enough space in thisline */ |
| 7269 | if (newlinesize > linesize) { |
| 7270 | char *newline; |
| 7271 | |
| 7272 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7273 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7274 | 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] | 7275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7276 | goto next_line; /* slip current line */ |
| 7277 | } |
| 7278 | /* recompute pointers if realloc returns a new pointer */ |
| 7279 | if (newline != thisline) { |
| 7280 | int i; |
| 7281 | int diff; |
| 7282 | |
| 7283 | for (i = 0; i <= arg; i++) { |
| 7284 | diff = args[i] - thisline; |
| 7285 | args[i] = newline + diff; |
| 7286 | } |
| 7287 | |
| 7288 | diff = var_end - thisline; |
| 7289 | var_end = newline + diff; |
| 7290 | diff = end - thisline; |
| 7291 | end = newline + diff; |
| 7292 | diff = line - thisline; |
| 7293 | line = newline + diff; |
| 7294 | thisline = newline; |
| 7295 | } |
| 7296 | linesize = newlinesize; |
| 7297 | } |
| 7298 | |
| 7299 | /* insert value inside the line */ |
| 7300 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7301 | memcpy(line, value, val_len); |
| 7302 | end += val_len - (var_end - line); |
| 7303 | line += val_len; |
| 7304 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7305 | else { |
| 7306 | line++; |
| 7307 | } |
| 7308 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7309 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7310 | if (dquote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7311 | ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7313 | } |
| 7314 | |
| 7315 | if (squote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7316 | ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7318 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7319 | |
| 7320 | /* empty line */ |
| 7321 | if (!**args) |
| 7322 | continue; |
| 7323 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7324 | if (*line) { |
| 7325 | /* we had to stop due to too many args. |
| 7326 | * Let's terminate the string, print the offending part then cut the |
| 7327 | * last arg. |
| 7328 | */ |
| 7329 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7330 | line++; |
| 7331 | *line = '\0'; |
| 7332 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7333 | ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
| 7334 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7336 | args[arg] = line; |
| 7337 | } |
| 7338 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7339 | /* zero out remaining args and ensure that at least one entry |
| 7340 | * is zeroed out. |
| 7341 | */ |
| 7342 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7343 | args[arg] = line; |
| 7344 | } |
| 7345 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7346 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7347 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7348 | char *tmp; |
| 7349 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7350 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7351 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7352 | for (arg=0; *args[arg+1]; arg++) |
| 7353 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7354 | *tmp = '\0'; // fix the next arg to \0 |
| 7355 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7356 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7357 | else if (!strcmp(args[0], "default")) { |
| 7358 | kwm = KWM_DEF; |
| 7359 | for (arg=0; *args[arg+1]; arg++) |
| 7360 | args[arg] = args[arg+1]; // shift args after inversion |
| 7361 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7362 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7363 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7364 | strcmp(args[0], "log") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7365 | 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] | 7366 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7367 | } |
| 7368 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7369 | /* detect section start */ |
| 7370 | list_for_each_entry(ics, §ions, list) { |
| 7371 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7372 | cursection = ics->section_name; |
| 7373 | cs = ics; |
| 7374 | break; |
| 7375 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7376 | } |
| 7377 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7378 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7379 | 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] | 7380 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7381 | } else { |
| 7382 | /* else it's a section keyword */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7383 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7384 | if (pcs != cs && pcs && pcs->post_section_parser) { |
| 7385 | err_code |= pcs->post_section_parser(); |
| 7386 | if (err_code & ERR_ABORT) |
| 7387 | goto err; |
| 7388 | } |
| 7389 | |
| 7390 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7391 | if (err_code & ERR_ABORT) |
| 7392 | goto err; |
| 7393 | } |
| 7394 | pcs = cs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7395 | } |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7396 | |
| 7397 | if (pcs == cs && pcs && pcs->post_section_parser) |
| 7398 | err_code |= pcs->post_section_parser(); |
| 7399 | |
| 7400 | err: |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7401 | free(cfg_scope); |
| 7402 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7403 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7404 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7405 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7406 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7407 | } |
| 7408 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7409 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7410 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7411 | * bound to all of its processes. After that, if the target is a "listen" |
| 7412 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7413 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7414 | * checked first to ensure that <to> is already bound to all processes of |
| 7415 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7416 | * path to the destination. |
| 7417 | * |
| 7418 | * It is possible to set <to> to NULL for the first call so that the function |
| 7419 | * takes care of visiting the initial frontend in <from>. |
| 7420 | * |
| 7421 | * It is important to note that the function relies on the fact that all names |
| 7422 | * have already been resolved. |
| 7423 | */ |
| 7424 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7425 | { |
| 7426 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7427 | |
| 7428 | if (to) { |
| 7429 | /* check whether we need to go down */ |
| 7430 | if (from->bind_proc && |
| 7431 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7432 | return; |
| 7433 | |
| 7434 | if (!from->bind_proc && !to->bind_proc) |
| 7435 | return; |
| 7436 | |
| 7437 | to->bind_proc = from->bind_proc ? |
| 7438 | (to->bind_proc | from->bind_proc) : 0; |
| 7439 | |
| 7440 | /* now propagate down */ |
| 7441 | from = to; |
| 7442 | } |
| 7443 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7444 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7445 | return; |
| 7446 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7447 | if (from->state == PR_STSTOPPED) |
| 7448 | return; |
| 7449 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7450 | /* default_backend */ |
| 7451 | if (from->defbe.be) |
| 7452 | propagate_processes(from, from->defbe.be); |
| 7453 | |
| 7454 | /* use_backend */ |
| 7455 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7456 | if (rule->dynamic) |
| 7457 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7458 | to = rule->be.backend; |
| 7459 | propagate_processes(from, to); |
| 7460 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7461 | } |
| 7462 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7463 | /* |
| 7464 | * Returns the error code, 0 if OK, or any combination of : |
| 7465 | * - ERR_ABORT: must abort ASAP |
| 7466 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7467 | * - ERR_WARN: a warning has been emitted |
| 7468 | * - ERR_ALERT: an alert has been emitted |
| 7469 | * Only the two first ones can stop processing, the two others are just |
| 7470 | * indicators. |
| 7471 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7472 | int check_config_validity() |
| 7473 | { |
| 7474 | int cfgerr = 0; |
| 7475 | struct proxy *curproxy = NULL; |
| 7476 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7477 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7478 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7479 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7480 | char *err; |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 7481 | struct cfg_postparser *postparser; |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 7482 | struct dns_resolvers *curr_resolvers = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7483 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7484 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7485 | /* |
| 7486 | * Now, check for the integrity of all that we have collected. |
| 7487 | */ |
| 7488 | |
| 7489 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7490 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7491 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7492 | if (!global.tune.max_http_hdr) |
| 7493 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7494 | |
| 7495 | if (!global.tune.cookie_len) |
| 7496 | global.tune.cookie_len = CAPTURE_LEN; |
| 7497 | |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 7498 | if (!global.tune.requri_len) |
| 7499 | global.tune.requri_len = REQURI_LEN; |
| 7500 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7501 | 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] | 7502 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7503 | 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] | 7504 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7505 | /* Post initialisation of the users and groups lists. */ |
| 7506 | err_code = userlist_postinit(); |
| 7507 | if (err_code != ERR_NONE) |
| 7508 | goto out; |
| 7509 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7510 | /* first, we will invert the proxy list order */ |
| 7511 | curproxy = NULL; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7512 | while (proxies_list) { |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7513 | struct proxy *next; |
| 7514 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7515 | next = proxies_list->next; |
| 7516 | proxies_list->next = curproxy; |
| 7517 | curproxy = proxies_list; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7518 | if (!next) |
| 7519 | break; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7520 | proxies_list = next; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7521 | } |
| 7522 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7523 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7524 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7525 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7526 | struct sticking_rule *mrule; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7527 | struct act_rule *arule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7528 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7529 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7530 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7531 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7532 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7533 | /* proxy ID not set, use automatic numbering with first |
| 7534 | * spare entry starting with next_pxid. |
| 7535 | */ |
| 7536 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7537 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7538 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7539 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7540 | next_pxid++; |
| 7541 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7542 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7543 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7544 | /* ensure we don't keep listeners uselessly bound */ |
| 7545 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7546 | free((void *)curproxy->table.peers.name); |
| 7547 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7548 | continue; |
| 7549 | } |
| 7550 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7551 | /* Check multi-process mode compatibility for the current proxy */ |
| 7552 | |
| 7553 | if (curproxy->bind_proc) { |
| 7554 | /* an explicit bind-process was specified, let's check how many |
| 7555 | * processes remain. |
| 7556 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7557 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7558 | |
| 7559 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7560 | if (!curproxy->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7561 | 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] | 7562 | curproxy->bind_proc = 1; |
| 7563 | } |
| 7564 | else if (!curproxy->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7565 | 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] | 7566 | curproxy->bind_proc = 0; |
| 7567 | } |
| 7568 | } |
| 7569 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7570 | /* check and reduce the bind-proc of each listener */ |
| 7571 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7572 | unsigned long mask; |
| 7573 | |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7574 | /* HTTP frontends with "h2" as ALPN/NPN will work in |
| 7575 | * HTTP/2 and absolutely require buffers 16kB or larger. |
| 7576 | */ |
| 7577 | #ifdef USE_OPENSSL |
| 7578 | if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) { |
| 7579 | #ifdef OPENSSL_NPN_NEGOTIATED |
| 7580 | /* check NPN */ |
| 7581 | 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] | 7582 | 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", |
| 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 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 7588 | /* check ALPN */ |
| 7589 | 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] | 7590 | 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", |
| 7591 | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7592 | cfgerr++; |
| 7593 | } |
| 7594 | #endif |
| 7595 | } /* HTTP && bufsize < 16384 */ |
| 7596 | #endif |
| 7597 | |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7598 | /* detect and address thread affinity inconsistencies */ |
| 7599 | nbproc = 0; |
| 7600 | if (bind_conf->bind_proc) |
| 7601 | nbproc = my_ffsl(bind_conf->bind_proc); |
| 7602 | |
| 7603 | mask = bind_conf->bind_thread[nbproc - 1]; |
Willy Tarreau | 0c026f4 | 2018-08-01 19:12:20 +0200 | [diff] [blame] | 7604 | if (mask && !(mask & all_threads_mask)) { |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7605 | unsigned long new_mask = 0; |
| 7606 | |
| 7607 | while (mask) { |
Willy Tarreau | 0c026f4 | 2018-08-01 19:12:20 +0200 | [diff] [blame] | 7608 | new_mask |= mask & all_threads_mask; |
Willy Tarreau | c477b6f | 2018-07-27 18:07:41 +0200 | [diff] [blame] | 7609 | mask >>= global.nbthread; |
| 7610 | } |
| 7611 | |
| 7612 | for (nbproc = 0; nbproc < LONGBITS; nbproc++) { |
| 7613 | if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc))) |
| 7614 | bind_conf->bind_thread[nbproc] = new_mask; |
| 7615 | } |
| 7616 | 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", |
| 7617 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask); |
| 7618 | } |
| 7619 | |
| 7620 | /* detect process and nbproc affinity inconsistencies */ |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7621 | if (!bind_conf->bind_proc) |
| 7622 | continue; |
| 7623 | |
| 7624 | mask = nbits(global.nbproc); |
| 7625 | if (curproxy->bind_proc) |
| 7626 | mask &= curproxy->bind_proc; |
| 7627 | /* mask cannot be null here thanks to the previous checks */ |
| 7628 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7629 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7630 | bind_conf->bind_proc &= mask; |
| 7631 | |
| 7632 | if (!bind_conf->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7633 | 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", |
| 7634 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7635 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7636 | } |
| 7637 | else if (!bind_conf->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7638 | 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", |
| 7639 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7640 | bind_conf->bind_proc = 0; |
| 7641 | } |
| 7642 | } |
| 7643 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7644 | switch (curproxy->mode) { |
| 7645 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7646 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7647 | if (!(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7648 | ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7649 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7650 | cfgerr++; |
| 7651 | } |
| 7652 | |
| 7653 | if (curproxy->srv != NULL) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7654 | ha_warning("config : servers will be ignored for %s '%s'.\n", |
| 7655 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7656 | break; |
| 7657 | |
| 7658 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7659 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7660 | break; |
| 7661 | |
| 7662 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7663 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7664 | break; |
| 7665 | } |
| 7666 | |
Willy Tarreau | 58aa5cc | 2018-02-08 09:55:09 +0100 | [diff] [blame] | 7667 | 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] | 7668 | ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7669 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7670 | err_code |= ERR_WARN; |
| 7671 | } |
| 7672 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7673 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7674 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7675 | if (curproxy->options & PR_O_TRANSP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7676 | ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7677 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7678 | cfgerr++; |
| 7679 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7680 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7681 | else if (curproxy->srv == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7682 | ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7683 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7684 | cfgerr++; |
| 7685 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7686 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7687 | else if (curproxy->options & PR_O_DISPATCH) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7688 | ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7689 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7690 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7691 | } |
| 7692 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7693 | 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] | 7694 | /* If no LB algo is set in a backend, and we're not in |
| 7695 | * transparent mode, dispatch mode nor proxy mode, we |
| 7696 | * want to use balance roundrobin by default. |
| 7697 | */ |
| 7698 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7699 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7700 | } |
| 7701 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7702 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7703 | if (curproxy->options & PR_O_DISPATCH) |
| 7704 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7705 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7706 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7707 | else if (curproxy->options & PR_O_TRANSP) |
| 7708 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7709 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7710 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7711 | if (curproxy->options & PR_O_DISABLE404) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7712 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7713 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7714 | err_code |= ERR_WARN; |
| 7715 | curproxy->options &= ~PR_O_DISABLE404; |
| 7716 | } |
| 7717 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7718 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7719 | "send-state", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7720 | err_code |= ERR_WARN; |
| 7721 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7722 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7723 | } |
| 7724 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7725 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7726 | if (!global.external_check) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7727 | ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7728 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7729 | cfgerr++; |
| 7730 | } |
| 7731 | if (!curproxy->check_command) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7732 | ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7733 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7734 | cfgerr++; |
| 7735 | } |
| 7736 | } |
| 7737 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7738 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7739 | 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] | 7740 | ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of " |
| 7741 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7742 | "'email-alert myhostname', or 'email-alert to' " |
| 7743 | "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' " |
| 7744 | "to be present).\n", |
| 7745 | proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7746 | err_code |= ERR_WARN; |
| 7747 | free_email_alert(curproxy); |
| 7748 | } |
| 7749 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7750 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7751 | } |
| 7752 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7753 | if (curproxy->check_command) { |
| 7754 | int clear = 0; |
| 7755 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7756 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7757 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7758 | err_code |= ERR_WARN; |
| 7759 | clear = 1; |
| 7760 | } |
| 7761 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7762 | ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n", |
| 7763 | curproxy->id, "external-check command"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7764 | cfgerr++; |
| 7765 | } |
| 7766 | if (clear) { |
| 7767 | free(curproxy->check_command); |
| 7768 | curproxy->check_command = NULL; |
| 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | if (curproxy->check_path) { |
| 7773 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7774 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7775 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7776 | err_code |= ERR_WARN; |
| 7777 | free(curproxy->check_path); |
| 7778 | curproxy->check_path = NULL; |
| 7779 | } |
| 7780 | } |
| 7781 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7782 | /* if a default backend was specified, let's find it */ |
| 7783 | if (curproxy->defbe.name) { |
| 7784 | struct proxy *target; |
| 7785 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7786 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7787 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7788 | ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7789 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7790 | cfgerr++; |
| 7791 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7792 | ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7793 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7794 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7795 | } else if (target->mode != curproxy->mode && |
| 7796 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7797 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7798 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7799 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7800 | curproxy->conf.file, curproxy->conf.line, |
| 7801 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7802 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7803 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7804 | } else { |
| 7805 | free(curproxy->defbe.name); |
| 7806 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7807 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7808 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7809 | /* Emit a warning if this proxy also has some servers */ |
| 7810 | if (curproxy->srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7811 | ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7812 | curproxy->id); |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7813 | err_code |= ERR_WARN; |
| 7814 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7815 | } |
| 7816 | } |
| 7817 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7818 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7819 | /* Case of listen without default backend |
| 7820 | * The curproxy will be its own default backend |
| 7821 | * so we update tot_fe_maxconn for a further |
| 7822 | * fullconn's computation */ |
| 7823 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7824 | } |
| 7825 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7826 | /* find the target proxy for 'use_backend' rules */ |
| 7827 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7828 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7829 | struct logformat_node *node; |
| 7830 | char *pxname; |
| 7831 | |
| 7832 | /* Try to parse the string as a log format expression. If the result |
| 7833 | * of the parsing is only one entry containing a simple string, then |
| 7834 | * it's a standard string corresponding to a static rule, thus the |
| 7835 | * parsing is cancelled and be.name is restored to be resolved. |
| 7836 | */ |
| 7837 | pxname = rule->be.name; |
| 7838 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7839 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7840 | curproxy->conf.args.file = rule->file; |
| 7841 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7842 | err = NULL; |
| 7843 | 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] | 7844 | ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7845 | rule->file, rule->line, pxname, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7846 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7847 | cfgerr++; |
| 7848 | continue; |
| 7849 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7850 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7851 | |
| 7852 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7853 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7854 | rule->dynamic = 1; |
| 7855 | free(pxname); |
| 7856 | continue; |
| 7857 | } |
| 7858 | /* simple string: free the expression and fall back to static rule */ |
| 7859 | free(node->arg); |
| 7860 | free(node); |
| 7861 | } |
| 7862 | |
| 7863 | rule->dynamic = 0; |
| 7864 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7865 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7866 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7867 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7868 | ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7869 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7870 | cfgerr++; |
| 7871 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7872 | ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7873 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7874 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7875 | } else if (target->mode != curproxy->mode && |
| 7876 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7877 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7878 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7879 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7880 | curproxy->conf.file, curproxy->conf.line, |
| 7881 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7882 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7883 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7884 | } else { |
| 7885 | free((void *)rule->be.name); |
| 7886 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7887 | /* For each target of switching rules, we update |
| 7888 | * their tot_fe_maxconn, except if a previous rule point |
| 7889 | * on the same backend or on the default backend */ |
| 7890 | if (rule->be.backend != curproxy->defbe.be) { |
| 7891 | struct switching_rule *swrule; |
| 7892 | |
| 7893 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7894 | if (rule == swrule) { |
| 7895 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7896 | break; |
| 7897 | } |
| 7898 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7899 | /* there is multiple ref of this backend */ |
| 7900 | break; |
| 7901 | } |
| 7902 | } |
| 7903 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7904 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7905 | } |
| 7906 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7907 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7908 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7909 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7910 | |
| 7911 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7912 | ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7913 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7914 | cfgerr++; |
| 7915 | continue; |
| 7916 | } |
| 7917 | free((void *)srule->srv.name); |
| 7918 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7919 | } |
| 7920 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7921 | /* find the target table for 'stick' rules */ |
| 7922 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7923 | struct proxy *target; |
| 7924 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7925 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7926 | if (mrule->flags & STK_IS_STORE) |
| 7927 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7928 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7929 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7930 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7931 | else |
| 7932 | target = curproxy; |
| 7933 | |
| 7934 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7935 | ha_alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7936 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7937 | cfgerr++; |
| 7938 | } |
| 7939 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7940 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7941 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7942 | cfgerr++; |
| 7943 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7944 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7945 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7946 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7947 | cfgerr++; |
| 7948 | } |
| 7949 | else { |
| 7950 | free((void *)mrule->table.name); |
| 7951 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7952 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7953 | } |
| 7954 | } |
| 7955 | |
| 7956 | /* find the target table for 'store response' rules */ |
| 7957 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7958 | struct proxy *target; |
| 7959 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7960 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7961 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7962 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7963 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7964 | else |
| 7965 | target = curproxy; |
| 7966 | |
| 7967 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7968 | ha_alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7969 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7970 | cfgerr++; |
| 7971 | } |
| 7972 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7973 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7974 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7975 | cfgerr++; |
| 7976 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7977 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7978 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7979 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7980 | cfgerr++; |
| 7981 | } |
| 7982 | else { |
| 7983 | free((void *)mrule->table.name); |
| 7984 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7985 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7989 | /* check validity for 'tcp-request' layer 4 rules */ |
| 7990 | list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) { |
| 7991 | err = NULL; |
| 7992 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7993 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7994 | free(err); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7995 | cfgerr++; |
| 7996 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7997 | } |
| 7998 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7999 | /* check validity for 'tcp-request' layer 5 rules */ |
| 8000 | list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) { |
| 8001 | err = NULL; |
| 8002 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8003 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8004 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8005 | cfgerr++; |
| 8006 | } |
| 8007 | } |
| 8008 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8009 | /* check validity for 'tcp-request' layer 6 rules */ |
| 8010 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8011 | err = NULL; |
| 8012 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8013 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8014 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 8015 | cfgerr++; |
| 8016 | } |
| 8017 | } |
| 8018 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8019 | /* check validity for 'http-request' layer 7 rules */ |
| 8020 | list_for_each_entry(arule, &curproxy->http_req_rules, list) { |
| 8021 | err = NULL; |
| 8022 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8023 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8024 | free(err); |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8025 | cfgerr++; |
| 8026 | } |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 8027 | } |
| 8028 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8029 | /* check validity for 'http-response' layer 7 rules */ |
| 8030 | list_for_each_entry(arule, &curproxy->http_res_rules, list) { |
| 8031 | err = NULL; |
| 8032 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8033 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8034 | free(err); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8035 | cfgerr++; |
| 8036 | } |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8037 | } |
| 8038 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8039 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8040 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8041 | /* insert block_rules into http_req_rules at the beginning */ |
| 8042 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8043 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8044 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8045 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8046 | LIST_INIT(&curproxy->block_rules); |
| 8047 | } |
| 8048 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8049 | if (curproxy->table.peers.name) { |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8050 | struct peers *curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8051 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8052 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8053 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8054 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8055 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8056 | break; |
| 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | if (!curpeers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8061 | ha_alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8062 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8063 | free((void *)curproxy->table.peers.name); |
| 8064 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8065 | cfgerr++; |
| 8066 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8067 | else if (curpeers->state == PR_STSTOPPED) { |
| 8068 | /* silently disable this peers section */ |
| 8069 | curproxy->table.peers.p = NULL; |
| 8070 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8071 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8072 | ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8073 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8074 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8075 | cfgerr++; |
| 8076 | } |
| 8077 | } |
| 8078 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8079 | |
| 8080 | if (curproxy->email_alert.mailers.name) { |
| 8081 | struct mailers *curmailers = mailers; |
| 8082 | |
| 8083 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8084 | if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name)) |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8085 | break; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8086 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8087 | if (!curmailers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8088 | ha_alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8089 | curproxy->id, curproxy->email_alert.mailers.name); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8090 | free_email_alert(curproxy); |
| 8091 | cfgerr++; |
| 8092 | } |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8093 | else { |
| 8094 | err = NULL; |
| 8095 | if (init_email_alert(curmailers, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8096 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8097 | free(err); |
| 8098 | cfgerr++; |
| 8099 | } |
| 8100 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8101 | } |
| 8102 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8103 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8104 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8105 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8106 | ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8107 | "proxy", curproxy->id); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8108 | cfgerr++; |
| 8109 | goto out_uri_auth_compat; |
| 8110 | } |
| 8111 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8112 | 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] | 8113 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8114 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8115 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8116 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8117 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8118 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8119 | |
| 8120 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8121 | uri_auth_compat_req[i++] = "realm"; |
| 8122 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8123 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8124 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8125 | uri_auth_compat_req[i++] = "unless"; |
| 8126 | uri_auth_compat_req[i++] = "{"; |
| 8127 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8128 | uri_auth_compat_req[i++] = "}"; |
| 8129 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8130 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8131 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8132 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8133 | cfgerr++; |
| 8134 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8135 | } |
| 8136 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8137 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8138 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8139 | if (curproxy->uri_auth->auth_realm) { |
| 8140 | free(curproxy->uri_auth->auth_realm); |
| 8141 | curproxy->uri_auth->auth_realm = NULL; |
| 8142 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8143 | |
| 8144 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8145 | } |
| 8146 | out_uri_auth_compat: |
| 8147 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8148 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8149 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8150 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8151 | if (!curproxy->conf.logformat_sd_string) { |
| 8152 | /* set the default logformat_sd_string */ |
| 8153 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8154 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8155 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8156 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8157 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8158 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8159 | /* compile the log format */ |
| 8160 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8161 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8162 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8163 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8164 | free(curproxy->conf.logformat_string); |
| 8165 | curproxy->conf.logformat_string = NULL; |
| 8166 | free(curproxy->conf.lfs_file); |
| 8167 | curproxy->conf.lfs_file = NULL; |
| 8168 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8169 | |
| 8170 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8171 | free(curproxy->conf.logformat_sd_string); |
| 8172 | curproxy->conf.logformat_sd_string = NULL; |
| 8173 | free(curproxy->conf.lfsd_file); |
| 8174 | curproxy->conf.lfsd_file = NULL; |
| 8175 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8176 | } |
| 8177 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8178 | if (curproxy->conf.logformat_string) { |
| 8179 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8180 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8181 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8182 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8183 | 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] | 8184 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8185 | ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8186 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8187 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8188 | cfgerr++; |
| 8189 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8190 | curproxy->conf.args.file = NULL; |
| 8191 | curproxy->conf.args.line = 0; |
| 8192 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8193 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8194 | if (curproxy->conf.logformat_sd_string) { |
| 8195 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8196 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8197 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8198 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8199 | 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] | 8200 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8201 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8202 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8203 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8204 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8205 | } 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] | 8206 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8207 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8208 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8209 | cfgerr++; |
| 8210 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8211 | curproxy->conf.args.file = NULL; |
| 8212 | curproxy->conf.args.line = 0; |
| 8213 | } |
| 8214 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8215 | if (curproxy->conf.uniqueid_format_string) { |
| 8216 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8217 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8218 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8219 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8220 | 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] | 8221 | (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] | 8222 | ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8223 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8224 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8225 | cfgerr++; |
| 8226 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8227 | curproxy->conf.args.file = NULL; |
| 8228 | curproxy->conf.args.line = 0; |
| 8229 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8230 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8231 | /* only now we can check if some args remain unresolved. |
| 8232 | * This must be done after the users and groups resolution. |
| 8233 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8234 | cfgerr += smp_resolve_args(curproxy); |
| 8235 | if (!cfgerr) |
| 8236 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8237 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8238 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8239 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8240 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8241 | (!curproxy->timeout.connect || |
| 8242 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8243 | ha_warning("config : missing timeouts for %s '%s'.\n" |
| 8244 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8245 | " | with such a configuration. To fix this, please ensure that all following\n" |
| 8246 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
| 8247 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8248 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8249 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8250 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8251 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8252 | * We must still support older configurations, so let's find out whether those |
| 8253 | * parameters have been set or must be copied from contimeouts. |
| 8254 | */ |
| 8255 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8256 | if (!curproxy->timeout.tarpit || |
| 8257 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8258 | /* tarpit timeout not set. We search in the following order: |
| 8259 | * default.tarpit, curr.connect, default.connect. |
| 8260 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8261 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8262 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8263 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8264 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8265 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8266 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8267 | } |
| 8268 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8269 | (!curproxy->timeout.queue || |
| 8270 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8271 | /* queue timeout not set. We search in the following order: |
| 8272 | * default.queue, curr.connect, default.connect. |
| 8273 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8274 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8275 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8276 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8277 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8278 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8279 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8280 | } |
| 8281 | } |
| 8282 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8283 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8284 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8285 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8286 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8287 | } |
| 8288 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8289 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8290 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8291 | ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8292 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8293 | err_code |= ERR_WARN; |
| 8294 | } |
| 8295 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8296 | /* ensure that cookie capture length is not too large */ |
| 8297 | if (curproxy->capture_len >= global.tune.cookie_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8298 | ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8299 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8300 | err_code |= ERR_WARN; |
| 8301 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8302 | } |
| 8303 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8304 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8305 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8306 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8307 | curproxy->nb_req_cap * sizeof(char *), |
| 8308 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8309 | } |
| 8310 | |
| 8311 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8312 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8313 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8314 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8315 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8316 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8317 | switch (curproxy->load_server_state_from_file) { |
| 8318 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8319 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8320 | break; |
| 8321 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8322 | if (!global.server_state_file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8323 | 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", |
| 8324 | curproxy->id); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8325 | err_code |= ERR_WARN; |
| 8326 | } |
| 8327 | break; |
| 8328 | } |
| 8329 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8330 | /* first, we will invert the servers list order */ |
| 8331 | newsrv = NULL; |
| 8332 | while (curproxy->srv) { |
| 8333 | struct server *next; |
| 8334 | |
| 8335 | next = curproxy->srv->next; |
| 8336 | curproxy->srv->next = newsrv; |
| 8337 | newsrv = curproxy->srv; |
| 8338 | if (!next) |
| 8339 | break; |
| 8340 | curproxy->srv = next; |
| 8341 | } |
| 8342 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8343 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8344 | * We only emit a warning for the first conflict affecting each server, |
| 8345 | * in order to avoid combinatory explosion if all servers have the same |
| 8346 | * name. We do that only for servers which do not have an explicit ID, |
| 8347 | * because these IDs were made also for distinguishing them and we don't |
| 8348 | * want to annoy people who correctly manage them. |
| 8349 | */ |
| 8350 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8351 | struct server *other_srv; |
| 8352 | |
| 8353 | if (newsrv->puid) |
| 8354 | continue; |
| 8355 | |
| 8356 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8357 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8358 | 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", |
| 8359 | newsrv->conf.file, newsrv->conf.line, |
| 8360 | proxy_type_str(curproxy), curproxy->id, |
| 8361 | newsrv->id, other_srv->conf.line); |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8362 | break; |
| 8363 | } |
| 8364 | } |
| 8365 | } |
| 8366 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8367 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8368 | next_id = 1; |
| 8369 | newsrv = curproxy->srv; |
| 8370 | while (newsrv != NULL) { |
| 8371 | if (!newsrv->puid) { |
| 8372 | /* server ID not set, use automatic numbering with first |
| 8373 | * spare entry starting with next_svid. |
| 8374 | */ |
| 8375 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8376 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8377 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8378 | } |
| 8379 | next_id++; |
| 8380 | newsrv = newsrv->next; |
| 8381 | } |
| 8382 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8383 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8384 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8385 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8386 | /* |
| 8387 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8388 | * tasks to fill the emptied slots when a connection leaves. |
| 8389 | * Also, resolve deferred tracking dependency if needed. |
| 8390 | */ |
| 8391 | newsrv = curproxy->srv; |
| 8392 | while (newsrv != NULL) { |
| 8393 | if (newsrv->minconn > newsrv->maxconn) { |
| 8394 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8395 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8396 | * this will avoid further useless expensive computations. |
| 8397 | */ |
| 8398 | newsrv->maxconn = newsrv->minconn; |
| 8399 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8400 | /* minconn was not specified, so we set it to maxconn */ |
| 8401 | newsrv->minconn = newsrv->maxconn; |
| 8402 | } |
| 8403 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8404 | /* this will also properly set the transport layer for prod and checks */ |
| 8405 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8406 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8407 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8408 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8409 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8410 | /* set the check type on the server */ |
| 8411 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8412 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8413 | if (newsrv->trackit) { |
| 8414 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8415 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8416 | char *pname, *sname; |
| 8417 | |
| 8418 | pname = newsrv->trackit; |
| 8419 | sname = strrchr(pname, '/'); |
| 8420 | |
| 8421 | if (sname) |
| 8422 | *sname++ = '\0'; |
| 8423 | else { |
| 8424 | sname = pname; |
| 8425 | pname = NULL; |
| 8426 | } |
| 8427 | |
| 8428 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8429 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8430 | if (!px) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8431 | ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8432 | proxy_type_str(curproxy), curproxy->id, |
| 8433 | newsrv->id, pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8434 | cfgerr++; |
| 8435 | goto next_srv; |
| 8436 | } |
| 8437 | } else |
| 8438 | px = curproxy; |
| 8439 | |
| 8440 | srv = findserver(px, sname); |
| 8441 | if (!srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8442 | ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8443 | proxy_type_str(curproxy), curproxy->id, |
| 8444 | newsrv->id, sname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8445 | cfgerr++; |
| 8446 | goto next_srv; |
| 8447 | } |
| 8448 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8449 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8450 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8451 | !srv->track && !srv->trackit) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8452 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 8453 | "tracking as it does not have any check nor agent enabled.\n", |
| 8454 | proxy_type_str(curproxy), curproxy->id, |
| 8455 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8456 | cfgerr++; |
| 8457 | goto next_srv; |
| 8458 | } |
| 8459 | |
| 8460 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8461 | |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8462 | if (newsrv == srv || loop) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8463 | ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8464 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8465 | proxy_type_str(curproxy), curproxy->id, |
| 8466 | newsrv->id, px->id, srv->id, px->id, |
| 8467 | newsrv == srv ? srv->id : loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8468 | cfgerr++; |
| 8469 | goto next_srv; |
| 8470 | } |
| 8471 | |
| 8472 | if (curproxy != px && |
| 8473 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8474 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8475 | "tracking: disable-on-404 option inconsistency.\n", |
| 8476 | proxy_type_str(curproxy), curproxy->id, |
| 8477 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8478 | cfgerr++; |
| 8479 | goto next_srv; |
| 8480 | } |
| 8481 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8482 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8483 | newsrv->tracknext = srv->trackers; |
| 8484 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8485 | |
| 8486 | free(newsrv->trackit); |
| 8487 | newsrv->trackit = NULL; |
| 8488 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8489 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8490 | next_srv: |
| 8491 | newsrv = newsrv->next; |
| 8492 | } |
| 8493 | |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 8494 | /* |
| 8495 | * Try to generate dynamic cookies for servers now. |
| 8496 | * It couldn't be done earlier, since at the time we parsed |
| 8497 | * the server line, we may not have known yet that we |
| 8498 | * should use dynamic cookies, or the secret key may not |
| 8499 | * have been provided yet. |
| 8500 | */ |
| 8501 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
| 8502 | newsrv = curproxy->srv; |
| 8503 | while (newsrv != NULL) { |
| 8504 | srv_set_dyncookie(newsrv); |
| 8505 | newsrv = newsrv->next; |
| 8506 | } |
| 8507 | |
| 8508 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8509 | /* We have to initialize the server lookup mechanism depending |
| 8510 | * on what LB algorithm was choosen. |
| 8511 | */ |
| 8512 | |
| 8513 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8514 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8515 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8516 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8517 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8518 | init_server_map(curproxy); |
Willy Tarreau | 760e81d | 2018-05-03 07:20:40 +0200 | [diff] [blame] | 8519 | } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) { |
| 8520 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8521 | chash_init_server_tree(curproxy); |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8522 | } else { |
| 8523 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8524 | fwrr_init_server_groups(curproxy); |
| 8525 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8526 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8527 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8528 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8529 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8530 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8531 | fwlc_init_server_tree(curproxy); |
| 8532 | } else { |
| 8533 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8534 | fas_init_server_tree(curproxy); |
| 8535 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8536 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8537 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8538 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8539 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8540 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8541 | chash_init_server_tree(curproxy); |
| 8542 | } else { |
| 8543 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8544 | init_server_map(curproxy); |
| 8545 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8546 | break; |
| 8547 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 8548 | HA_SPIN_INIT(&curproxy->lbprm.lock); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8549 | |
| 8550 | if (curproxy->options & PR_O_LOGASAP) |
| 8551 | curproxy->to_log &= ~LW_BYTES; |
| 8552 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8553 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8554 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8555 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8556 | ha_warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8557 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8558 | err_code |= ERR_WARN; |
| 8559 | } |
| 8560 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8561 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8562 | int optnum; |
| 8563 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8564 | if (curproxy->uri_auth) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8565 | ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8566 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8567 | err_code |= ERR_WARN; |
| 8568 | curproxy->uri_auth = NULL; |
| 8569 | } |
| 8570 | |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8571 | if (curproxy->capture_name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8572 | ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8573 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8574 | err_code |= ERR_WARN; |
| 8575 | } |
| 8576 | |
| 8577 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8578 | ha_warning("config : 'http-request' rules ignored for %s '%s' as they require 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_res_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8584 | ha_warning("config : 'http-response' 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->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8590 | ha_warning("config : 'block' 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->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8596 | ha_warning("config : 'redirect' 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 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8601 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8602 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8603 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8604 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8605 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8606 | } |
| 8607 | |
| 8608 | if (curproxy->options & PR_O_ORGTO) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8609 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8610 | "originalto", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8611 | err_code |= ERR_WARN; |
| 8612 | curproxy->options &= ~PR_O_ORGTO; |
| 8613 | } |
| 8614 | |
| 8615 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8616 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8617 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8618 | (curproxy->options & cfg_opts[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8619 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8620 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8621 | err_code |= ERR_WARN; |
| 8622 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8627 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8628 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8629 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8630 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8631 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8632 | err_code |= ERR_WARN; |
| 8633 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8634 | } |
| 8635 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8636 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8637 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8638 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8639 | curproxy->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8640 | ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 8641 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8642 | err_code |= ERR_WARN; |
| 8643 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8644 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8645 | } |
| 8646 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8647 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8648 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8649 | */ |
| 8650 | newsrv = curproxy->srv; |
| 8651 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8652 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8653 | ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8654 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8655 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8656 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8657 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8658 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8659 | ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8660 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8661 | err_code |= ERR_WARN; |
| 8662 | } |
| 8663 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8664 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8665 | ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8666 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8667 | err_code |= ERR_WARN; |
| 8668 | } |
| 8669 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8670 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8671 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8672 | newsrv->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8673 | ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 8674 | 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] | 8675 | err_code |= ERR_WARN; |
| 8676 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8677 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8678 | |
Willy Tarreau | 46deab6 | 2018-04-28 07:18:15 +0200 | [diff] [blame] | 8679 | if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) |
| 8680 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 8681 | |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8682 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8683 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8684 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8685 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8686 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8687 | 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", |
| 8688 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8689 | err_code |= ERR_WARN; |
| 8690 | } |
| 8691 | |
| 8692 | |
| 8693 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8694 | 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", |
| 8695 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8696 | err_code |= ERR_WARN; |
| 8697 | } |
| 8698 | } |
| 8699 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8700 | newsrv = newsrv->next; |
| 8701 | } |
| 8702 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8703 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8704 | * with no inspect-delay |
| 8705 | */ |
| 8706 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8707 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8708 | if (arule->action == ACT_TCP_CAPTURE && |
| 8709 | !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8710 | break; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8711 | if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) && |
| 8712 | !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8713 | break; |
| 8714 | } |
| 8715 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8716 | if (&arule->list != &curproxy->tcp_req.inspect_rules) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8717 | ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8718 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8719 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8720 | " setting the tcp-request inspect-delay.\n", |
| 8721 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8722 | err_code |= ERR_WARN; |
| 8723 | } |
| 8724 | } |
| 8725 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8726 | /* Check filter configuration, if any */ |
| 8727 | cfgerr += flt_check(curproxy); |
| 8728 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8729 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8730 | if (!curproxy->accept) |
| 8731 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8732 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8733 | if (curproxy->tcp_req.inspect_delay || |
| 8734 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8735 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8736 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8737 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8738 | 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] | 8739 | 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] | 8740 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8741 | |
| 8742 | /* both TCP and HTTP must check switching rules */ |
| 8743 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8744 | |
| 8745 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8746 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8747 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8748 | 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] | 8749 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8750 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8751 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8752 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8753 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8754 | } |
| 8755 | |
| 8756 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8757 | if (curproxy->tcp_req.inspect_delay || |
| 8758 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8759 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8760 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8761 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8762 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8763 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8764 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8765 | 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] | 8766 | 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] | 8767 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8768 | |
| 8769 | /* If the backend does requires RDP cookie persistence, we have to |
| 8770 | * enable the corresponding analyser. |
| 8771 | */ |
| 8772 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8773 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8774 | |
| 8775 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8776 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8777 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8778 | 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] | 8779 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8780 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8781 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8782 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8783 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8784 | } |
Christopher Faulet | a717b99 | 2018-04-10 14:43:00 +0200 | [diff] [blame] | 8785 | |
Christopher Faulet | 8ed0a3e | 2018-04-10 14:45:45 +0200 | [diff] [blame] | 8786 | /* Check the mux protocols, if any, for each listener and server |
Christopher Faulet | a717b99 | 2018-04-10 14:43:00 +0200 | [diff] [blame] | 8787 | * attached to the current proxy */ |
| 8788 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8789 | int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); |
| 8790 | |
| 8791 | if (!bind_conf->mux_proto) |
| 8792 | continue; |
| 8793 | if (!(bind_conf->mux_proto->mode & mode)) { |
| 8794 | ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n", |
| 8795 | proxy_type_str(curproxy), curproxy->id, |
| 8796 | (int)bind_conf->mux_proto->token.len, |
| 8797 | bind_conf->mux_proto->token.ptr, |
| 8798 | bind_conf->arg, bind_conf->file, bind_conf->line); |
| 8799 | cfgerr++; |
| 8800 | } |
| 8801 | } |
Christopher Faulet | 8ed0a3e | 2018-04-10 14:45:45 +0200 | [diff] [blame] | 8802 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8803 | int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); |
| 8804 | |
| 8805 | if (!newsrv->mux_proto) |
| 8806 | continue; |
| 8807 | if (!(newsrv->mux_proto->mode & mode)) { |
| 8808 | ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n", |
| 8809 | proxy_type_str(curproxy), curproxy->id, |
| 8810 | (int)newsrv->mux_proto->token.len, |
| 8811 | newsrv->mux_proto->token.ptr, |
| 8812 | newsrv->id, newsrv->conf.file, newsrv->conf.line); |
| 8813 | cfgerr++; |
| 8814 | } |
| 8815 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8816 | } |
| 8817 | |
| 8818 | /***********************************************************/ |
| 8819 | /* At this point, target names have already been resolved. */ |
| 8820 | /***********************************************************/ |
| 8821 | |
| 8822 | /* Check multi-process mode compatibility */ |
| 8823 | |
| 8824 | if (global.nbproc > 1 && global.stats_fe) { |
| 8825 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8826 | unsigned long mask; |
| 8827 | |
| 8828 | mask = nbits(global.nbproc); |
| 8829 | if (global.stats_fe->bind_proc) |
| 8830 | mask &= global.stats_fe->bind_proc; |
| 8831 | |
| 8832 | if (bind_conf->bind_proc) |
| 8833 | mask &= bind_conf->bind_proc; |
| 8834 | |
| 8835 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8836 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8837 | break; |
| 8838 | } |
| 8839 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8840 | 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] | 8841 | } |
| 8842 | } |
| 8843 | |
| 8844 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8845 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8846 | if (curproxy->bind_proc) |
| 8847 | continue; |
| 8848 | |
| 8849 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8850 | unsigned long mask; |
| 8851 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8852 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8853 | curproxy->bind_proc |= mask; |
| 8854 | } |
| 8855 | |
| 8856 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8857 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8858 | } |
| 8859 | |
| 8860 | if (global.stats_fe) { |
| 8861 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8862 | unsigned long mask; |
| 8863 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8864 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8865 | global.stats_fe->bind_proc |= mask; |
| 8866 | } |
| 8867 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8868 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8869 | } |
| 8870 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8871 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8872 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8873 | */ |
| 8874 | if (!cfgerr) { |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8875 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8876 | if (curproxy->cap & PR_CAP_FE) |
| 8877 | propagate_processes(curproxy, NULL); |
| 8878 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | /* Bind each unbound backend to all processes when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8882 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8883 | if (curproxy->bind_proc) |
| 8884 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8885 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8886 | } |
| 8887 | |
| 8888 | /*******************************************************/ |
| 8889 | /* At this step, all proxies have a non-null bind_proc */ |
| 8890 | /*******************************************************/ |
| 8891 | |
| 8892 | /* perform the final checks before creating tasks */ |
| 8893 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8894 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8895 | struct listener *listener; |
| 8896 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8897 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8898 | /* Configure SSL for each bind line. |
| 8899 | * Note: if configuration fails at some point, the ->ctx member |
| 8900 | * remains NULL so that listeners can later detach. |
| 8901 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8902 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8903 | if (bind_conf->xprt->prepare_bind_conf && |
| 8904 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8905 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8906 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8907 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8908 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8909 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8910 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8911 | int nbproc; |
| 8912 | |
| 8913 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8914 | (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] | 8915 | nbits(global.nbproc)); |
| 8916 | |
| 8917 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8918 | nbproc = 1; |
| 8919 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8920 | if (!listener->luid) { |
| 8921 | /* listener ID not set, use automatic numbering with first |
| 8922 | * spare entry starting with next_luid. |
| 8923 | */ |
| 8924 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8925 | listener->conf.id.key = listener->luid = next_id; |
| 8926 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8927 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8928 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8929 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8930 | /* enable separate counters */ |
| 8931 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8932 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8933 | if (!listener->name) |
| 8934 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8935 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8936 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8937 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8938 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8939 | if (!listener->maxconn) |
| 8940 | listener->maxconn = curproxy->maxconn; |
| 8941 | if (!listener->backlog) |
| 8942 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8943 | if (!listener->maxaccept) |
| 8944 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8945 | |
| 8946 | /* we want to have an optimal behaviour on single process mode to |
| 8947 | * maximize the work at once, but in multi-process we want to keep |
| 8948 | * some fairness between processes, so we target half of the max |
| 8949 | * number of events to be balanced over all the processes the proxy |
| 8950 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8951 | * used to disable the limit. |
| 8952 | */ |
| 8953 | if (listener->maxaccept > 0) { |
| 8954 | if (nbproc > 1) |
| 8955 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8956 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8957 | } |
| 8958 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8959 | listener->accept = session_accept_fd; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8960 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8961 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8962 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8963 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8964 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8965 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8966 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8967 | listener->options |= LI_O_TCP_L5_RULES; |
| 8968 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8969 | if (curproxy->mon_mask.s_addr) |
| 8970 | listener->options |= LI_O_CHK_MONNET; |
| 8971 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8972 | /* smart accept mode is automatic in HTTP mode */ |
| 8973 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8974 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8975 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8976 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8977 | } |
| 8978 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8979 | /* Release unused SSL configs */ |
| 8980 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 8981 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 8982 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8983 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8984 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8985 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8986 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8987 | int count, maxproc = 0; |
| 8988 | |
| 8989 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8990 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8991 | if (count > maxproc) |
| 8992 | maxproc = count; |
| 8993 | } |
| 8994 | /* backends have 0, frontends have 1 or more */ |
| 8995 | if (maxproc != 1) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8996 | ha_warning("Proxy '%s': in multi-process mode, stats will be" |
| 8997 | " limited to process assigned to the current request.\n", |
| 8998 | curproxy->id); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8999 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9000 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9001 | ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 9002 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9003 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9004 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 9005 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9006 | ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 9007 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 9008 | } |
| 9009 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9010 | |
| 9011 | /* create the task associated with the proxy */ |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 9012 | curproxy->task = task_new(MAX_THREADS_MASK); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9013 | if (curproxy->task) { |
| 9014 | curproxy->task->context = curproxy; |
| 9015 | curproxy->task->process = manage_proxy; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9016 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9017 | ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 9018 | curproxy->id); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 9019 | cfgerr++; |
| 9020 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 9021 | } |
| 9022 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9023 | /* automatically compute fullconn if not set. We must not do it in the |
| 9024 | * loop above because cross-references are not yet fully resolved. |
| 9025 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9026 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9027 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 9028 | * the possible incoming frontend's maxconns. |
| 9029 | */ |
| 9030 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9031 | /* we have the sum of the maxconns in <total>. We only |
| 9032 | * keep 10% of that sum to set the default fullconn, with |
| 9033 | * a hard minimum of 1 (to avoid a divide by zero). |
| 9034 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 9035 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 9036 | if (!curproxy->fullconn) |
| 9037 | curproxy->fullconn = 1; |
| 9038 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 9039 | } |
| 9040 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9041 | /* |
| 9042 | * Recount currently required checks. |
| 9043 | */ |
| 9044 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9045 | for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) { |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9046 | int optnum; |
| 9047 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9048 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 9049 | if (curproxy->options & cfg_opts[optnum].val) |
| 9050 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9051 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 9052 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 9053 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 9054 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 9055 | } |
| 9056 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9057 | /* compute the required process bindings for the peers */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9058 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 9059 | if (curproxy->table.peers.p) |
| 9060 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 9061 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9062 | if (cfg_peers) { |
| 9063 | struct peers *curpeers = cfg_peers, **last; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9064 | struct peer *p, *pb; |
| 9065 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9066 | /* Remove all peers sections which don't have a valid listener, |
| 9067 | * which are not used by any table, or which are bound to more |
| 9068 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9069 | */ |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9070 | last = &cfg_peers; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9071 | while (*last) { |
| 9072 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9073 | |
| 9074 | if (curpeers->state == PR_STSTOPPED) { |
| 9075 | /* the "disabled" keyword was present */ |
| 9076 | if (curpeers->peers_fe) |
| 9077 | stop_proxy(curpeers->peers_fe); |
| 9078 | curpeers->peers_fe = NULL; |
| 9079 | } |
| 9080 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9081 | ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9082 | curpeers->id, localpeer); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9083 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9084 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9085 | /* either it's totally stopped or too much used */ |
| 9086 | if (curpeers->peers_fe->bind_proc) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9087 | ha_alert("Peers section '%s': peers referenced by sections " |
| 9088 | "running in different processes (%d different ones). " |
| 9089 | "Check global.nbproc and all tables' bind-process " |
| 9090 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9091 | cfgerr++; |
| 9092 | } |
| 9093 | stop_proxy(curpeers->peers_fe); |
| 9094 | curpeers->peers_fe = NULL; |
| 9095 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9096 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9097 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9098 | last = &curpeers->next; |
| 9099 | continue; |
| 9100 | } |
| 9101 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9102 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9103 | p = curpeers->remote; |
| 9104 | while (p) { |
| 9105 | pb = p->next; |
| 9106 | free(p->id); |
| 9107 | free(p); |
| 9108 | p = pb; |
| 9109 | } |
| 9110 | |
| 9111 | /* Destroy and unlink this curpeers section. |
| 9112 | * Note: curpeers is backed up into *last. |
| 9113 | */ |
| 9114 | free(curpeers->id); |
| 9115 | curpeers = curpeers->next; |
| 9116 | free(*last); |
| 9117 | *last = curpeers; |
| 9118 | } |
| 9119 | } |
| 9120 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9121 | /* initialize stick-tables on backend capable proxies. This must not |
| 9122 | * be done earlier because the data size may be discovered while parsing |
| 9123 | * other proxies. |
| 9124 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9125 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9126 | if (curproxy->state == PR_STSTOPPED) |
| 9127 | continue; |
| 9128 | |
| 9129 | if (!stktable_init(&curproxy->table)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9130 | ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9131 | cfgerr++; |
| 9132 | } |
| 9133 | } |
| 9134 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9135 | if (mailers) { |
| 9136 | struct mailers *curmailers = mailers, **last; |
| 9137 | struct mailer *m, *mb; |
| 9138 | |
| 9139 | /* Remove all mailers sections which don't have a valid listener. |
| 9140 | * This can happen when a mailers section is never referenced. |
| 9141 | */ |
| 9142 | last = &mailers; |
| 9143 | while (*last) { |
| 9144 | curmailers = *last; |
| 9145 | if (curmailers->users) { |
| 9146 | last = &curmailers->next; |
| 9147 | continue; |
| 9148 | } |
| 9149 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9150 | ha_warning("Removing incomplete section 'mailers %s'.\n", |
| 9151 | curmailers->id); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9152 | |
| 9153 | m = curmailers->mailer_list; |
| 9154 | while (m) { |
| 9155 | mb = m->next; |
| 9156 | free(m->id); |
| 9157 | free(m); |
| 9158 | m = mb; |
| 9159 | } |
| 9160 | |
| 9161 | /* Destroy and unlink this curmailers section. |
| 9162 | * Note: curmailers is backed up into *last. |
| 9163 | */ |
| 9164 | free(curmailers->id); |
| 9165 | curmailers = curmailers->next; |
| 9166 | free(*last); |
| 9167 | *last = curmailers; |
| 9168 | } |
| 9169 | } |
| 9170 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9171 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9172 | * a server-state file locally defined and none has been provided */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9173 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9174 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9175 | curproxy->server_state_file_name == NULL) |
| 9176 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9177 | } |
| 9178 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 9179 | pool_head_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9180 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9181 | MEM_F_SHARED); |
| 9182 | |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 9183 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 9184 | if (LIST_ISEMPTY(&curr_resolvers->nameservers)) { |
| 9185 | ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n", |
| 9186 | curr_resolvers->id, curr_resolvers->conf.file, |
| 9187 | curr_resolvers->conf.line); |
| 9188 | err_code |= ERR_WARN; |
| 9189 | } |
| 9190 | } |
| 9191 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9192 | list_for_each_entry(postparser, &postparsers, list) { |
| 9193 | if (postparser->func) |
| 9194 | cfgerr += postparser->func(); |
| 9195 | } |
| 9196 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9197 | if (cfgerr > 0) |
| 9198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9199 | out: |
| 9200 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9201 | } |
| 9202 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9203 | /* |
| 9204 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9205 | * parsing sessions. |
| 9206 | */ |
| 9207 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9208 | { |
| 9209 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9210 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9211 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9212 | /* |
| 9213 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9214 | */ |
| 9215 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9216 | { |
| 9217 | LIST_DEL(&kwl->list); |
| 9218 | LIST_INIT(&kwl->list); |
| 9219 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9220 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9221 | /* this function register new section in the haproxy configuration file. |
| 9222 | * <section_name> is the name of this new section and <section_parser> |
| 9223 | * is the called parser. If two section declaration have the same name, |
| 9224 | * only the first declared is used. |
| 9225 | */ |
| 9226 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9227 | int (*section_parser)(const char *, int, char **, int), |
| 9228 | int (*post_section_parser)()) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9229 | { |
| 9230 | struct cfg_section *cs; |
| 9231 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9232 | list_for_each_entry(cs, §ions, list) { |
| 9233 | if (strcmp(cs->section_name, section_name) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9234 | ha_alert("register section '%s': already registered.\n", section_name); |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9235 | return 0; |
| 9236 | } |
| 9237 | } |
| 9238 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9239 | cs = calloc(1, sizeof(*cs)); |
| 9240 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9241 | ha_alert("register section '%s': out of memory.\n", section_name); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9242 | return 0; |
| 9243 | } |
| 9244 | |
| 9245 | cs->section_name = section_name; |
| 9246 | cs->section_parser = section_parser; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9247 | cs->post_section_parser = post_section_parser; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9248 | |
| 9249 | LIST_ADDQ(§ions, &cs->list); |
| 9250 | |
| 9251 | return 1; |
| 9252 | } |
| 9253 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9254 | /* this function register a new function which will be called once the haproxy |
| 9255 | * configuration file has been parsed. It's useful to check dependencies |
| 9256 | * between sections or to resolve items once everything is parsed. |
| 9257 | */ |
| 9258 | int cfg_register_postparser(char *name, int (*func)()) |
| 9259 | { |
| 9260 | struct cfg_postparser *cp; |
| 9261 | |
| 9262 | cp = calloc(1, sizeof(*cp)); |
| 9263 | if (!cp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9264 | ha_alert("register postparser '%s': out of memory.\n", name); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9265 | return 0; |
| 9266 | } |
| 9267 | cp->name = name; |
| 9268 | cp->func = func; |
| 9269 | |
| 9270 | LIST_ADDQ(&postparsers, &cp->list); |
| 9271 | |
| 9272 | return 1; |
| 9273 | } |
| 9274 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9275 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9276 | * free all config section entries |
| 9277 | */ |
| 9278 | void cfg_unregister_sections(void) |
| 9279 | { |
| 9280 | struct cfg_section *cs, *ics; |
| 9281 | |
| 9282 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9283 | LIST_DEL(&cs->list); |
| 9284 | free(cs); |
| 9285 | } |
| 9286 | } |
| 9287 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9288 | void cfg_backup_sections(struct list *backup_sections) |
| 9289 | { |
| 9290 | struct cfg_section *cs, *ics; |
| 9291 | |
| 9292 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9293 | LIST_DEL(&cs->list); |
| 9294 | LIST_ADDQ(backup_sections, &cs->list); |
| 9295 | } |
| 9296 | } |
| 9297 | |
| 9298 | void cfg_restore_sections(struct list *backup_sections) |
| 9299 | { |
| 9300 | struct cfg_section *cs, *ics; |
| 9301 | |
| 9302 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9303 | LIST_DEL(&cs->list); |
| 9304 | LIST_ADDQ(§ions, &cs->list); |
| 9305 | } |
| 9306 | } |
| 9307 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9308 | __attribute__((constructor)) |
| 9309 | static void cfgparse_init(void) |
| 9310 | { |
| 9311 | /* Register internal sections */ |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9312 | cfg_register_section("listen", cfg_parse_listen, NULL); |
| 9313 | cfg_register_section("frontend", cfg_parse_listen, NULL); |
| 9314 | cfg_register_section("backend", cfg_parse_listen, NULL); |
| 9315 | cfg_register_section("defaults", cfg_parse_listen, NULL); |
| 9316 | cfg_register_section("global", cfg_parse_global, NULL); |
| 9317 | cfg_register_section("userlist", cfg_parse_users, NULL); |
| 9318 | cfg_register_section("peers", cfg_parse_peers, NULL); |
| 9319 | cfg_register_section("mailers", cfg_parse_mailers, NULL); |
| 9320 | cfg_register_section("namespace_list", cfg_parse_netns, NULL); |
| 9321 | cfg_register_section("resolvers", cfg_parse_resolvers, NULL); |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9322 | } |
| 9323 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9324 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9325 | * Local variables: |
| 9326 | * c-indent-level: 8 |
| 9327 | * c-basic-offset: 8 |
| 9328 | * End: |
| 9329 | */ |