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); |
| 298 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | 12eb2a6 | 2013-03-06 15:45:03 +0100 | [diff] [blame] | 300 | /* OK the address looks correct */ |
William Lallemand | 75ea0a0 | 2017-11-15 19:02:58 +0100 | [diff] [blame] | 301 | if (!create_listeners(bind_conf, ss2, port, end, fd, inherited, err)) { |
Willy Tarreau | 0de59fd | 2017-09-15 08:10:44 +0200 | [diff] [blame] | 302 | memprintf(err, "%s for address '%s'.\n", *err, str); |
| 303 | goto fail; |
| 304 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 305 | } /* end while(next) */ |
| 306 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 307 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 308 | fail: |
| 309 | free(dupstr); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 310 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 311 | } |
| 312 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 313 | /* |
Willy Tarreau | ece9b07 | 2016-12-21 22:41:44 +0100 | [diff] [blame] | 314 | * Report an error in <msg> when there are too many arguments. This version is |
| 315 | * intended to be used by keyword parsers so that the message will be included |
| 316 | * into the general error message. The index is the current keyword in args. |
| 317 | * Return 0 if the number of argument is correct, otherwise build a message and |
| 318 | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
| 319 | * message may also be null, it will simply not be produced (useful to check only). |
| 320 | * <msg> and <err_code> are only affected on error. |
| 321 | */ |
| 322 | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
| 323 | { |
| 324 | int i; |
| 325 | |
| 326 | if (!*args[index + maxarg + 1]) |
| 327 | return 0; |
| 328 | |
| 329 | if (msg) { |
| 330 | *msg = NULL; |
| 331 | memprintf(msg, "%s", args[0]); |
| 332 | for (i = 1; i <= index; i++) |
| 333 | memprintf(msg, "%s %s", *msg, args[i]); |
| 334 | |
| 335 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
| 336 | } |
| 337 | if (err_code) |
| 338 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 339 | |
| 340 | return 1; |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * same as too_many_args_idx with a 0 index |
| 345 | */ |
| 346 | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
| 347 | { |
| 348 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
| 349 | } |
| 350 | |
| 351 | /* |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 352 | * Report a fatal Alert when there is too much arguments |
| 353 | * The index is the current keyword in args |
| 354 | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
| 355 | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
| 356 | */ |
| 357 | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
| 358 | { |
| 359 | char *kw = NULL; |
| 360 | int i; |
| 361 | |
| 362 | if (!*args[index + maxarg + 1]) |
| 363 | return 0; |
| 364 | |
| 365 | memprintf(&kw, "%s", args[0]); |
| 366 | for (i = 1; i <= index; i++) { |
| 367 | memprintf(&kw, "%s %s", kw, args[i]); |
| 368 | } |
| 369 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 370 | 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] | 371 | free(kw); |
| 372 | *err_code |= ERR_ALERT | ERR_FATAL; |
| 373 | return 1; |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | * same as alertif_too_many_args_idx with a 0 index |
| 378 | */ |
| 379 | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
| 380 | { |
| 381 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
| 382 | } |
| 383 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 384 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 385 | * Return 1 if the warning has been emitted, otherwise 0. |
| 386 | */ |
| 387 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 388 | { |
| 389 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 390 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 391 | file, line, arg); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 392 | return 1; |
| 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 397 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 398 | * Return 1 if the warning has been emitted, otherwise 0. |
| 399 | */ |
| 400 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 401 | { |
| 402 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 403 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 404 | file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 405 | return 1; |
| 406 | } |
| 407 | return 0; |
| 408 | } |
| 409 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 410 | /* Report a warning if a rule is placed after a 'monitor fail' rule. |
| 411 | * Return 1 if the warning has been emitted, otherwise 0. |
| 412 | */ |
| 413 | int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
| 414 | { |
| 415 | if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { |
| 416 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", |
| 417 | file, line, arg); |
| 418 | return 1; |
| 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 423 | /* Report a warning if a rule is placed after a 'block' rule. |
| 424 | * Return 1 if the warning has been emitted, otherwise 0. |
| 425 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 426 | 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] | 427 | { |
Willy Tarreau | 353bc9f | 2014-04-28 22:05:31 +0200 | [diff] [blame] | 428 | if (!LIST_ISEMPTY(&proxy->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 429 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'block' rule will still be processed before.\n", |
| 430 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 431 | return 1; |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 436 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 437 | * Return 1 if the warning has been emitted, otherwise 0. |
| 438 | */ |
| 439 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 440 | { |
| 441 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 442 | ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 443 | file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 444 | return 1; |
| 445 | } |
| 446 | return 0; |
| 447 | } |
| 448 | |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 449 | /* Report a warning if a rule is placed after a reqrewrite rule. |
| 450 | * Return 1 if the warning has been emitted, otherwise 0. |
| 451 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 452 | 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] | 453 | { |
| 454 | if (proxy->req_exp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 455 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqxxx' rule will still be processed before.\n", |
| 456 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 457 | return 1; |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | /* Report a warning if a rule is placed after a reqadd rule. |
| 463 | * Return 1 if the warning has been emitted, otherwise 0. |
| 464 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 465 | 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] | 466 | { |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 467 | if (!LIST_ISEMPTY(&proxy->req_add)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 468 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'reqadd' rule will still be processed before.\n", |
| 469 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 470 | return 1; |
| 471 | } |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | /* Report a warning if a rule is placed after a redirect rule. |
| 476 | * Return 1 if the warning has been emitted, otherwise 0. |
| 477 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 478 | 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] | 479 | { |
| 480 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 481 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 482 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 483 | return 1; |
| 484 | } |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 489 | * Return 1 if the warning has been emitted, otherwise 0. |
| 490 | */ |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 491 | 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] | 492 | { |
| 493 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 494 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 495 | file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 496 | return 1; |
| 497 | } |
| 498 | return 0; |
| 499 | } |
| 500 | |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 501 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 502 | * Return 1 if the warning has been emitted, otherwise 0. |
| 503 | */ |
| 504 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 505 | { |
| 506 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 507 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 508 | file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 509 | return 1; |
| 510 | } |
| 511 | return 0; |
| 512 | } |
| 513 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 514 | /* report a warning if a redirect rule is dangerously placed */ |
| 515 | 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] | 516 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 517 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 518 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 519 | } |
| 520 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 521 | /* report a warning if a reqadd rule is dangerously placed */ |
| 522 | 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] | 523 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 524 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 525 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3986b9c | 2014-09-16 15:39:51 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 528 | /* report a warning if a reqxxx rule is dangerously placed */ |
| 529 | 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] | 530 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 531 | return warnif_rule_after_reqadd(proxy, file, line, arg) || |
| 532 | warnif_misplaced_reqadd(proxy, file, line, arg); |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /* report a warning if an http-request rule is dangerously placed */ |
| 536 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 537 | { |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 538 | return warnif_rule_after_reqxxx(proxy, file, line, arg) || |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 539 | warnif_misplaced_reqxxx(proxy, file, line, arg);; |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 540 | } |
| 541 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 542 | /* report a warning if a block rule is dangerously placed */ |
| 543 | 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] | 544 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 545 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 546 | warnif_misplaced_http_req(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 549 | /* report a warning if a block rule is dangerously placed */ |
| 550 | 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] | 551 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 552 | return warnif_rule_after_block(proxy, file, line, arg) || |
| 553 | warnif_misplaced_block(proxy, file, line, arg); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 556 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 557 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 558 | { |
| 559 | return warnif_rule_after_monitor(proxy, file, line, arg) || |
| 560 | warnif_misplaced_monitor(proxy, file, line, arg); |
| 561 | } |
| 562 | |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 563 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 564 | 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] | 565 | { |
Willy Tarreau | d39ad44 | 2016-11-25 15:16:12 +0100 | [diff] [blame] | 566 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 567 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 568 | } |
| 569 | |
| 570 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 571 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 572 | { |
| 573 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 574 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 577 | /* Report it if a request ACL condition uses some keywords that are incompatible |
| 578 | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
| 579 | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
| 580 | * will be ignored. |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 581 | */ |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 582 | 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] | 583 | { |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 584 | const struct acl *acl; |
Willy Tarreau | 93fddf1 | 2013-03-31 22:59:32 +0200 | [diff] [blame] | 585 | const char *kw; |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 586 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 587 | if (!cond) |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 588 | return 0; |
| 589 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 590 | acl = acl_cond_conflicts(cond, where); |
| 591 | if (acl) { |
| 592 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 593 | ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
| 594 | file, line, acl->name, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 595 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 596 | ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
| 597 | 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] | 598 | return ERR_WARN; |
| 599 | } |
| 600 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 601 | return 0; |
| 602 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 603 | if (acl->name && *acl->name) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 604 | ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
| 605 | file, line, acl->name, kw, sample_ckp_names(where)); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 606 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 607 | ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
| 608 | file, line, kw, sample_ckp_names(where)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 609 | return ERR_WARN; |
| 610 | } |
| 611 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 612 | /* 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] | 613 | * 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] | 614 | * two such numbers delimited by a dash ('-'). On success, it returns |
| 615 | * 0. otherwise it returns 1 with an error message in <err>. |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 616 | * |
| 617 | * Note: this function can also be used to parse a thread number or a set of |
| 618 | * threads. |
| 619 | */ |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 620 | 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] | 621 | { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 622 | if (autoinc) { |
| 623 | *autoinc = 0; |
| 624 | if (strncmp(arg, "auto:", 5) == 0) { |
| 625 | arg += 5; |
| 626 | *autoinc = 1; |
| 627 | } |
| 628 | } |
| 629 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 630 | if (strcmp(arg, "all") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 631 | *proc |= ~0UL; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 632 | else if (strcmp(arg, "odd") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 633 | *proc |= ~0UL/3UL; /* 0x555....555 */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 634 | else if (strcmp(arg, "even") == 0) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 635 | *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 636 | else { |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 637 | char *dash; |
| 638 | unsigned int low, high; |
| 639 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 640 | if (!isdigit((int)*arg)) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 641 | memprintf(err, "'%s' is not a valid number.\n", arg); |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 642 | return -1; |
| 643 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 644 | |
| 645 | low = high = str2uic(arg); |
| 646 | if ((dash = strchr(arg, '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 647 | high = ((!*(dash+1)) ? LONGBITS : str2uic(dash + 1)); |
| 648 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 649 | if (high < low) { |
| 650 | unsigned int swap = low; |
| 651 | low = high; |
| 652 | high = swap; |
| 653 | } |
| 654 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 655 | if (low < 1 || low > LONGBITS || high > LONGBITS) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 656 | memprintf(err, "'%s' is not a valid number/range." |
| 657 | " It supports numbers from 1 to %d.\n", |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 658 | arg, LONGBITS); |
| 659 | return 1; |
| 660 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 661 | |
| 662 | for (;low <= high; low++) |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 663 | *proc |= 1UL << (low-1); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 664 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 665 | |
Christopher Faulet | 5ab5177 | 2017-11-22 11:21:58 +0100 | [diff] [blame] | 666 | return 0; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 667 | } |
| 668 | |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 669 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 670 | /* Parse cpu sets. Each CPU set is either a unique number between 0 and |
| 671 | * <LONGBITS> or a range with two such numbers delimited by a dash |
| 672 | * ('-'). Multiple CPU numbers or ranges may be specified. On success, it |
| 673 | * returns 0. otherwise it returns 1 with an error message in <err>. |
| 674 | */ |
| 675 | static unsigned long parse_cpu_set(const char **args, unsigned long *cpu_set, char **err) |
| 676 | { |
| 677 | int cur_arg = 0; |
| 678 | |
| 679 | *cpu_set = 0; |
| 680 | while (*args[cur_arg]) { |
| 681 | char *dash; |
| 682 | unsigned int low, high; |
| 683 | |
| 684 | if (!isdigit((int)*args[cur_arg])) { |
| 685 | memprintf(err, "'%s' is not a CPU range.\n", args[cur_arg]); |
| 686 | return -1; |
| 687 | } |
| 688 | |
| 689 | low = high = str2uic(args[cur_arg]); |
| 690 | if ((dash = strchr(args[cur_arg], '-')) != NULL) |
Christopher Faulet | ff4121f | 2017-11-22 16:38:49 +0100 | [diff] [blame] | 691 | high = ((!*(dash+1)) ? LONGBITS-1 : str2uic(dash + 1)); |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 692 | |
| 693 | if (high < low) { |
| 694 | unsigned int swap = low; |
| 695 | low = high; |
| 696 | high = swap; |
| 697 | } |
| 698 | |
| 699 | if (high >= LONGBITS) { |
| 700 | memprintf(err, "supports CPU numbers from 0 to %d.\n", LONGBITS - 1); |
| 701 | return 1; |
| 702 | } |
| 703 | |
| 704 | while (low <= high) |
| 705 | *cpu_set |= 1UL << low++; |
| 706 | |
| 707 | cur_arg++; |
| 708 | } |
| 709 | return 0; |
| 710 | } |
David Carlier | 7e351ee | 2017-12-01 09:14:02 +0000 | [diff] [blame] | 711 | #endif |
| 712 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 713 | /* |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 714 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 715 | * any combination of : |
| 716 | * - ERR_ABORT: must abort ASAP |
| 717 | * - ERR_FATAL: we can continue parsing but not start the service |
| 718 | * - ERR_WARN: a warning has been emitted |
| 719 | * - ERR_ALERT: an alert has been emitted |
| 720 | * Only the two first ones can stop processing, the two others are just |
| 721 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 722 | */ |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 723 | 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] | 724 | { |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 725 | int err_code = 0; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 726 | char *errmsg = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 727 | |
| 728 | if (!strcmp(args[0], "global")) { /* new section */ |
| 729 | /* no option, nothing special to do */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 730 | alertif_too_many_args(0, file, linenum, args, &err_code); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 731 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 732 | } |
| 733 | else if (!strcmp(args[0], "daemon")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 734 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 735 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 736 | global.mode |= MODE_DAEMON; |
| 737 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 738 | else if (!strcmp(args[0], "master-worker")) { |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 739 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 740 | goto out; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 741 | if (*args[1]) { |
William Lallemand | 4cfede8 | 2017-11-24 22:02:34 +0100 | [diff] [blame] | 742 | if (!strcmp(args[1], "no-exit-on-failure")) { |
| 743 | global.tune.options |= GTUNE_NOEXIT_ONFAILURE; |
William Lallemand | 69f9b3b | 2017-06-01 17:38:54 +0200 | [diff] [blame] | 744 | } else { |
Tim Duesterhus | c578d9a | 2017-12-05 18:14:12 +0100 | [diff] [blame] | 745 | 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] | 746 | err_code |= ERR_ALERT | ERR_FATAL; |
| 747 | goto out; |
| 748 | } |
| 749 | } |
William Lallemand | 095ba4c | 2017-06-01 17:38:50 +0200 | [diff] [blame] | 750 | global.mode |= MODE_MWORKER; |
| 751 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 752 | else if (!strcmp(args[0], "debug")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 753 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 754 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 755 | global.mode |= MODE_DEBUG; |
| 756 | } |
| 757 | else if (!strcmp(args[0], "noepoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 758 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 759 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 760 | global.tune.options &= ~GTUNE_USE_EPOLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 761 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 762 | else if (!strcmp(args[0], "nokqueue")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 763 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 764 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 765 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 766 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 767 | else if (!strcmp(args[0], "nopoll")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 768 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 769 | goto out; |
Willy Tarreau | 43b7899 | 2009-01-25 15:42:27 +0100 | [diff] [blame] | 770 | global.tune.options &= ~GTUNE_USE_POLL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 771 | } |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 772 | else if (!strcmp(args[0], "nosplice")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 773 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 774 | goto out; |
Willy Tarreau | 3ab68cf | 2009-01-25 16:03:28 +0100 | [diff] [blame] | 775 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 776 | } |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 777 | else if (!strcmp(args[0], "nogetaddrinfo")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 778 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 779 | goto out; |
Nenad Merdanovic | 88afe03 | 2014-04-14 15:56:58 +0200 | [diff] [blame] | 780 | global.tune.options &= ~GTUNE_USE_GAI; |
| 781 | } |
Lukas Tribus | a0bcbdc | 2016-09-12 21:42:20 +0000 | [diff] [blame] | 782 | else if (!strcmp(args[0], "noreuseport")) { |
| 783 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 784 | goto out; |
| 785 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 786 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 787 | else if (!strcmp(args[0], "quiet")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 788 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 789 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 790 | global.mode |= MODE_QUIET; |
| 791 | } |
Olivier Houchard | 1599b80 | 2018-05-24 18:59:04 +0200 | [diff] [blame] | 792 | else if (!strcmp(args[0], "tune.runqueue-depth")) { |
| 793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 794 | goto out; |
| 795 | if (global.tune.runqueue_depth != 0) { |
| 796 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 797 | err_code |= ERR_ALERT; |
| 798 | goto out; |
| 799 | } |
| 800 | if (*(args[1]) == 0) { |
| 801 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 802 | err_code |= ERR_ALERT | ERR_FATAL; |
| 803 | goto out; |
| 804 | } |
| 805 | global.tune.runqueue_depth = atol(args[1]); |
| 806 | |
| 807 | } |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 808 | else if (!strcmp(args[0], "tune.maxpollevents")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 809 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 810 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 811 | if (global.tune.maxpollevents != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 812 | 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] | 813 | err_code |= ERR_ALERT; |
| 814 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 815 | } |
| 816 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 817 | 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] | 818 | err_code |= ERR_ALERT | ERR_FATAL; |
| 819 | goto out; |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 820 | } |
| 821 | global.tune.maxpollevents = atol(args[1]); |
| 822 | } |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 823 | else if (!strcmp(args[0], "tune.maxaccept")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 824 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 825 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 826 | if (global.tune.maxaccept != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 827 | 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] | 828 | err_code |= ERR_ALERT; |
| 829 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 830 | } |
| 831 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 832 | 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] | 833 | err_code |= ERR_ALERT | ERR_FATAL; |
| 834 | goto out; |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 835 | } |
| 836 | global.tune.maxaccept = atol(args[1]); |
| 837 | } |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 838 | else if (!strcmp(args[0], "tune.chksize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 839 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 840 | goto out; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 841 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 842 | 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] | 843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 844 | goto out; |
| 845 | } |
| 846 | global.tune.chksize = atol(args[1]); |
| 847 | } |
Willy Tarreau | b22fc30 | 2015-12-14 12:04:35 +0100 | [diff] [blame] | 848 | else if (!strcmp(args[0], "tune.recv_enough")) { |
| 849 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 850 | goto out; |
| 851 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 852 | 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] | 853 | err_code |= ERR_ALERT | ERR_FATAL; |
| 854 | goto out; |
| 855 | } |
| 856 | global.tune.recv_enough = atol(args[1]); |
| 857 | } |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 858 | else if (!strcmp(args[0], "tune.buffers.limit")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 859 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 860 | goto out; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 861 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 862 | 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] | 863 | err_code |= ERR_ALERT | ERR_FATAL; |
| 864 | goto out; |
| 865 | } |
| 866 | global.tune.buf_limit = atol(args[1]); |
| 867 | if (global.tune.buf_limit) { |
| 868 | if (global.tune.buf_limit < 3) |
| 869 | global.tune.buf_limit = 3; |
| 870 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 871 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 872 | } |
| 873 | } |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 874 | else if (!strcmp(args[0], "tune.buffers.reserve")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 875 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 876 | goto out; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 877 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 878 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto out; |
| 881 | } |
| 882 | global.tune.reserved_bufs = atol(args[1]); |
| 883 | if (global.tune.reserved_bufs < 2) |
| 884 | global.tune.reserved_bufs = 2; |
Willy Tarreau | 33cb065 | 2014-12-23 22:52:37 +0100 | [diff] [blame] | 885 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 886 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
Willy Tarreau | 1058ae7 | 2014-12-23 22:40:40 +0100 | [diff] [blame] | 887 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 888 | else if (!strcmp(args[0], "tune.bufsize")) { |
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 | 27a674e | 2009-08-17 07:23:33 +0200 | [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 | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
| 896 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | 9b69454 | 2015-09-28 13:49:53 +0200 | [diff] [blame] | 897 | if (global.tune.bufsize <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 898 | 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] | 899 | err_code |= ERR_ALERT | ERR_FATAL; |
| 900 | goto out; |
| 901 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 902 | } |
| 903 | else if (!strcmp(args[0], "tune.maxrewrite")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 904 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 905 | goto out; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 906 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 907 | 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] | 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto out; |
| 910 | } |
| 911 | global.tune.maxrewrite = atol(args[1]); |
Willy Tarreau | 2709784 | 2015-09-28 13:53:23 +0200 | [diff] [blame] | 912 | if (global.tune.maxrewrite < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 913 | 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] | 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto out; |
| 916 | } |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 917 | } |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 918 | else if (!strcmp(args[0], "tune.idletimer")) { |
| 919 | unsigned int idle; |
| 920 | const char *res; |
| 921 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 922 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 923 | goto out; |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 924 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 925 | 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] | 926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 927 | goto out; |
| 928 | } |
| 929 | |
| 930 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
| 931 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 932 | 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] | 933 | file, linenum, *res, args[0]); |
| 934 | err_code |= ERR_ALERT | ERR_FATAL; |
| 935 | goto out; |
| 936 | } |
| 937 | |
| 938 | if (idle > 65535) { |
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 | global.tune.idle_timer = idle; |
| 944 | } |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 945 | else if (!strcmp(args[0], "tune.rcvbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 946 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 947 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 948 | if (global.tune.client_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 949 | 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] | 950 | err_code |= ERR_ALERT; |
| 951 | goto out; |
| 952 | } |
| 953 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 954 | 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] | 955 | err_code |= ERR_ALERT | ERR_FATAL; |
| 956 | goto out; |
| 957 | } |
| 958 | global.tune.client_rcvbuf = atol(args[1]); |
| 959 | } |
| 960 | else if (!strcmp(args[0], "tune.rcvbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 961 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 962 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 963 | if (global.tune.server_rcvbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 964 | 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] | 965 | err_code |= ERR_ALERT; |
| 966 | goto out; |
| 967 | } |
| 968 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 969 | 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] | 970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 971 | goto out; |
| 972 | } |
| 973 | global.tune.server_rcvbuf = atol(args[1]); |
| 974 | } |
| 975 | else if (!strcmp(args[0], "tune.sndbuf.client")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 976 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 977 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 978 | if (global.tune.client_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 979 | 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] | 980 | err_code |= ERR_ALERT; |
| 981 | goto out; |
| 982 | } |
| 983 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 984 | 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] | 985 | err_code |= ERR_ALERT | ERR_FATAL; |
| 986 | goto out; |
| 987 | } |
| 988 | global.tune.client_sndbuf = atol(args[1]); |
| 989 | } |
| 990 | else if (!strcmp(args[0], "tune.sndbuf.server")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 991 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 992 | goto out; |
Willy Tarreau | e803de2 | 2010-01-21 17:43:04 +0100 | [diff] [blame] | 993 | if (global.tune.server_sndbuf != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 994 | 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] | 995 | err_code |= ERR_ALERT; |
| 996 | goto out; |
| 997 | } |
| 998 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 999 | 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] | 1000 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1001 | goto out; |
| 1002 | } |
| 1003 | global.tune.server_sndbuf = atol(args[1]); |
| 1004 | } |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1005 | else if (!strcmp(args[0], "tune.pipesize")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1006 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1007 | goto out; |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 1008 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1009 | 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] | 1010 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | global.tune.pipesize = atol(args[1]); |
| 1014 | } |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1015 | else if (!strcmp(args[0], "tune.http.cookielen")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1016 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1017 | goto out; |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 1018 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1019 | 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] | 1020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1021 | goto out; |
| 1022 | } |
| 1023 | global.tune.cookie_len = atol(args[1]) + 1; |
| 1024 | } |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 1025 | else if (!strcmp(args[0], "tune.http.logurilen")) { |
| 1026 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1027 | goto out; |
| 1028 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1029 | 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] | 1030 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1031 | goto out; |
| 1032 | } |
| 1033 | global.tune.requri_len = atol(args[1]) + 1; |
| 1034 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1035 | else if (!strcmp(args[0], "tune.http.maxhdr")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1036 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1037 | goto out; |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1038 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1039 | 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] | 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto out; |
| 1042 | } |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1043 | global.tune.max_http_hdr = atoi(args[1]); |
| 1044 | 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] | 1045 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 1046 | file, linenum, args[0]); |
Christopher Faulet | 50174f3 | 2017-06-21 16:31:35 +0200 | [diff] [blame] | 1047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1048 | goto out; |
| 1049 | } |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 1050 | } |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1051 | else if (!strcmp(args[0], "tune.comp.maxlevel")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1052 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1053 | goto out; |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1054 | if (*args[1]) { |
| 1055 | global.tune.comp_maxlevel = atoi(args[1]); |
| 1056 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1057 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1058 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1059 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1060 | goto out; |
| 1061 | } |
| 1062 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1063 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 1064 | file, linenum, args[0]); |
William Lallemand | f374783 | 2012-11-09 12:33:10 +0100 | [diff] [blame] | 1065 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1066 | goto out; |
| 1067 | } |
| 1068 | } |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1069 | else if (!strcmp(args[0], "tune.pattern.cache-size")) { |
| 1070 | if (*args[1]) { |
| 1071 | global.tune.pattern_cache = atoi(args[1]); |
| 1072 | if (global.tune.pattern_cache < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1073 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1074 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1079 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 1080 | file, linenum, args[0]); |
Willy Tarreau | f3045d2 | 2015-04-29 16:24:50 +0200 | [diff] [blame] | 1081 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1082 | goto out; |
| 1083 | } |
| 1084 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1085 | else if (!strcmp(args[0], "uid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1086 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1087 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1088 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1089 | 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] | 1090 | err_code |= ERR_ALERT; |
| 1091 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1092 | } |
| 1093 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1094 | 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] | 1095 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1096 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1097 | } |
Baptiste Assmann | 79fee6a | 2016-03-11 17:10:04 +0100 | [diff] [blame] | 1098 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1099 | 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] | 1100 | err_code |= ERR_WARN; |
| 1101 | goto out; |
| 1102 | } |
| 1103 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1104 | } |
| 1105 | else if (!strcmp(args[0], "gid")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1106 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1107 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1108 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1109 | 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] | 1110 | err_code |= ERR_ALERT; |
| 1111 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1112 | } |
| 1113 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1114 | 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] | 1115 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1116 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1117 | } |
Baptiste Assmann | 776e518 | 2016-03-11 17:21:15 +0100 | [diff] [blame] | 1118 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1119 | 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] | 1120 | err_code |= ERR_WARN; |
| 1121 | goto out; |
| 1122 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1123 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1124 | else if (!strcmp(args[0], "external-check")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1125 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1126 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 1127 | global.external_check = 1; |
| 1128 | } |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1129 | /* user/group name handling */ |
| 1130 | else if (!strcmp(args[0], "user")) { |
| 1131 | struct passwd *ha_user; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1132 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1133 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1134 | if (global.uid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1135 | 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] | 1136 | err_code |= ERR_ALERT; |
| 1137 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1138 | } |
| 1139 | errno = 0; |
| 1140 | ha_user = getpwnam(args[1]); |
| 1141 | if (ha_user != NULL) { |
| 1142 | global.uid = (int)ha_user->pw_uid; |
| 1143 | } |
| 1144 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1145 | 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] | 1146 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | else if (!strcmp(args[0], "group")) { |
| 1150 | struct group *ha_group; |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1151 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1152 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1153 | if (global.gid != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1154 | 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] | 1155 | err_code |= ERR_ALERT; |
| 1156 | goto out; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1157 | } |
| 1158 | errno = 0; |
| 1159 | ha_group = getgrnam(args[1]); |
| 1160 | if (ha_group != NULL) { |
| 1161 | global.gid = (int)ha_group->gr_gid; |
| 1162 | } |
| 1163 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1164 | 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] | 1165 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 95c20ac | 2007-03-25 15:39:23 +0200 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | /* end of user/group name handling*/ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1169 | else if (!strcmp(args[0], "nbproc")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1170 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1171 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1172 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1173 | 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] | 1174 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1175 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1176 | } |
| 1177 | global.nbproc = atol(args[1]); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1178 | if (global.nbproc < 1 || global.nbproc > LONGBITS) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1179 | ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1180 | file, linenum, args[0], LONGBITS, global.nbproc); |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 1181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1182 | goto out; |
| 1183 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1184 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1185 | else if (!strcmp(args[0], "nbthread")) { |
| 1186 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1187 | goto out; |
| 1188 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1189 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1191 | goto out; |
| 1192 | } |
| 1193 | global.nbthread = atol(args[1]); |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1194 | #ifndef USE_THREAD |
| 1195 | if (global.nbthread > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1196 | ha_alert("HAProxy is not compiled with threads support, please check build options for USE_THREAD.\n"); |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1197 | global.nbthread = 1; |
| 1198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1199 | goto out; |
| 1200 | } |
| 1201 | #endif |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1202 | if (global.nbthread < 1 || global.nbthread > MAX_THREADS) { |
| 1203 | ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", |
| 1204 | file, linenum, args[0], MAX_THREADS, global.nbthread); |
| 1205 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1206 | goto out; |
| 1207 | } |
Christopher Faulet | be0faa2 | 2017-08-29 15:37:10 +0200 | [diff] [blame] | 1208 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1209 | else if (!strcmp(args[0], "maxconn")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1210 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1211 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1212 | if (global.maxconn != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1213 | 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] | 1214 | err_code |= ERR_ALERT; |
| 1215 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1216 | } |
| 1217 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1218 | 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] | 1219 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1220 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1221 | } |
| 1222 | global.maxconn = atol(args[1]); |
| 1223 | #ifdef SYSTEM_MAXCONN |
| 1224 | if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1225 | 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] | 1226 | global.maxconn = DEFAULT_MAXCONN; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1227 | err_code |= ERR_ALERT; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1228 | } |
| 1229 | #endif /* SYSTEM_MAXCONN */ |
| 1230 | } |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1231 | else if (!strcmp(args[0], "ssl-server-verify")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1232 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1233 | goto out; |
Emeric Brun | 850efd5 | 2014-01-29 12:24:34 +0100 | [diff] [blame] | 1234 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1235 | 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] | 1236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1237 | goto out; |
| 1238 | } |
| 1239 | if (strcmp(args[1],"none") == 0) |
| 1240 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 1241 | else if (strcmp(args[1],"required") == 0) |
| 1242 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 1243 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1244 | 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] | 1245 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1246 | goto out; |
| 1247 | } |
| 1248 | } |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1249 | else if (!strcmp(args[0], "maxconnrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1250 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1251 | goto out; |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1252 | if (global.cps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1253 | 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] | 1254 | err_code |= ERR_ALERT; |
| 1255 | goto out; |
| 1256 | } |
| 1257 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1258 | 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] | 1259 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1260 | goto out; |
| 1261 | } |
| 1262 | global.cps_lim = atol(args[1]); |
| 1263 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1264 | else if (!strcmp(args[0], "maxsessrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1265 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1266 | goto out; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1267 | if (global.sps_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1268 | 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] | 1269 | err_code |= ERR_ALERT; |
| 1270 | goto out; |
| 1271 | } |
| 1272 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1273 | 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] | 1274 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1275 | goto out; |
| 1276 | } |
| 1277 | global.sps_lim = atol(args[1]); |
| 1278 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1279 | else if (!strcmp(args[0], "maxsslrate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1280 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1281 | goto out; |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1282 | if (global.ssl_lim != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1283 | 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] | 1284 | err_code |= ERR_ALERT; |
| 1285 | goto out; |
| 1286 | } |
| 1287 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1288 | 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] | 1289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1290 | goto out; |
| 1291 | } |
| 1292 | global.ssl_lim = atol(args[1]); |
| 1293 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1294 | else if (!strcmp(args[0], "maxcomprate")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1295 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1296 | goto out; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1297 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1298 | 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] | 1299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1300 | goto out; |
| 1301 | } |
| 1302 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 1303 | } |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1304 | else if (!strcmp(args[0], "maxpipes")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1305 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1306 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1307 | if (global.maxpipes != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1308 | 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] | 1309 | err_code |= ERR_ALERT; |
| 1310 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1311 | } |
| 1312 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1313 | 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] | 1314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1315 | goto out; |
Willy Tarreau | 3ec79b9 | 2009-01-18 20:39:42 +0100 | [diff] [blame] | 1316 | } |
| 1317 | global.maxpipes = atol(args[1]); |
| 1318 | } |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1319 | else if (!strcmp(args[0], "maxzlibmem")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1320 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1321 | goto out; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1322 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1323 | 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] | 1324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1325 | goto out; |
| 1326 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1327 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 1328 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1329 | else if (!strcmp(args[0], "maxcompcpuusage")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1330 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1331 | goto out; |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1332 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1333 | 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] | 1334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1335 | goto out; |
| 1336 | } |
| 1337 | compress_min_idle = 100 - atoi(args[1]); |
Willy Tarreau | cb2699a | 2013-01-24 16:25:38 +0100 | [diff] [blame] | 1338 | if (compress_min_idle > 100) { |
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 | } |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1343 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 1344 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1345 | else if (!strcmp(args[0], "ulimit-n")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1346 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1347 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1348 | if (global.rlimit_nofile != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1349 | 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] | 1350 | err_code |= ERR_ALERT; |
| 1351 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1352 | } |
| 1353 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1354 | 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] | 1355 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1356 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1357 | } |
| 1358 | global.rlimit_nofile = atol(args[1]); |
| 1359 | } |
| 1360 | else if (!strcmp(args[0], "chroot")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1361 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1362 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1363 | if (global.chroot != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1364 | 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] | 1365 | err_code |= ERR_ALERT; |
| 1366 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1367 | } |
| 1368 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1369 | 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] | 1370 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1371 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1372 | } |
| 1373 | global.chroot = strdup(args[1]); |
| 1374 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1375 | else if (!strcmp(args[0], "description")) { |
| 1376 | int i, len=0; |
| 1377 | char *d; |
| 1378 | |
| 1379 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1380 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 1381 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1382 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1383 | goto out; |
| 1384 | } |
| 1385 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1386 | for (i = 1; *args[i]; i++) |
| 1387 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1388 | |
| 1389 | if (global.desc) |
| 1390 | free(global.desc); |
| 1391 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 1392 | global.desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1393 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 1394 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 1395 | for (i = 2; *args[i]; i++) |
| 1396 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1397 | } |
| 1398 | else if (!strcmp(args[0], "node")) { |
| 1399 | int i; |
| 1400 | char c; |
| 1401 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1402 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1403 | goto out; |
| 1404 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1405 | for (i=0; args[1][i]; i++) { |
| 1406 | c = args[1][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 1407 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1408 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1409 | break; |
| 1410 | } |
| 1411 | |
| 1412 | if (!i || args[1][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1413 | ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 1414 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 1415 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1416 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1417 | goto out; |
| 1418 | } |
| 1419 | |
| 1420 | if (global.node) |
| 1421 | free(global.node); |
| 1422 | |
| 1423 | global.node = strdup(args[1]); |
| 1424 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1425 | else if (!strcmp(args[0], "pidfile")) { |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1426 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1427 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1428 | if (global.pidfile != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1429 | 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] | 1430 | err_code |= ERR_ALERT; |
| 1431 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1432 | } |
| 1433 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1434 | 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] | 1435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1436 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1437 | } |
| 1438 | global.pidfile = strdup(args[1]); |
| 1439 | } |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1440 | else if (!strcmp(args[0], "unix-bind")) { |
| 1441 | int cur_arg = 1; |
| 1442 | while (*(args[cur_arg])) { |
| 1443 | if (!strcmp(args[cur_arg], "prefix")) { |
| 1444 | if (global.unix_bind.prefix != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1445 | 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] | 1446 | err_code |= ERR_ALERT; |
| 1447 | cur_arg += 2; |
| 1448 | continue; |
| 1449 | } |
| 1450 | |
| 1451 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1452 | 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] | 1453 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1454 | goto out; |
| 1455 | } |
| 1456 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 1457 | cur_arg += 2; |
| 1458 | continue; |
| 1459 | } |
| 1460 | |
| 1461 | if (!strcmp(args[cur_arg], "mode")) { |
| 1462 | |
| 1463 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 1464 | cur_arg += 2; |
| 1465 | continue; |
| 1466 | } |
| 1467 | |
| 1468 | if (!strcmp(args[cur_arg], "uid")) { |
| 1469 | |
| 1470 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 1471 | cur_arg += 2; |
| 1472 | continue; |
| 1473 | } |
| 1474 | |
| 1475 | if (!strcmp(args[cur_arg], "gid")) { |
| 1476 | |
| 1477 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 1478 | cur_arg += 2; |
| 1479 | continue; |
| 1480 | } |
| 1481 | |
| 1482 | if (!strcmp(args[cur_arg], "user")) { |
| 1483 | struct passwd *user; |
| 1484 | |
| 1485 | user = getpwnam(args[cur_arg + 1]); |
| 1486 | if (!user) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1487 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 1488 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | global.unix_bind.ux.uid = user->pw_uid; |
| 1494 | cur_arg += 2; |
| 1495 | continue; |
| 1496 | } |
| 1497 | |
| 1498 | if (!strcmp(args[cur_arg], "group")) { |
| 1499 | struct group *group; |
| 1500 | |
| 1501 | group = getgrnam(args[cur_arg + 1]); |
| 1502 | if (!group) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1503 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 1504 | file, linenum, args[0], args[cur_arg + 1 ]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | global.unix_bind.ux.gid = group->gr_gid; |
| 1510 | cur_arg += 2; |
| 1511 | continue; |
| 1512 | } |
| 1513 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1514 | ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
| 1515 | file, linenum, args[0]); |
Emeric Brun | ed76092 | 2010-10-22 17:59:25 +0200 | [diff] [blame] | 1516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1517 | goto out; |
| 1518 | } |
| 1519 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 1520 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 1521 | if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 1522 | 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] | 1523 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 9b435bc | 2013-03-06 15:02:49 +0100 | [diff] [blame] | 1524 | goto out; |
| 1525 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1526 | } |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1527 | else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */ |
| 1528 | char *name; |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1529 | |
| 1530 | if (global.log_send_hostname != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1531 | 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] | 1532 | err_code |= ERR_ALERT; |
| 1533 | goto out; |
| 1534 | } |
| 1535 | |
| 1536 | if (*(args[1])) |
| 1537 | name = args[1]; |
| 1538 | else |
| 1539 | name = hostname; |
| 1540 | |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1541 | free(global.log_send_hostname); |
Dragan Dosen | c8cfa7b | 2015-09-28 13:28:21 +0200 | [diff] [blame] | 1542 | global.log_send_hostname = strdup(name); |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 1543 | } |
Baptiste Assmann | 6bc8936 | 2015-08-23 09:22:25 +0200 | [diff] [blame] | 1544 | else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */ |
| 1545 | if (global.server_state_base != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1546 | 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] | 1547 | err_code |= ERR_ALERT; |
| 1548 | goto out; |
| 1549 | } |
| 1550 | |
| 1551 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1552 | 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] | 1553 | err_code |= ERR_FATAL; |
| 1554 | goto out; |
| 1555 | } |
| 1556 | |
| 1557 | global.server_state_base = strdup(args[1]); |
| 1558 | } |
Baptiste Assmann | e088226 | 2015-08-23 09:54:31 +0200 | [diff] [blame] | 1559 | else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */ |
| 1560 | if (global.server_state_file != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1561 | 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] | 1562 | err_code |= ERR_ALERT; |
| 1563 | goto out; |
| 1564 | } |
| 1565 | |
| 1566 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1567 | 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] | 1568 | err_code |= ERR_FATAL; |
| 1569 | goto out; |
| 1570 | } |
| 1571 | |
| 1572 | global.server_state_file = strdup(args[1]); |
| 1573 | } |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1574 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1575 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1576 | goto out; |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1577 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1578 | 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] | 1579 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1580 | goto out; |
| 1581 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 1582 | chunk_destroy(&global.log_tag); |
| 1583 | chunk_initstr(&global.log_tag, strdup(args[1])); |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 1584 | } |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1585 | 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] | 1586 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1587 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1588 | if (global.spread_checks != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1589 | 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] | 1590 | err_code |= ERR_ALERT; |
| 1591 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1592 | } |
| 1593 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1594 | 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] | 1595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1596 | goto out; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1597 | } |
| 1598 | global.spread_checks = atol(args[1]); |
| 1599 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1600 | 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] | 1601 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1602 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1603 | } |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1604 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 1605 | const char *err; |
| 1606 | unsigned int val; |
| 1607 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 1608 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1609 | goto out; |
Willy Tarreau | 1746eec | 2014-04-25 10:46:47 +0200 | [diff] [blame] | 1610 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1611 | 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] | 1612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1613 | goto out; |
| 1614 | } |
| 1615 | |
| 1616 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 1617 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1618 | 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] | 1619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1620 | } |
| 1621 | global.max_spread_checks = val; |
| 1622 | if (global.max_spread_checks < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1623 | 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] | 1624 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1625 | } |
| 1626 | } |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1627 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 1628 | /* map a process list to a CPU set */ |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1629 | #ifdef USE_CPU_AFFINITY |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1630 | char *slash; |
| 1631 | unsigned long proc = 0, thread = 0, cpus; |
| 1632 | int i, j, n, autoinc; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1633 | |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1634 | if (!*args[1] || !*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1635 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 1636 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 1637 | " followed by a list of CPU ranges with numbers from 0 to %d.\n", |
| 1638 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1639 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1640 | goto out; |
| 1641 | } |
Christopher Faulet | 1dcb9cb | 2017-11-22 10:24:40 +0100 | [diff] [blame] | 1642 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1643 | if ((slash = strchr(args[1], '/')) != NULL) |
| 1644 | *slash = 0; |
| 1645 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1646 | if (parse_process_number(args[1], &proc, &autoinc, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1647 | 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] | 1648 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1649 | goto out; |
| 1650 | } |
| 1651 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1652 | if (slash) { |
| 1653 | if (parse_process_number(slash+1, &thread, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1654 | 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] | 1655 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1656 | goto out; |
| 1657 | } |
| 1658 | *slash = '/'; |
| 1659 | |
| 1660 | if (autoinc && my_popcountl(proc) != 1 && my_popcountl(thread) != 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1661 | ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind " |
| 1662 | "a process range _AND_ a thread range\n", |
| 1663 | file, linenum, args[0], args[1]); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1664 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1665 | goto out; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1669 | if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1670 | 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] | 1671 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1672 | goto out; |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1673 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1674 | |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1675 | if (autoinc && |
| 1676 | my_popcountl(proc) != my_popcountl(cpus) && |
| 1677 | my_popcountl(thread) != my_popcountl(cpus)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1678 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1679 | "must have the same size to be automatically bound\n", |
| 1680 | file, linenum, args[0]); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1681 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1682 | goto out; |
| 1683 | } |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1684 | |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1685 | for (i = n = 0; i < LONGBITS; i++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1686 | /* No mapping for this process */ |
| 1687 | if (!(proc & (1UL << i))) |
| 1688 | continue; |
| 1689 | |
| 1690 | /* Mapping at the process level */ |
| 1691 | if (!thread) { |
| 1692 | if (!autoinc) |
| 1693 | global.cpu_map.proc[i] = cpus; |
| 1694 | else { |
| 1695 | n += my_ffsl(cpus >> n); |
| 1696 | global.cpu_map.proc[i] = (1UL << (n-1)); |
| 1697 | } |
| 1698 | continue; |
| 1699 | } |
| 1700 | |
| 1701 | /* Mapping at the thread level */ |
Willy Tarreau | 421f02e | 2018-01-20 18:19:22 +0100 | [diff] [blame] | 1702 | for (j = 0; j < MAX_THREADS; j++) { |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1703 | /* Np mapping for this thread */ |
| 1704 | if (!(thread & (1UL << j))) |
| 1705 | continue; |
| 1706 | |
| 1707 | if (!autoinc) |
| 1708 | global.cpu_map.thread[i][j] = cpus; |
| 1709 | else { |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1710 | n += my_ffsl(cpus >> n); |
Christopher Faulet | cb6a945 | 2017-11-22 16:50:41 +0100 | [diff] [blame] | 1711 | global.cpu_map.thread[i][j] = (1UL << (n-1)); |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1712 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 1713 | } |
| 1714 | } |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1715 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1716 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1717 | file, linenum, args[0]); |
Willy Tarreau | fc6c032 | 2012-11-16 16:12:27 +0100 | [diff] [blame] | 1718 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1719 | goto out; |
Christopher Faulet | 6251902 | 2017-10-16 15:49:32 +0200 | [diff] [blame] | 1720 | #endif /* ! USE_CPU_AFFINITY */ |
| 1721 | } |
Willy Tarreau | 1d54972 | 2016-02-16 12:41:57 +0100 | [diff] [blame] | 1722 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1723 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1724 | goto out; |
| 1725 | |
| 1726 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1727 | 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] | 1728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1729 | goto out; |
| 1730 | } |
| 1731 | |
| 1732 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1733 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1734 | 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] | 1735 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1736 | goto out; |
| 1737 | } |
| 1738 | } |
| 1739 | else if (!strcmp(args[0], "unsetenv")) { |
| 1740 | int arg; |
| 1741 | |
| 1742 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1743 | 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] | 1744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1745 | goto out; |
| 1746 | } |
| 1747 | |
| 1748 | for (arg = 1; *args[arg]; arg++) { |
| 1749 | if (unsetenv(args[arg]) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1750 | 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] | 1751 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1752 | goto out; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | else if (!strcmp(args[0], "resetenv")) { |
| 1757 | extern char **environ; |
| 1758 | char **env = environ; |
| 1759 | |
| 1760 | /* args contain variable names to keep, one per argument */ |
| 1761 | while (*env) { |
| 1762 | int arg; |
| 1763 | |
| 1764 | /* look for current variable in among all those we want to keep */ |
| 1765 | for (arg = 1; *args[arg]; arg++) { |
| 1766 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1767 | (*env)[strlen(args[arg])] == '=') |
| 1768 | break; |
| 1769 | } |
| 1770 | |
| 1771 | /* delete this variable */ |
| 1772 | if (!*args[arg]) { |
| 1773 | char *delim = strchr(*env, '='); |
| 1774 | |
| 1775 | if (!delim || delim - *env >= trash.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1776 | 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] | 1777 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1778 | goto out; |
| 1779 | } |
| 1780 | |
| 1781 | memcpy(trash.str, *env, delim - *env); |
| 1782 | trash.str[delim - *env] = 0; |
| 1783 | |
| 1784 | if (unsetenv(trash.str) != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1785 | 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] | 1786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1787 | goto out; |
| 1788 | } |
| 1789 | } |
| 1790 | else |
| 1791 | env++; |
| 1792 | } |
| 1793 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1794 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1795 | struct cfg_kw_list *kwl; |
| 1796 | int index; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1797 | int rc; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1798 | |
| 1799 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1800 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1801 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1802 | continue; |
| 1803 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 1804 | 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] | 1805 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1806 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1807 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1808 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1809 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1810 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1811 | err_code |= ERR_WARN; |
| 1812 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 1813 | } |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1814 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1819 | 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] | 1820 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1821 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1822 | |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1823 | out: |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 1824 | free(errmsg); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 1825 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 1828 | void init_default_instance() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1829 | { |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 1830 | init_new_proxy(&defproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1831 | defproxy.mode = PR_MODE_TCP; |
| 1832 | defproxy.state = PR_STNEW; |
| 1833 | defproxy.maxconn = cfg_maxpconn; |
| 1834 | defproxy.conn_retries = CONN_RETRIES; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 1835 | defproxy.redispatch_after = 0; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 1836 | defproxy.lbprm.chash.balance_factor = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1837 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 1838 | defproxy.defsrv.check.inter = DEF_CHKINTR; |
| 1839 | defproxy.defsrv.check.fastinter = 0; |
| 1840 | defproxy.defsrv.check.downinter = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1841 | defproxy.defsrv.agent.inter = DEF_CHKINTR; |
| 1842 | defproxy.defsrv.agent.fastinter = 0; |
| 1843 | defproxy.defsrv.agent.downinter = 0; |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1844 | defproxy.defsrv.check.rise = DEF_RISETIME; |
| 1845 | defproxy.defsrv.check.fall = DEF_FALLTIME; |
| 1846 | defproxy.defsrv.agent.rise = DEF_AGENT_RISETIME; |
| 1847 | defproxy.defsrv.agent.fall = DEF_AGENT_FALLTIME; |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 1848 | defproxy.defsrv.check.port = 0; |
Simon Horman | d60d691 | 2013-11-25 10:46:36 +0900 | [diff] [blame] | 1849 | defproxy.defsrv.agent.port = 0; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 1850 | defproxy.defsrv.maxqueue = 0; |
| 1851 | defproxy.defsrv.minconn = 0; |
| 1852 | defproxy.defsrv.maxconn = 0; |
| 1853 | defproxy.defsrv.slowstart = 0; |
| 1854 | defproxy.defsrv.onerror = DEF_HANA_ONERR; |
| 1855 | defproxy.defsrv.consecutive_errors_limit = DEF_HANA_ERRLIMIT; |
| 1856 | defproxy.defsrv.uweight = defproxy.defsrv.iweight = 1; |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 1857 | |
| 1858 | defproxy.email_alert.level = LOG_ALERT; |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 1859 | defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1860 | } |
| 1861 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1862 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1863 | /* This function createss a new req* or rsp* rule to the proxy. It compiles the |
| 1864 | * regex and may return the ERR_WARN bit, and error bits such as ERR_ALERT and |
| 1865 | * ERR_FATAL in case of error. |
| 1866 | */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1867 | static int create_cond_regex_rule(const char *file, int line, |
| 1868 | struct proxy *px, int dir, int action, int flags, |
| 1869 | const char *cmd, const char *reg, const char *repl, |
| 1870 | const char **cond_start) |
| 1871 | { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1872 | struct my_regex *preg = NULL; |
Willy Tarreau | b7451bb | 2012-04-27 12:38:15 +0200 | [diff] [blame] | 1873 | char *errmsg = NULL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1874 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1875 | char *error; |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1876 | int ret_code = 0; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1877 | struct acl_cond *cond = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1878 | int cs; |
| 1879 | int cap; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1880 | |
| 1881 | if (px == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1882 | 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] | 1883 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1884 | goto err; |
| 1885 | } |
| 1886 | |
| 1887 | if (*reg == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1888 | 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] | 1889 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1890 | goto err; |
| 1891 | } |
| 1892 | |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 1893 | 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] | 1894 | ret_code |= ERR_WARN; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1895 | |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1896 | if (cond_start && |
| 1897 | (strcmp(*cond_start, "if") == 0 || strcmp(*cond_start, "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 1898 | 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] | 1899 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 1900 | file, line, cmd, errmsg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1901 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1902 | goto err; |
| 1903 | } |
| 1904 | } |
| 1905 | else if (cond_start && **cond_start) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1906 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 1907 | file, line, cmd, *cond_start); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1908 | ret_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1909 | goto err; |
| 1910 | } |
| 1911 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1912 | ret_code |= warnif_cond_conflicts(cond, |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 1913 | (dir == SMP_OPT_DIR_REQ) ? |
| 1914 | ((px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR) : |
| 1915 | ((px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR), |
| 1916 | file, line); |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 1917 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1918 | preg = calloc(1, sizeof(*preg)); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1919 | if (!preg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1920 | 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] | 1921 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1922 | goto err; |
| 1923 | } |
| 1924 | |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1925 | cs = !(flags & REG_ICASE); |
| 1926 | cap = !(flags & REG_NOSUB); |
| 1927 | error = NULL; |
| 1928 | if (!regex_comp(reg, preg, cs, cap, &error)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1929 | 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] | 1930 | free(error); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1931 | ret_code = ERR_ALERT | ERR_FATAL; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1932 | goto err; |
| 1933 | } |
| 1934 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1935 | 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] | 1936 | preg, action, repl ? strdup(repl) : NULL, cond); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1937 | if (repl && err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1938 | ha_alert("parsing [%s:%d] : '%s' : invalid character or unterminated sequence in replacement string near '%c'.\n", |
| 1939 | file, line, cmd, *err); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1940 | ret_code |= ERR_ALERT | ERR_FATAL; |
| 1941 | goto err_free; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1944 | 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] | 1945 | ret_code |= ERR_WARN; |
| 1946 | |
| 1947 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1948 | |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1949 | err_free: |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 1950 | regex_free(preg); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1951 | err: |
| 1952 | free(preg); |
Willy Tarreau | 63af98d | 2014-05-18 08:11:41 +0200 | [diff] [blame] | 1953 | free(errmsg); |
| 1954 | return ret_code; |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1957 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 1958 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 1959 | * Returns the error code, 0 if OK, or any combination of : |
| 1960 | * - ERR_ABORT: must abort ASAP |
| 1961 | * - ERR_FATAL: we can continue parsing but not start the service |
| 1962 | * - ERR_WARN: a warning has been emitted |
| 1963 | * - ERR_ALERT: an alert has been emitted |
| 1964 | * Only the two first ones can stop processing, the two others are just |
| 1965 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1966 | */ |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1967 | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
| 1968 | { |
| 1969 | static struct peers *curpeers = NULL; |
| 1970 | struct peer *newpeer = NULL; |
| 1971 | const char *err; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1972 | struct bind_conf *bind_conf; |
| 1973 | struct listener *l; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1974 | int err_code = 0; |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 1975 | char *errmsg = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1976 | |
| 1977 | if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1978 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1979 | 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] | 1980 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1981 | goto out; |
| 1982 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1983 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 1984 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1985 | goto out; |
| 1986 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1987 | err = invalid_char(args[1]); |
| 1988 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1989 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 1990 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 5498472 | 2014-02-16 08:20:13 +0100 | [diff] [blame] | 1991 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 0dbbf31 | 2013-03-05 11:31:55 +0100 | [diff] [blame] | 1992 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 1995 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 1996 | /* |
| 1997 | * If there are two proxies with the same name only following |
| 1998 | * combinations are allowed: |
| 1999 | */ |
| 2000 | if (strcmp(curpeers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2001 | ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", |
| 2002 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2003 | err_code |= ERR_ALERT | ERR_FATAL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2004 | } |
| 2005 | } |
| 2006 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2007 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2008 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2009 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2010 | goto out; |
| 2011 | } |
| 2012 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2013 | curpeers->next = cfg_peers; |
| 2014 | cfg_peers = curpeers; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2015 | curpeers->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2016 | curpeers->conf.line = linenum; |
| 2017 | curpeers->last_change = now.tv_sec; |
| 2018 | curpeers->id = strdup(args[1]); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2019 | curpeers->state = PR_STNEW; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2020 | } |
| 2021 | else if (strcmp(args[0], "peer") == 0) { /* peer definition */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2022 | struct sockaddr_storage *sk; |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2023 | int port1, port2; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2024 | struct protocol *proto; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2025 | |
| 2026 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2027 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2028 | file, linenum, args[0]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2029 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2030 | goto out; |
| 2031 | } |
| 2032 | |
| 2033 | err = invalid_char(args[1]); |
| 2034 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2035 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2036 | file, linenum, *err, args[1]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2037 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2038 | goto out; |
| 2039 | } |
| 2040 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2041 | if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2042 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2043 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2044 | goto out; |
| 2045 | } |
| 2046 | |
| 2047 | /* the peers are linked backwards first */ |
| 2048 | curpeers->count++; |
| 2049 | newpeer->next = curpeers->remote; |
| 2050 | curpeers->remote = newpeer; |
Willy Tarreau | 8113a5d | 2012-10-04 08:01:43 +0200 | [diff] [blame] | 2051 | newpeer->conf.file = strdup(file); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2052 | newpeer->conf.line = linenum; |
| 2053 | |
| 2054 | newpeer->last_change = now.tv_sec; |
| 2055 | newpeer->id = strdup(args[1]); |
| 2056 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2057 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2058 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2059 | 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] | 2060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2061 | goto out; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2062 | } |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2063 | |
| 2064 | proto = protocol_by_family(sk->ss_family); |
| 2065 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2066 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 2067 | file, linenum, args[0], args[1]); |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2069 | goto out; |
| 2070 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2071 | |
| 2072 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2073 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2074 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2076 | goto out; |
| 2077 | } |
| 2078 | |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2079 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2080 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2081 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2083 | goto out; |
| 2084 | } |
Willy Tarreau | 2aa3880 | 2013-02-20 19:20:59 +0100 | [diff] [blame] | 2085 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2086 | newpeer->addr = *sk; |
Willy Tarreau | b36487e | 2013-03-10 18:37:42 +0100 | [diff] [blame] | 2087 | newpeer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2088 | newpeer->xprt = xprt_get(XPRT_RAW); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 2089 | newpeer->sock_init_arg = NULL; |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2090 | HA_SPIN_INIT(&newpeer->lock); |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 2091 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2092 | if (strcmp(newpeer->id, localpeer) == 0) { |
| 2093 | /* Current is local peer, it define a frontend */ |
| 2094 | newpeer->local = 1; |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 2095 | cfg_peers->local = newpeer; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2096 | |
| 2097 | if (!curpeers->peers_fe) { |
| 2098 | if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2099 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2100 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2101 | goto out; |
| 2102 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2103 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 2104 | init_new_proxy(curpeers->peers_fe); |
| 2105 | curpeers->peers_fe->parent = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2106 | curpeers->peers_fe->id = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2107 | curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); |
| 2108 | curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; |
Willy Tarreau | 91d9628 | 2015-03-13 15:47:26 +0100 | [diff] [blame] | 2109 | peers_setup_frontend(curpeers->peers_fe); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2110 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2111 | 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] | 2112 | |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2113 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
| 2114 | if (errmsg && *errmsg) { |
| 2115 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2116 | 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] | 2117 | } |
| 2118 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2119 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
| 2120 | file, linenum, args[0], args[1], args[2]); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2121 | err_code |= ERR_FATAL; |
| 2122 | goto out; |
| 2123 | } |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2124 | |
| 2125 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
Willy Tarreau | acf3bf9 | 2013-01-18 10:51:07 +0100 | [diff] [blame] | 2126 | l->maxaccept = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2127 | l->maxconn = curpeers->peers_fe->maxconn; |
| 2128 | l->backlog = curpeers->peers_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 2129 | l->accept = session_accept_fd; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 2130 | l->analysers |= curpeers->peers_fe->fe_req_ana; |
| 2131 | l->default_target = curpeers->peers_fe->default_target; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2132 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 2133 | global.maxsock += l->maxconn; |
| 2134 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2135 | } |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2136 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2137 | ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d.\n", |
| 2138 | file, linenum, args[0], args[1], |
| 2139 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line); |
Willy Tarreau | 8b8fd56 | 2013-01-18 11:12:27 +0100 | [diff] [blame] | 2140 | err_code |= ERR_FATAL; |
| 2141 | goto out; |
| 2142 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2143 | } |
| 2144 | } /* neither "peer" nor "peers" */ |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 2145 | else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ |
| 2146 | curpeers->state = PR_STSTOPPED; |
| 2147 | } |
| 2148 | else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ |
| 2149 | curpeers->state = PR_STNEW; |
| 2150 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2151 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2152 | 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] | 2153 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2154 | goto out; |
| 2155 | } |
| 2156 | |
| 2157 | out: |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 2158 | free(errmsg); |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 2159 | return err_code; |
| 2160 | } |
| 2161 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2162 | /* |
| 2163 | * Parse a <resolvers> section. |
| 2164 | * Returns the error code, 0 if OK, or any combination of : |
| 2165 | * - ERR_ABORT: must abort ASAP |
| 2166 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2167 | * - ERR_WARN: a warning has been emitted |
| 2168 | * - ERR_ALERT: an alert has been emitted |
| 2169 | * Only the two first ones can stop processing, the two others are just |
| 2170 | * indicators. |
| 2171 | */ |
| 2172 | int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) |
| 2173 | { |
| 2174 | static struct dns_resolvers *curr_resolvers = NULL; |
| 2175 | struct dns_nameserver *newnameserver = NULL; |
| 2176 | const char *err; |
| 2177 | int err_code = 0; |
| 2178 | char *errmsg = NULL; |
| 2179 | |
| 2180 | if (strcmp(args[0], "resolvers") == 0) { /* new resolvers section */ |
| 2181 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2182 | 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] | 2183 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2184 | goto out; |
| 2185 | } |
| 2186 | |
| 2187 | err = invalid_char(args[1]); |
| 2188 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2189 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2190 | file, linenum, *err, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2191 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2192 | goto out; |
| 2193 | } |
| 2194 | |
| 2195 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 2196 | /* Error if two resolvers owns the same name */ |
| 2197 | if (strcmp(curr_resolvers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2198 | ha_alert("Parsing [%s:%d]: resolvers '%s' has same name as another resolvers (declared at %s:%d).\n", |
| 2199 | file, linenum, args[1], curr_resolvers->conf.file, curr_resolvers->conf.line); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2200 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2201 | } |
| 2202 | } |
| 2203 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2204 | if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2205 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2206 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2207 | goto out; |
| 2208 | } |
| 2209 | |
| 2210 | /* default values */ |
| 2211 | LIST_ADDQ(&dns_resolvers, &curr_resolvers->list); |
| 2212 | curr_resolvers->conf.file = strdup(file); |
| 2213 | curr_resolvers->conf.line = linenum; |
| 2214 | curr_resolvers->id = strdup(args[1]); |
| 2215 | curr_resolvers->query_ids = EB_ROOT; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2216 | /* default maximum response size */ |
| 2217 | curr_resolvers->accepted_payload_size = 512; |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2218 | /* default hold period for nx, other, refuse and timeout is 30s */ |
| 2219 | curr_resolvers->hold.nx = 30000; |
| 2220 | curr_resolvers->hold.other = 30000; |
| 2221 | curr_resolvers->hold.refused = 30000; |
| 2222 | curr_resolvers->hold.timeout = 30000; |
Baptiste Assmann | 686408b | 2017-08-18 10:15:42 +0200 | [diff] [blame] | 2223 | curr_resolvers->hold.obsolete = 0; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2224 | /* default hold period for valid is 10s */ |
Baptiste Assmann | 4c5490a | 2015-07-14 21:42:49 +0200 | [diff] [blame] | 2225 | curr_resolvers->hold.valid = 10000; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2226 | curr_resolvers->timeout.resolve = 1000; |
| 2227 | curr_resolvers->timeout.retry = 1000; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2228 | curr_resolvers->resolve_retries = 3; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2229 | curr_resolvers->nb_nameservers = 0; |
| 2230 | LIST_INIT(&curr_resolvers->nameservers); |
| 2231 | LIST_INIT(&curr_resolvers->resolutions.curr); |
| 2232 | LIST_INIT(&curr_resolvers->resolutions.wait); |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2233 | HA_SPIN_INIT(&curr_resolvers->lock); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2234 | } |
| 2235 | else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */ |
| 2236 | struct sockaddr_storage *sk; |
| 2237 | int port1, port2; |
| 2238 | struct protocol *proto; |
| 2239 | |
| 2240 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2241 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2242 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2244 | goto out; |
| 2245 | } |
| 2246 | |
| 2247 | err = invalid_char(args[1]); |
| 2248 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2249 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2250 | file, linenum, *err, args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2252 | goto out; |
| 2253 | } |
| 2254 | |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2255 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2256 | /* Error if two resolvers owns the same name */ |
| 2257 | if (strcmp(newnameserver->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2258 | 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] | 2259 | file, linenum, args[1], newnameserver->conf.file, newnameserver->conf.line); |
Baptiste Assmann | a315c55 | 2015-11-02 22:55:49 +0100 | [diff] [blame] | 2260 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2261 | } |
| 2262 | } |
| 2263 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2264 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2265 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2266 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2267 | goto out; |
| 2268 | } |
| 2269 | |
| 2270 | /* the nameservers are linked backward first */ |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2271 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2272 | newnameserver->resolvers = curr_resolvers; |
| 2273 | newnameserver->conf.file = strdup(file); |
| 2274 | newnameserver->conf.line = linenum; |
| 2275 | newnameserver->id = strdup(args[1]); |
| 2276 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2277 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2278 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2279 | 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] | 2280 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2281 | goto out; |
| 2282 | } |
| 2283 | |
| 2284 | proto = protocol_by_family(sk->ss_family); |
| 2285 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2286 | 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] | 2287 | file, linenum, args[0], args[1]); |
| 2288 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2289 | goto out; |
| 2290 | } |
| 2291 | |
| 2292 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2293 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2294 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2296 | goto out; |
| 2297 | } |
| 2298 | |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2299 | if (!port1 && !port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2300 | ha_alert("parsing [%s:%d] : '%s %s' : no UDP port specified\n", |
| 2301 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 7f43fa9 | 2016-01-21 00:59:46 +0100 | [diff] [blame] | 2302 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2303 | goto out; |
| 2304 | } |
| 2305 | |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2306 | newnameserver->addr = *sk; |
| 2307 | } |
Ben Draut | 44e609b | 2018-05-29 15:40:08 -0600 | [diff] [blame] | 2308 | else if (strcmp(args[0], "parse-resolv-conf") == 0) { |
| 2309 | const char *whitespace = "\r\n\t "; |
| 2310 | char *resolv_line = NULL; |
| 2311 | int resolv_linenum = 0; |
| 2312 | FILE *f = NULL; |
| 2313 | char *address = NULL; |
| 2314 | struct sockaddr_storage *sk = NULL; |
| 2315 | struct protocol *proto; |
| 2316 | int duplicate_name = 0; |
| 2317 | |
| 2318 | if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) { |
| 2319 | ha_alert("parsing [%s:%d] : out of memory.\n", |
| 2320 | file, linenum); |
| 2321 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2322 | goto resolv_out; |
| 2323 | } |
| 2324 | |
| 2325 | if ((f = fopen("/etc/resolv.conf", "r")) == NULL) { |
| 2326 | ha_alert("parsing [%s:%d] : failed to open /etc/resolv.conf.\n", |
| 2327 | file, linenum); |
| 2328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2329 | goto resolv_out; |
| 2330 | } |
| 2331 | |
| 2332 | sk = calloc(1, sizeof(*sk)); |
| 2333 | if (sk == NULL) { |
| 2334 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", |
| 2335 | resolv_linenum); |
| 2336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2337 | goto resolv_out; |
| 2338 | } |
| 2339 | |
| 2340 | while (fgets(resolv_line, LINESIZE, f) != NULL) { |
| 2341 | resolv_linenum++; |
| 2342 | if (strncmp(resolv_line, "nameserver", 10) != 0) |
| 2343 | continue; |
| 2344 | |
| 2345 | address = strtok(resolv_line + 10, whitespace); |
| 2346 | if (address == resolv_line + 10) |
| 2347 | continue; |
| 2348 | |
| 2349 | if (address == NULL) { |
| 2350 | ha_warning("parsing [/etc/resolv.conf:%d] : nameserver line is missing address.\n", |
| 2351 | resolv_linenum); |
| 2352 | err_code |= ERR_WARN; |
| 2353 | continue; |
| 2354 | } |
| 2355 | |
| 2356 | duplicate_name = 0; |
| 2357 | list_for_each_entry(newnameserver, &curr_resolvers->nameservers, list) { |
| 2358 | if (strcmp(newnameserver->id, address) == 0) { |
| 2359 | 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", |
| 2360 | resolv_linenum, address, newnameserver->conf.file, newnameserver->conf.line); |
| 2361 | err_code |= ERR_WARN; |
| 2362 | duplicate_name = 1; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | if (duplicate_name) |
| 2367 | continue; |
| 2368 | |
| 2369 | memset(sk, 0, sizeof(*sk)); |
| 2370 | sk = str2ip2(address, sk, 1); |
| 2371 | if (!sk) { |
| 2372 | ha_warning("parsing [/etc/resolv.conf:%d] : address '%s' could not be recognized, namerserver will be excluded.\n", |
| 2373 | resolv_linenum, address); |
| 2374 | err_code |= ERR_WARN; |
| 2375 | continue; |
| 2376 | } |
| 2377 | |
| 2378 | set_host_port(sk, 53); |
| 2379 | |
| 2380 | proto = protocol_by_family(sk->ss_family); |
| 2381 | if (!proto || !proto->connect) { |
| 2382 | ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n", |
| 2383 | resolv_linenum, address); |
| 2384 | err_code |= ERR_WARN; |
| 2385 | continue; |
| 2386 | } |
| 2387 | |
| 2388 | if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) { |
| 2389 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2391 | goto resolv_out; |
| 2392 | } |
| 2393 | |
| 2394 | newnameserver->conf.file = strdup("/etc/resolv.conf"); |
| 2395 | if (newnameserver->conf.file == NULL) { |
| 2396 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2397 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2398 | goto resolv_out; |
| 2399 | } |
| 2400 | |
| 2401 | newnameserver->id = strdup(address); |
| 2402 | if (newnameserver->id == NULL) { |
| 2403 | ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum); |
| 2404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2405 | goto resolv_out; |
| 2406 | } |
| 2407 | |
| 2408 | newnameserver->resolvers = curr_resolvers; |
| 2409 | newnameserver->conf.line = resolv_linenum; |
| 2410 | newnameserver->addr = *sk; |
| 2411 | |
| 2412 | LIST_ADDQ(&curr_resolvers->nameservers, &newnameserver->list); |
| 2413 | } |
| 2414 | |
| 2415 | resolv_out: |
| 2416 | free(sk); |
| 2417 | free(resolv_line); |
| 2418 | if (f != NULL) |
| 2419 | fclose(f); |
| 2420 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2421 | else if (strcmp(args[0], "hold") == 0) { /* hold periods */ |
| 2422 | const char *res; |
| 2423 | unsigned int time; |
| 2424 | |
| 2425 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2426 | ha_alert("parsing [%s:%d] : '%s' expects an <event> and a <time> as arguments.\n", |
| 2427 | file, linenum, args[0]); |
| 2428 | 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] | 2429 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2430 | goto out; |
| 2431 | } |
| 2432 | res = parse_time_err(args[2], &time, TIME_UNIT_MS); |
| 2433 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2434 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2435 | file, linenum, *res, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2436 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2437 | goto out; |
| 2438 | } |
Baptiste Assmann | 987e16d | 2016-11-02 22:23:31 +0100 | [diff] [blame] | 2439 | if (strcmp(args[1], "nx") == 0) |
| 2440 | curr_resolvers->hold.nx = time; |
| 2441 | else if (strcmp(args[1], "other") == 0) |
| 2442 | curr_resolvers->hold.other = time; |
| 2443 | else if (strcmp(args[1], "refused") == 0) |
| 2444 | curr_resolvers->hold.refused = time; |
| 2445 | else if (strcmp(args[1], "timeout") == 0) |
| 2446 | curr_resolvers->hold.timeout = time; |
| 2447 | else if (strcmp(args[1], "valid") == 0) |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2448 | curr_resolvers->hold.valid = time; |
Olivier Houchard | a8c6db8 | 2017-07-06 18:46:47 +0200 | [diff] [blame] | 2449 | else if (strcmp(args[1], "obsolete") == 0) |
| 2450 | curr_resolvers->hold.obsolete = time; |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2451 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2452 | ha_alert("parsing [%s:%d] : '%s' unknown <event>: '%s', expects either 'nx', 'timeout', 'valid', 'obsolete' or 'other'.\n", |
| 2453 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2454 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2455 | goto out; |
| 2456 | } |
| 2457 | |
| 2458 | } |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2459 | else if (strcmp(args[0], "accepted_payload_size") == 0) { |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2460 | int i = 0; |
| 2461 | |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2462 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2463 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2464 | file, linenum, args[0]); |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2466 | goto out; |
| 2467 | } |
Baptiste Assmann | 9d8dbbc | 2017-08-18 23:35:08 +0200 | [diff] [blame] | 2468 | |
| 2469 | i = atoi(args[1]); |
Willy Tarreau | 0c219be | 2017-08-22 12:01:26 +0200 | [diff] [blame] | 2470 | if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2471 | ha_alert("parsing [%s:%d] : '%s' must be between %d and %d inclusive (was %s).\n", |
| 2472 | 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] | 2473 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2474 | goto out; |
| 2475 | } |
| 2476 | |
| 2477 | curr_resolvers->accepted_payload_size = i; |
Baptiste Assmann | 2af08fe | 2017-08-14 00:13:01 +0200 | [diff] [blame] | 2478 | } |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2479 | else if (strcmp(args[0], "resolution_pool_size") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2480 | ha_warning("parsing [%s:%d] : '%s' directive is now deprecated and ignored.\n", |
| 2481 | file, linenum, args[0]); |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2482 | err_code |= ERR_WARN; |
| 2483 | goto out; |
Baptiste Assmann | 201c07f | 2017-05-22 15:17:15 +0200 | [diff] [blame] | 2484 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2485 | else if (strcmp(args[0], "resolve_retries") == 0) { |
| 2486 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2487 | ha_alert("parsing [%s:%d] : '%s' expects <nb> as argument.\n", |
| 2488 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | curr_resolvers->resolve_retries = atoi(args[1]); |
| 2493 | } |
| 2494 | else if (strcmp(args[0], "timeout") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2495 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2496 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments.\n", |
| 2497 | file, linenum, args[0]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2499 | goto out; |
| 2500 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2501 | else if (strcmp(args[1], "retry") == 0 || |
| 2502 | strcmp(args[1], "resolve") == 0) { |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2503 | const char *res; |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2504 | unsigned int tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2505 | |
| 2506 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2507 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2508 | file, linenum, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2509 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2510 | goto out; |
| 2511 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2512 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2513 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2514 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 2515 | file, linenum, *res, args[0], args[1]); |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2517 | goto out; |
| 2518 | } |
Christopher Faulet | 67957bd | 2017-09-27 11:00:59 +0200 | [diff] [blame] | 2519 | if (args[1][2] == 't') |
| 2520 | curr_resolvers->timeout.retry = tout; |
| 2521 | else |
| 2522 | curr_resolvers->timeout.resolve = tout; |
Pieter Baauw | 7a91a0e | 2016-02-13 15:51:58 +0100 | [diff] [blame] | 2523 | } |
| 2524 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2525 | ha_alert("parsing [%s:%d] : '%s' expects 'retry' or 'resolve' and <time> as arguments got '%s'.\n", |
| 2526 | file, linenum, args[0], args[1]); |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2527 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2528 | goto out; |
| 2529 | } |
Baptiste Assmann | 325137d | 2015-04-13 23:40:55 +0200 | [diff] [blame] | 2530 | } /* neither "nameserver" nor "resolvers" */ |
| 2531 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2532 | 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] | 2533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2534 | goto out; |
| 2535 | } |
| 2536 | |
| 2537 | out: |
| 2538 | free(errmsg); |
| 2539 | return err_code; |
| 2540 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2541 | |
| 2542 | /* |
William Lallemand | 5109719 | 2015-04-14 16:35:22 +0200 | [diff] [blame] | 2543 | * Parse a line in a <listen>, <frontend> or <backend> section. |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2544 | * Returns the error code, 0 if OK, or any combination of : |
| 2545 | * - ERR_ABORT: must abort ASAP |
| 2546 | * - ERR_FATAL: we can continue parsing but not start the service |
| 2547 | * - ERR_WARN: a warning has been emitted |
| 2548 | * - ERR_ALERT: an alert has been emitted |
| 2549 | * Only the two first ones can stop processing, the two others are just |
| 2550 | * indicators. |
| 2551 | */ |
| 2552 | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
| 2553 | { |
| 2554 | static struct mailers *curmailers = NULL; |
| 2555 | struct mailer *newmailer = NULL; |
| 2556 | const char *err; |
| 2557 | int err_code = 0; |
| 2558 | char *errmsg = NULL; |
| 2559 | |
| 2560 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
| 2561 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2562 | 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] | 2563 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2564 | goto out; |
| 2565 | } |
| 2566 | |
| 2567 | err = invalid_char(args[1]); |
| 2568 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2569 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2570 | file, linenum, *err, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2571 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2572 | goto out; |
| 2573 | } |
| 2574 | |
| 2575 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
| 2576 | /* |
| 2577 | * If there are two proxies with the same name only following |
| 2578 | * combinations are allowed: |
| 2579 | */ |
| 2580 | if (strcmp(curmailers->id, args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2581 | ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", |
| 2582 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2583 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2587 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2588 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2589 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2590 | goto out; |
| 2591 | } |
| 2592 | |
| 2593 | curmailers->next = mailers; |
| 2594 | mailers = curmailers; |
| 2595 | curmailers->conf.file = strdup(file); |
| 2596 | curmailers->conf.line = linenum; |
| 2597 | curmailers->id = strdup(args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2598 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
| 2599 | * But need enough time so that timeouts don't occur |
| 2600 | * during tcp procssing. For now just us an arbitrary default. */ |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2601 | } |
| 2602 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
| 2603 | struct sockaddr_storage *sk; |
| 2604 | int port1, port2; |
| 2605 | struct protocol *proto; |
| 2606 | |
| 2607 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2608 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
| 2609 | file, linenum, args[0]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2611 | goto out; |
| 2612 | } |
| 2613 | |
| 2614 | err = invalid_char(args[1]); |
| 2615 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2616 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
| 2617 | file, linenum, *err, args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2619 | goto out; |
| 2620 | } |
| 2621 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2622 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2623 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2624 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2625 | goto out; |
| 2626 | } |
| 2627 | |
| 2628 | /* the mailers are linked backwards first */ |
| 2629 | curmailers->count++; |
| 2630 | newmailer->next = curmailers->mailer_list; |
| 2631 | curmailers->mailer_list = newmailer; |
| 2632 | newmailer->mailers = curmailers; |
| 2633 | newmailer->conf.file = strdup(file); |
| 2634 | newmailer->conf.line = linenum; |
| 2635 | |
| 2636 | newmailer->id = strdup(args[1]); |
| 2637 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 2638 | sk = str2sa_range(args[2], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2639 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2640 | 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] | 2641 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2642 | goto out; |
| 2643 | } |
| 2644 | |
| 2645 | proto = protocol_by_family(sk->ss_family); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 2646 | if (!proto || !proto->connect || proto->sock_prot != IPPROTO_TCP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2647 | ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n", |
| 2648 | file, linenum, args[0], args[1]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
| 2653 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2654 | ha_alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n", |
| 2655 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2656 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2657 | goto out; |
| 2658 | } |
| 2659 | |
| 2660 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2661 | ha_alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n", |
| 2662 | file, linenum, args[0], args[1], args[2]); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | |
| 2667 | newmailer->addr = *sk; |
| 2668 | newmailer->proto = proto; |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 2669 | newmailer->xprt = xprt_get(XPRT_RAW); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2670 | newmailer->sock_init_arg = NULL; |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2671 | } |
| 2672 | else if (strcmp(args[0], "timeout") == 0) { |
| 2673 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2674 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
| 2675 | file, linenum, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2676 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | else if (strcmp(args[1], "mail") == 0) { |
| 2680 | const char *res; |
| 2681 | unsigned int timeout_mail; |
| 2682 | if (!*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2683 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 2684 | file, linenum, args[0], args[1]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2685 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2686 | goto out; |
| 2687 | } |
| 2688 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
| 2689 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2690 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 2691 | file, linenum, *res, args[0]); |
Pieter Baauw | 235fcfc | 2016-02-13 15:33:40 +0100 | [diff] [blame] | 2692 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2693 | goto out; |
| 2694 | } |
| 2695 | if (timeout_mail <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2696 | 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] | 2697 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | curmailers->timeout.mail = timeout_mail; |
| 2701 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2702 | 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] | 2703 | file, linenum, args[0], args[1]); |
| 2704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2705 | goto out; |
| 2706 | } |
| 2707 | } |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 2708 | else if (*args[0] != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2709 | 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] | 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
| 2712 | } |
| 2713 | |
| 2714 | out: |
| 2715 | free(errmsg); |
| 2716 | return err_code; |
| 2717 | } |
| 2718 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 2719 | static void free_email_alert(struct proxy *p) |
| 2720 | { |
| 2721 | free(p->email_alert.mailers.name); |
| 2722 | p->email_alert.mailers.name = NULL; |
| 2723 | free(p->email_alert.from); |
| 2724 | p->email_alert.from = NULL; |
| 2725 | free(p->email_alert.to); |
| 2726 | p->email_alert.to = NULL; |
| 2727 | free(p->email_alert.myhostname); |
| 2728 | p->email_alert.myhostname = NULL; |
| 2729 | } |
| 2730 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 2731 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2732 | { |
| 2733 | static struct proxy *curproxy = NULL; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 2734 | const char *err; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2735 | char *error; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 2736 | int rc; |
| 2737 | unsigned val; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2738 | int err_code = 0; |
Willy Tarreau | 3ec18a0 | 2010-01-28 19:01:34 +0100 | [diff] [blame] | 2739 | struct acl_cond *cond = NULL; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2740 | struct logsrv *tmplogsrv; |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 2741 | char *errmsg = NULL; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 2742 | struct bind_conf *bind_conf; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2743 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2744 | if (!strcmp(args[0], "listen")) |
| 2745 | rc = PR_CAP_LISTEN; |
| 2746 | else if (!strcmp(args[0], "frontend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2747 | rc = PR_CAP_FE; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 2748 | else if (!strcmp(args[0], "backend")) |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 2749 | rc = PR_CAP_BE; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2750 | else |
| 2751 | rc = PR_CAP_NONE; |
| 2752 | |
| 2753 | if (rc != PR_CAP_NONE) { /* new proxy */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2754 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2755 | ha_alert("parsing [%s:%d] : '%s' expects an <id> argument and\n" |
| 2756 | " optionally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n", |
| 2757 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2758 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2759 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2760 | } |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2761 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2762 | err = invalid_char(args[1]); |
| 2763 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2764 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 2765 | file, linenum, *err, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2766 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
Willy Tarreau | 8f50b68 | 2015-05-26 11:45:02 +0200 | [diff] [blame] | 2769 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 2770 | if (curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2771 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 2772 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 2773 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
Willy Tarreau | 911fa2e | 2015-05-26 10:35:50 +0200 | [diff] [blame] | 2774 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 365d1cd | 2007-10-21 02:55:17 +0200 | [diff] [blame] | 2775 | } |
| 2776 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2777 | if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2778 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 2779 | err_code |= ERR_ALERT | ERR_ABORT; |
| 2780 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2781 | } |
Willy Tarreau | 5af24ef | 2009-03-15 15:23:16 +0100 | [diff] [blame] | 2782 | |
Willy Tarreau | 97cb780 | 2010-01-03 20:23:58 +0100 | [diff] [blame] | 2783 | init_new_proxy(curproxy); |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 2784 | curproxy->next = proxies_list; |
| 2785 | proxies_list = curproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 2786 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 2787 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2788 | curproxy->last_change = now.tv_sec; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2789 | curproxy->id = strdup(args[1]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2790 | curproxy->cap = rc; |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 2791 | proxy_store_name(curproxy); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2792 | |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 2793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 2794 | if (curproxy->cap & PR_CAP_FE) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 2795 | 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] | 2796 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /* set default values */ |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2800 | memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); |
Willy Tarreau | 7016020 | 2010-04-07 16:06:40 +0200 | [diff] [blame] | 2801 | curproxy->defsrv.id = "default-server"; |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 2802 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2803 | curproxy->state = defproxy.state; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2804 | curproxy->options = defproxy.options; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 2805 | curproxy->options2 = defproxy.options2; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 2806 | curproxy->no_options = defproxy.no_options; |
| 2807 | curproxy->no_options2 = defproxy.no_options2; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 2808 | curproxy->bind_proc = defproxy.bind_proc; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 2809 | curproxy->except_net = defproxy.except_net; |
| 2810 | curproxy->except_mask = defproxy.except_mask; |
Maik Broemme | 36db02e | 2009-05-08 17:02:07 +0200 | [diff] [blame] | 2811 | curproxy->except_to = defproxy.except_to; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 2812 | curproxy->except_mask_to = defproxy.except_mask_to; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2813 | |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 2814 | if (defproxy.fwdfor_hdr_len) { |
| 2815 | curproxy->fwdfor_hdr_len = defproxy.fwdfor_hdr_len; |
| 2816 | curproxy->fwdfor_hdr_name = strdup(defproxy.fwdfor_hdr_name); |
| 2817 | } |
| 2818 | |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 2819 | if (defproxy.orgto_hdr_len) { |
| 2820 | curproxy->orgto_hdr_len = defproxy.orgto_hdr_len; |
| 2821 | curproxy->orgto_hdr_name = strdup(defproxy.orgto_hdr_name); |
| 2822 | } |
| 2823 | |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2824 | if (defproxy.server_id_hdr_len) { |
| 2825 | curproxy->server_id_hdr_len = defproxy.server_id_hdr_len; |
| 2826 | curproxy->server_id_hdr_name = strdup(defproxy.server_id_hdr_name); |
| 2827 | } |
| 2828 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2829 | if (curproxy->cap & PR_CAP_FE) { |
| 2830 | curproxy->maxconn = defproxy.maxconn; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 2831 | curproxy->backlog = defproxy.backlog; |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 2832 | curproxy->fe_sps_lim = defproxy.fe_sps_lim; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2833 | |
| 2834 | /* initialize error relocations */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2835 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
| 2836 | chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]); |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2837 | |
| 2838 | curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR; |
| 2839 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2840 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2841 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 743c128 | 2014-11-18 15:04:29 +0100 | [diff] [blame] | 2842 | curproxy->lbprm.algo = defproxy.lbprm.algo; |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 2843 | curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2844 | curproxy->fullconn = defproxy.fullconn; |
| 2845 | curproxy->conn_retries = defproxy.conn_retries; |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 2846 | curproxy->redispatch_after = defproxy.redispatch_after; |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 2847 | curproxy->max_ka_queue = defproxy.max_ka_queue; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2848 | |
Willy Tarreau | aa2f389 | 2010-10-22 16:15:31 +0200 | [diff] [blame] | 2849 | if (defproxy.check_req) { |
| 2850 | curproxy->check_req = calloc(1, defproxy.check_len); |
| 2851 | memcpy(curproxy->check_req, defproxy.check_req, defproxy.check_len); |
| 2852 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2853 | curproxy->check_len = defproxy.check_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2854 | |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2855 | if (defproxy.expect_str) { |
| 2856 | curproxy->expect_str = strdup(defproxy.expect_str); |
| 2857 | if (defproxy.expect_regex) { |
| 2858 | /* note: this regex is known to be valid */ |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 2859 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 2860 | regex_comp(defproxy.expect_str, curproxy->expect_regex, 1, 1, NULL); |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 2864 | curproxy->ck_opts = defproxy.ck_opts; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2865 | if (defproxy.cookie_name) |
| 2866 | curproxy->cookie_name = strdup(defproxy.cookie_name); |
| 2867 | curproxy->cookie_len = defproxy.cookie_len; |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 2868 | |
| 2869 | if (defproxy.dyncookie_key) |
| 2870 | curproxy->dyncookie_key = strdup(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 2871 | if (defproxy.cookie_domain) |
| 2872 | curproxy->cookie_domain = strdup(defproxy.cookie_domain); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2873 | |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 2874 | if (defproxy.cookie_maxidle) |
| 2875 | curproxy->cookie_maxidle = defproxy.cookie_maxidle; |
| 2876 | |
| 2877 | if (defproxy.cookie_maxlife) |
| 2878 | curproxy->cookie_maxlife = defproxy.cookie_maxlife; |
| 2879 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 2880 | if (defproxy.rdp_cookie_name) |
| 2881 | curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); |
| 2882 | curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; |
| 2883 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 2884 | if (defproxy.url_param_name) |
| 2885 | curproxy->url_param_name = strdup(defproxy.url_param_name); |
| 2886 | curproxy->url_param_len = defproxy.url_param_len; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 2887 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 2888 | if (defproxy.hh_name) |
| 2889 | curproxy->hh_name = strdup(defproxy.hh_name); |
| 2890 | curproxy->hh_len = defproxy.hh_len; |
| 2891 | curproxy->hh_match_domain = defproxy.hh_match_domain; |
| 2892 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2893 | if (defproxy.conn_src.iface_name) |
| 2894 | curproxy->conn_src.iface_name = strdup(defproxy.conn_src.iface_name); |
| 2895 | curproxy->conn_src.iface_len = defproxy.conn_src.iface_len; |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2896 | curproxy->conn_src.opts = defproxy.conn_src.opts; |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 2897 | #if defined(CONFIG_HAP_TRANSPARENT) |
Godbach | 9f04853 | 2013-04-23 15:27:57 +0800 | [diff] [blame] | 2898 | curproxy->conn_src.tproxy_addr = defproxy.conn_src.tproxy_addr; |
Willy Tarreau | c621d36 | 2013-04-25 17:35:22 +0200 | [diff] [blame] | 2899 | #endif |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 2900 | curproxy->load_server_state_from_file = defproxy.load_server_state_from_file; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2901 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2902 | |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 2903 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2904 | if (defproxy.capture_name) |
| 2905 | curproxy->capture_name = strdup(defproxy.capture_name); |
| 2906 | curproxy->capture_namelen = defproxy.capture_namelen; |
| 2907 | curproxy->capture_len = defproxy.capture_len; |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 2908 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2909 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2910 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2911 | curproxy->timeout.client = defproxy.timeout.client; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2912 | curproxy->timeout.clientfin = defproxy.timeout.clientfin; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2913 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 2914 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2915 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2916 | curproxy->mon_net = defproxy.mon_net; |
| 2917 | curproxy->mon_mask = defproxy.mon_mask; |
| 2918 | if (defproxy.monitor_uri) |
| 2919 | curproxy->monitor_uri = strdup(defproxy.monitor_uri); |
| 2920 | curproxy->monitor_uri_len = defproxy.monitor_uri_len; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 2921 | if (defproxy.defbe.name) |
| 2922 | curproxy->defbe.name = strdup(defproxy.defbe.name); |
Willy Tarreau | 99a7ca2 | 2012-05-31 19:39:23 +0200 | [diff] [blame] | 2923 | |
| 2924 | /* 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] | 2925 | curproxy->conf.logformat_string = defproxy.conf.logformat_string; |
| 2926 | if (curproxy->conf.logformat_string && |
| 2927 | curproxy->conf.logformat_string != default_http_log_format && |
| 2928 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2929 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2930 | curproxy->conf.logformat_string = strdup(curproxy->conf.logformat_string); |
| 2931 | |
| 2932 | if (defproxy.conf.lfs_file) { |
| 2933 | curproxy->conf.lfs_file = strdup(defproxy.conf.lfs_file); |
| 2934 | curproxy->conf.lfs_line = defproxy.conf.lfs_line; |
| 2935 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 2936 | |
| 2937 | /* get either a pointer to the logformat string for RFC5424 structured-data or a copy of it */ |
| 2938 | curproxy->conf.logformat_sd_string = defproxy.conf.logformat_sd_string; |
| 2939 | if (curproxy->conf.logformat_sd_string && |
| 2940 | curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2941 | curproxy->conf.logformat_sd_string = strdup(curproxy->conf.logformat_sd_string); |
| 2942 | |
| 2943 | if (defproxy.conf.lfsd_file) { |
| 2944 | curproxy->conf.lfsd_file = strdup(defproxy.conf.lfsd_file); |
| 2945 | curproxy->conf.lfsd_line = defproxy.conf.lfsd_line; |
| 2946 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 2950 | curproxy->timeout.connect = defproxy.timeout.connect; |
| 2951 | curproxy->timeout.server = defproxy.timeout.server; |
Simone Gotti | 1b48cc9 | 2014-06-11 12:25:28 +0200 | [diff] [blame] | 2952 | curproxy->timeout.serverfin = defproxy.timeout.serverfin; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 2953 | curproxy->timeout.check = defproxy.timeout.check; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 2954 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 2955 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 2956 | curproxy->timeout.httpreq = defproxy.timeout.httpreq; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 2957 | curproxy->timeout.httpka = defproxy.timeout.httpka; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2958 | curproxy->timeout.tunnel = defproxy.timeout.tunnel; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 2959 | curproxy->conn_src.source_addr = defproxy.conn_src.source_addr; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 2960 | } |
| 2961 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2962 | curproxy->mode = defproxy.mode; |
Willy Tarreau | ed2119c | 2014-04-24 22:10:39 +0200 | [diff] [blame] | 2963 | curproxy->uri_auth = defproxy.uri_auth; /* for stats */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2964 | |
| 2965 | /* copy default logsrvs to curproxy */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2966 | list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 2967 | struct logsrv *node = malloc(sizeof(*node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 2968 | memcpy(node, tmplogsrv, sizeof(struct logsrv)); |
Christopher Faulet | 28ac099 | 2018-03-26 16:09:19 +0200 | [diff] [blame] | 2969 | node->ref = tmplogsrv->ref; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 2970 | LIST_INIT(&node->list); |
| 2971 | LIST_ADDQ(&curproxy->logsrvs, &node->list); |
| 2972 | } |
| 2973 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2974 | curproxy->conf.uniqueid_format_string = defproxy.conf.uniqueid_format_string; |
| 2975 | if (curproxy->conf.uniqueid_format_string) |
| 2976 | curproxy->conf.uniqueid_format_string = strdup(curproxy->conf.uniqueid_format_string); |
| 2977 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 2978 | chunk_dup(&curproxy->log_tag, &defproxy.log_tag); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 2979 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 2980 | if (defproxy.conf.uif_file) { |
| 2981 | curproxy->conf.uif_file = strdup(defproxy.conf.uif_file); |
| 2982 | curproxy->conf.uif_line = defproxy.conf.uif_line; |
| 2983 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 2984 | |
| 2985 | /* copy default header unique id */ |
| 2986 | if (defproxy.header_unique_id) |
| 2987 | curproxy->header_unique_id = strdup(defproxy.header_unique_id); |
| 2988 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 2989 | /* default compression options */ |
| 2990 | if (defproxy.comp != NULL) { |
| 2991 | curproxy->comp = calloc(1, sizeof(struct comp)); |
| 2992 | curproxy->comp->algos = defproxy.comp->algos; |
| 2993 | curproxy->comp->types = defproxy.comp->types; |
| 2994 | } |
| 2995 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2996 | curproxy->grace = defproxy.grace; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 2997 | curproxy->conf.used_listener_id = EB_ROOT; |
| 2998 | curproxy->conf.used_server_id = EB_ROOT; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 2999 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3000 | if (defproxy.check_path) |
| 3001 | curproxy->check_path = strdup(defproxy.check_path); |
| 3002 | if (defproxy.check_command) |
| 3003 | curproxy->check_command = strdup(defproxy.check_command); |
| 3004 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3005 | if (defproxy.email_alert.mailers.name) |
| 3006 | curproxy->email_alert.mailers.name = strdup(defproxy.email_alert.mailers.name); |
| 3007 | if (defproxy.email_alert.from) |
| 3008 | curproxy->email_alert.from = strdup(defproxy.email_alert.from); |
| 3009 | if (defproxy.email_alert.to) |
| 3010 | curproxy->email_alert.to = strdup(defproxy.email_alert.to); |
| 3011 | if (defproxy.email_alert.myhostname) |
| 3012 | curproxy->email_alert.myhostname = strdup(defproxy.email_alert.myhostname); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3013 | curproxy->email_alert.level = defproxy.email_alert.level; |
Cyril Bonté | 7e08470 | 2015-12-04 03:07:06 +0100 | [diff] [blame] | 3014 | curproxy->email_alert.set = defproxy.email_alert.set; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3015 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3016 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3017 | } |
| 3018 | else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */ |
| 3019 | /* some variables may have already been initialized earlier */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 3020 | /* FIXME-20070101: we should do this too at the end of the |
| 3021 | * config parsing to free all default values. |
| 3022 | */ |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 3023 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
| 3024 | err_code |= ERR_ABORT; |
| 3025 | goto out; |
| 3026 | } |
| 3027 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3028 | free(defproxy.check_req); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3029 | free(defproxy.check_command); |
| 3030 | free(defproxy.check_path); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3031 | free(defproxy.cookie_name); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3032 | free(defproxy.rdp_cookie_name); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3033 | free(defproxy.dyncookie_key); |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3034 | free(defproxy.cookie_domain); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3035 | free(defproxy.url_param_name); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 3036 | free(defproxy.hh_name); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3037 | free(defproxy.capture_name); |
| 3038 | free(defproxy.monitor_uri); |
| 3039 | free(defproxy.defbe.name); |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 3040 | free(defproxy.conn_src.iface_name); |
Willy Tarreau | 79f5fe8 | 2008-08-23 08:18:21 +0200 | [diff] [blame] | 3041 | free(defproxy.fwdfor_hdr_name); |
| 3042 | defproxy.fwdfor_hdr_len = 0; |
Willy Tarreau | b86db34 | 2009-11-30 11:50:16 +0100 | [diff] [blame] | 3043 | free(defproxy.orgto_hdr_name); |
| 3044 | defproxy.orgto_hdr_len = 0; |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3045 | free(defproxy.server_id_hdr_name); |
| 3046 | defproxy.server_id_hdr_len = 0; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 3047 | free(defproxy.expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3048 | if (defproxy.expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 3049 | regex_free(defproxy.expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 3050 | free(defproxy.expect_regex); |
| 3051 | defproxy.expect_regex = NULL; |
| 3052 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3053 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3054 | if (defproxy.conf.logformat_string != default_http_log_format && |
| 3055 | defproxy.conf.logformat_string != default_tcp_log_format && |
| 3056 | defproxy.conf.logformat_string != clf_http_log_format) |
| 3057 | free(defproxy.conf.logformat_string); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3058 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 3059 | free(defproxy.conf.uniqueid_format_string); |
| 3060 | free(defproxy.conf.lfs_file); |
| 3061 | free(defproxy.conf.uif_file); |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 3062 | chunk_destroy(&defproxy.log_tag); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3063 | free_email_alert(&defproxy); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 3064 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 3065 | if (defproxy.conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 3066 | free(defproxy.conf.logformat_sd_string); |
| 3067 | free(defproxy.conf.lfsd_file); |
| 3068 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3069 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3070 | chunk_destroy(&defproxy.errmsg[rc]); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 3071 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3072 | /* we cannot free uri_auth because it might already be used */ |
| 3073 | init_default_instance(); |
| 3074 | curproxy = &defproxy; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3075 | curproxy->conf.args.file = curproxy->conf.file = strdup(file); |
| 3076 | curproxy->conf.args.line = curproxy->conf.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3077 | defproxy.cap = PR_CAP_LISTEN; /* all caps for now */ |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3078 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3079 | } |
| 3080 | else if (curproxy == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3081 | ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3082 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3083 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3084 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 3085 | |
| 3086 | /* update the current file and line being parsed */ |
| 3087 | curproxy->conf.args.file = curproxy->conf.file; |
| 3088 | curproxy->conf.args.line = linenum; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3089 | |
| 3090 | /* Now let's parse the proxy-specific keywords */ |
Frédéric Lécaille | b82f742 | 2017-04-13 18:24:23 +0200 | [diff] [blame] | 3091 | if (!strcmp(args[0], "server") || |
| 3092 | !strcmp(args[0], "default-server") || |
| 3093 | !strcmp(args[0], "server-template")) { |
Willy Tarreau | 272adea | 2014-03-31 10:39:59 +0200 | [diff] [blame] | 3094 | err_code |= parse_server(file, linenum, args, curproxy, &defproxy); |
| 3095 | if (err_code & ERR_FATAL) |
| 3096 | goto out; |
| 3097 | } |
| 3098 | else if (!strcmp(args[0], "bind")) { /* new listen addresses */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3099 | struct listener *l; |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3100 | int cur_arg; |
| 3101 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3102 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3103 | 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] | 3104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3105 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3106 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3107 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3108 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3109 | |
Willy Tarreau | 2470928 | 2013-03-10 21:32:12 +0100 | [diff] [blame] | 3110 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3111 | ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
| 3112 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3113 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3114 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3115 | } |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3116 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 3117 | 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] | 3118 | |
| 3119 | /* use default settings for unix sockets */ |
| 3120 | bind_conf->ux.uid = global.unix_bind.ux.uid; |
| 3121 | bind_conf->ux.gid = global.unix_bind.ux.gid; |
| 3122 | bind_conf->ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 8a95691 | 2010-10-15 14:27:08 +0200 | [diff] [blame] | 3123 | |
| 3124 | /* NOTE: the following line might create several listeners if there |
| 3125 | * are comma-separated IPs or port ranges. So all further processing |
| 3126 | * will have to be applied to all listeners created after last_listen. |
| 3127 | */ |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 3128 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 3129 | if (errmsg && *errmsg) { |
| 3130 | indent_msg(&errmsg, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3131 | 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] | 3132 | } |
| 3133 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3134 | ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 3135 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3136 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3137 | goto out; |
| 3138 | } |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3139 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3140 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 3141 | /* Set default global rights and owner for unix bind */ |
Willy Tarreau | c8b1109 | 2011-02-16 11:08:57 +0100 | [diff] [blame] | 3142 | global.maxsock++; |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 3143 | } |
| 3144 | |
Willy Tarreau | 5e6e204 | 2009-02-04 17:19:29 +0100 | [diff] [blame] | 3145 | cur_arg = 2; |
| 3146 | while (*(args[cur_arg])) { |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3147 | static int bind_dumped; |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3148 | struct bind_kw *kw; |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3149 | char *err; |
| 3150 | |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3151 | kw = bind_find_kw(args[cur_arg]); |
| 3152 | if (kw) { |
| 3153 | char *err = NULL; |
| 3154 | int code; |
| 3155 | |
| 3156 | if (!kw->parse) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3157 | ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 3158 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3159 | cur_arg += 1 + kw->skip ; |
| 3160 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3161 | goto out; |
| 3162 | } |
| 3163 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 3164 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3165 | err_code |= code; |
| 3166 | |
| 3167 | if (code) { |
| 3168 | if (err && *err) { |
| 3169 | indent_msg(&err, 2); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3170 | 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] | 3171 | } |
| 3172 | else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3173 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 3174 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 2698266 | 2012-09-12 23:17:10 +0200 | [diff] [blame] | 3175 | if (code & ERR_FATAL) { |
| 3176 | free(err); |
| 3177 | cur_arg += 1 + kw->skip; |
| 3178 | goto out; |
| 3179 | } |
| 3180 | } |
| 3181 | free(err); |
| 3182 | cur_arg += 1 + kw->skip; |
| 3183 | continue; |
| 3184 | } |
| 3185 | |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3186 | err = NULL; |
| 3187 | if (!bind_dumped) { |
| 3188 | bind_dump_kws(&err); |
| 3189 | indent_msg(&err, 4); |
| 3190 | bind_dumped = 1; |
| 3191 | } |
| 3192 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3193 | ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 3194 | file, linenum, args[0], args[1], args[cur_arg], |
| 3195 | err ? " Registered keywords :" : "", err ? err : ""); |
Willy Tarreau | 8638f48 | 2012-09-18 18:01:17 +0200 | [diff] [blame] | 3196 | free(err); |
| 3197 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3198 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3199 | goto out; |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 3200 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3202 | } |
| 3203 | 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] | 3204 | 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] | 3205 | ha_alert("parsing [%s:%d] : '%s' expects address[/mask].\n", |
| 3206 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3208 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3209 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3210 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3211 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3212 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3213 | /* flush useless bits */ |
| 3214 | curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3215 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3216 | } |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3217 | else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3218 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3219 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3220 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3221 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3222 | goto out; |
| 3223 | |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3224 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3225 | ha_alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 3226 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3227 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3228 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3229 | } |
| 3230 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3231 | free(curproxy->monitor_uri); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3232 | curproxy->monitor_uri_len = strlen(args[1]); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3233 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 3234 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3235 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 3236 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3237 | goto out; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 3238 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3239 | else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3240 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3241 | goto out; |
| 3242 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3243 | if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP; |
| 3244 | else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP; |
| 3245 | else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH; |
| 3246 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3247 | 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] | 3248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3249 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3250 | } |
| 3251 | } |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3252 | else if (!strcmp(args[0], "id")) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3253 | struct eb32_node *node; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3254 | |
| 3255 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3256 | 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] | 3257 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3259 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3262 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3263 | goto out; |
| 3264 | |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3265 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3266 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 3267 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3269 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | curproxy->uuid = atol(args[1]); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3273 | curproxy->conf.id.key = curproxy->uuid; |
Willy Tarreau | 0d1fdf7 | 2015-05-27 16:44:02 +0200 | [diff] [blame] | 3274 | curproxy->options |= PR_O_FORCED_ID; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3275 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3276 | if (curproxy->uuid <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3277 | ha_alert("parsing [%s:%d]: custom id has to be > 0.\n", |
| 3278 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3279 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3280 | goto out; |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3283 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 3284 | if (node) { |
| 3285 | struct proxy *target = container_of(node, struct proxy, conf.id); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3286 | ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 3287 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 3288 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 3289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3290 | goto out; |
| 3291 | } |
| 3292 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 3293 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3294 | else if (!strcmp(args[0], "description")) { |
| 3295 | int i, len=0; |
| 3296 | char *d; |
| 3297 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3298 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3299 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3300 | file, linenum, args[0]); |
| 3301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3302 | goto out; |
| 3303 | } |
| 3304 | |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3305 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3306 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 3307 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3308 | return -1; |
| 3309 | } |
| 3310 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3311 | for (i = 1; *args[i]; i++) |
| 3312 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3313 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 3314 | d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3315 | curproxy->desc = d; |
| 3316 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 3317 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 3318 | for (i = 2; *args[i]; i++) |
| 3319 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 3320 | |
| 3321 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3322 | else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3323 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3324 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3325 | curproxy->state = PR_STSTOPPED; |
| 3326 | } |
| 3327 | 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] | 3328 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 3329 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3330 | curproxy->state = PR_STNEW; |
| 3331 | } |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3332 | else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ |
| 3333 | int cur_arg = 1; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 3334 | unsigned long set = 0; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3335 | |
| 3336 | while (*args[cur_arg]) { |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3337 | if (strcmp(args[cur_arg], "all") == 0) { |
| 3338 | set = 0; |
| 3339 | break; |
| 3340 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 3341 | if (parse_process_number(args[cur_arg], &set, NULL, &errmsg)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3342 | 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] | 3343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3344 | goto out; |
Willy Tarreau | 0b9c02c | 2009-02-04 22:05:05 +0100 | [diff] [blame] | 3345 | } |
| 3346 | cur_arg++; |
| 3347 | } |
| 3348 | curproxy->bind_proc = set; |
| 3349 | } |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3350 | else if (!strcmp(args[0], "acl")) { /* add an ACL */ |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3351 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3352 | 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] | 3353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3354 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3355 | } |
| 3356 | |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3357 | err = invalid_char(args[1]); |
| 3358 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3359 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 3360 | file, linenum, *err, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3361 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 1822e8c | 2017-04-12 18:54:00 +0200 | [diff] [blame] | 3362 | goto out; |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 3363 | } |
| 3364 | |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 3365 | 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] | 3366 | ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 3367 | file, linenum, args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3369 | goto out; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3370 | } |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3371 | } |
| 3372 | else if (!strcmp(args[0], "dynamic-cookie-key")) { /* Dynamic cookies secret key */ |
| 3373 | |
| 3374 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3375 | err_code |= ERR_WARN; |
| 3376 | |
| 3377 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3378 | ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 3379 | file, linenum, args[0]); |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3380 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3381 | goto out; |
| 3382 | } |
| 3383 | free(curproxy->dyncookie_key); |
| 3384 | curproxy->dyncookie_key = strdup(args[1]); |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 3385 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3386 | else if (!strcmp(args[0], "cookie")) { /* cookie name */ |
| 3387 | int cur_arg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3388 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3389 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3390 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3391 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3392 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3393 | ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 3394 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3395 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3396 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3397 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3398 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3399 | curproxy->ck_opts = 0; |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3400 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
Willy Tarreau | 4d187ac | 2009-12-03 23:13:06 +0100 | [diff] [blame] | 3401 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3402 | free(curproxy->cookie_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3403 | curproxy->cookie_name = strdup(args[1]); |
| 3404 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
Willy Tarreau | c63d4bb | 2010-10-23 11:37:27 +0200 | [diff] [blame] | 3405 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3406 | cur_arg = 2; |
| 3407 | while (*(args[cur_arg])) { |
| 3408 | if (!strcmp(args[cur_arg], "rewrite")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3409 | curproxy->ck_opts |= PR_CK_RW; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3410 | } |
| 3411 | else if (!strcmp(args[cur_arg], "indirect")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3412 | curproxy->ck_opts |= PR_CK_IND; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3413 | } |
| 3414 | else if (!strcmp(args[cur_arg], "insert")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3415 | curproxy->ck_opts |= PR_CK_INS; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3416 | } |
| 3417 | else if (!strcmp(args[cur_arg], "nocache")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3418 | curproxy->ck_opts |= PR_CK_NOC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3419 | } |
| 3420 | else if (!strcmp(args[cur_arg], "postonly")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3421 | curproxy->ck_opts |= PR_CK_POST; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3422 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3423 | else if (!strcmp(args[cur_arg], "preserve")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3424 | curproxy->ck_opts |= PR_CK_PSV; |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3425 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3426 | else if (!strcmp(args[cur_arg], "prefix")) { |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3427 | curproxy->ck_opts |= PR_CK_PFX; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3428 | } |
Willy Tarreau | 4992dd2 | 2012-05-31 21:02:17 +0200 | [diff] [blame] | 3429 | else if (!strcmp(args[cur_arg], "httponly")) { |
| 3430 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 3431 | } |
| 3432 | else if (!strcmp(args[cur_arg], "secure")) { |
| 3433 | curproxy->ck_opts |= PR_CK_SECURE; |
| 3434 | } |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3435 | else if (!strcmp(args[cur_arg], "domain")) { |
| 3436 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3437 | ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 3438 | file, linenum, args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3440 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3441 | } |
| 3442 | |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3443 | if (*args[cur_arg + 1] != '.' || !strchr(args[cur_arg + 1] + 1, '.')) { |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3444 | /* rfc2109, 4.3.2 Rejecting Cookies */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3445 | ha_warning("parsing [%s:%d]: domain '%s' contains no embedded" |
| 3446 | " dots nor does not start with a dot." |
| 3447 | " RFC forbids it, this configuration may not work properly.\n", |
| 3448 | file, linenum, args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 1a8bea9 | 2009-12-15 23:40:47 +0100 | [diff] [blame] | 3449 | err_code |= ERR_WARN; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | err = invalid_domainchar(args[cur_arg + 1]); |
| 3453 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3454 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 3455 | file, linenum, *err, args[cur_arg + 1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3456 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3457 | goto out; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3458 | } |
| 3459 | |
Willy Tarreau | 68a897b | 2009-12-03 23:28:34 +0100 | [diff] [blame] | 3460 | if (!curproxy->cookie_domain) { |
| 3461 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 3462 | } else { |
| 3463 | /* one domain was already specified, add another one by |
| 3464 | * building the string which will be returned along with |
| 3465 | * the cookie. |
| 3466 | */ |
| 3467 | char *new_ptr; |
| 3468 | int new_len = strlen(curproxy->cookie_domain) + |
| 3469 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 3470 | new_ptr = malloc(new_len); |
| 3471 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 3472 | free(curproxy->cookie_domain); |
| 3473 | curproxy->cookie_domain = new_ptr; |
| 3474 | } |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3475 | cur_arg++; |
| 3476 | } |
| 3477 | else if (!strcmp(args[cur_arg], "maxidle")) { |
| 3478 | unsigned int maxidle; |
| 3479 | const char *res; |
| 3480 | |
| 3481 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3482 | ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 3483 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3484 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3485 | goto out; |
| 3486 | } |
| 3487 | |
| 3488 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
| 3489 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3490 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3491 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3492 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3493 | goto out; |
| 3494 | } |
| 3495 | curproxy->cookie_maxidle = maxidle; |
| 3496 | cur_arg++; |
| 3497 | } |
| 3498 | else if (!strcmp(args[cur_arg], "maxlife")) { |
| 3499 | unsigned int maxlife; |
| 3500 | const char *res; |
| 3501 | |
| 3502 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3503 | ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 3504 | file, linenum, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3505 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3506 | goto out; |
| 3507 | } |
| 3508 | |
| 3509 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
| 3510 | if (res) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3511 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 3512 | file, linenum, *res, args[cur_arg]); |
Willy Tarreau | 3193685 | 2010-10-06 16:59:56 +0200 | [diff] [blame] | 3513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3514 | goto out; |
| 3515 | } |
| 3516 | curproxy->cookie_maxlife = maxlife; |
Krzysztof Piotr Oledzki | efe3b6f | 2008-05-23 23:49:32 +0200 | [diff] [blame] | 3517 | cur_arg++; |
| 3518 | } |
Olivier Houchard | a5938f7 | 2017-03-15 15:12:06 +0100 | [diff] [blame] | 3519 | else if (!strcmp(args[cur_arg], "dynamic")) { /* Dynamic persistent cookies secret key */ |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 3520 | |
| 3521 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 3522 | err_code |= ERR_WARN; |
| 3523 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 3524 | } |
| 3525 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3526 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3527 | ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic' and 'maxlife' options.\n", |
| 3528 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3529 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3530 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3531 | } |
| 3532 | cur_arg++; |
| 3533 | } |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3534 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3535 | ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 3536 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3537 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3538 | } |
| 3539 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3540 | 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] | 3541 | ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' 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 | } |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3545 | |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 3546 | 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] | 3547 | ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 3548 | file, linenum); |
Willy Tarreau | ba4c5be | 2010-10-23 12:46:42 +0200 | [diff] [blame] | 3549 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3550 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3551 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3552 | else if (!strcmp(args[0], "email-alert")) { |
| 3553 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3554 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3555 | file, linenum, args[0]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3556 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3557 | goto out; |
| 3558 | } |
| 3559 | |
| 3560 | if (!strcmp(args[1], "from")) { |
| 3561 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3562 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3563 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3565 | goto out; |
| 3566 | } |
| 3567 | free(curproxy->email_alert.from); |
| 3568 | curproxy->email_alert.from = strdup(args[2]); |
| 3569 | } |
| 3570 | else if (!strcmp(args[1], "mailers")) { |
| 3571 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3572 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3573 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3574 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3575 | goto out; |
| 3576 | } |
| 3577 | free(curproxy->email_alert.mailers.name); |
| 3578 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 3579 | } |
| 3580 | else if (!strcmp(args[1], "myhostname")) { |
| 3581 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3582 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3583 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3585 | goto out; |
| 3586 | } |
| 3587 | free(curproxy->email_alert.myhostname); |
| 3588 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 3589 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3590 | else if (!strcmp(args[1], "level")) { |
| 3591 | curproxy->email_alert.level = get_log_level(args[2]); |
| 3592 | if (curproxy->email_alert.level < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3593 | ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 3594 | file, linenum, args[1], args[2]); |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3596 | goto out; |
| 3597 | } |
| 3598 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3599 | else if (!strcmp(args[1], "to")) { |
| 3600 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3601 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3602 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3603 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3604 | goto out; |
| 3605 | } |
| 3606 | free(curproxy->email_alert.to); |
| 3607 | curproxy->email_alert.to = strdup(args[2]); |
| 3608 | } |
| 3609 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3610 | ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 3611 | file, linenum, args[1]); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3613 | goto out; |
| 3614 | } |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 3615 | /* Indicate that the email_alert is at least partially configured */ |
| 3616 | curproxy->email_alert.set = 1; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 3617 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3618 | else if (!strcmp(args[0], "external-check")) { |
| 3619 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3620 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3621 | file, linenum, args[0]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3622 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3623 | goto out; |
| 3624 | } |
| 3625 | |
| 3626 | if (!strcmp(args[1], "command")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3627 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3628 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3629 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3630 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3631 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3632 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3633 | goto out; |
| 3634 | } |
| 3635 | free(curproxy->check_command); |
| 3636 | curproxy->check_command = strdup(args[2]); |
| 3637 | } |
| 3638 | else if (!strcmp(args[1], "path")) { |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3639 | if (alertif_too_many_args(2, file, linenum, args, &err_code)) |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3640 | goto out; |
Ben Cabot | 49795eb | 2015-09-16 12:07:51 +0100 | [diff] [blame] | 3641 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3642 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 3643 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3645 | goto out; |
| 3646 | } |
| 3647 | free(curproxy->check_path); |
| 3648 | curproxy->check_path = strdup(args[2]); |
| 3649 | } |
| 3650 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3651 | ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", |
| 3652 | file, linenum, args[1]); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 3653 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3654 | goto out; |
| 3655 | } |
| 3656 | }/* end else if (!strcmp(args[0], "external-check")) */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3657 | else if (!strcmp(args[0], "persist")) { /* persist */ |
| 3658 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3659 | ha_alert("parsing [%s:%d] : missing persist method.\n", |
| 3660 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3662 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 3666 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 3667 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3668 | if (*(args[1] + 10) == '(') { /* cookie name */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3669 | const char *beg, *end; |
| 3670 | |
| 3671 | beg = args[1] + 11; |
| 3672 | end = strchr(beg, ')'); |
| 3673 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3674 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3675 | goto out; |
| 3676 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3677 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3678 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3679 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3680 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3681 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | free(curproxy->rdp_cookie_name); |
| 3685 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 3686 | curproxy->rdp_cookie_len = end-beg; |
| 3687 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 3688 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3689 | free(curproxy->rdp_cookie_name); |
| 3690 | curproxy->rdp_cookie_name = strdup("msts"); |
| 3691 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 3692 | } |
| 3693 | else { /* syntax */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3694 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 3695 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3696 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3697 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3701 | ha_alert("parsing [%s:%d] : unknown persist method.\n", |
| 3702 | file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3703 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3704 | goto out; |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 3705 | } |
| 3706 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3707 | else if (!strcmp(args[0], "appsession")) { /* cookie name */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3708 | 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] | 3709 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3710 | goto out; |
| 3711 | } |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3712 | else if (!strcmp(args[0], "load-server-state-from-file")) { |
| 3713 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3714 | err_code |= ERR_WARN; |
| 3715 | if (!strcmp(args[1], "global")) { /* use the file pointed to by global server-state-file directive */ |
| 3716 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 3717 | } |
| 3718 | else if (!strcmp(args[1], "local")) { /* use the server-state-file-name variable to locate the server-state file */ |
| 3719 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 3720 | } |
| 3721 | else if (!strcmp(args[1], "none")) { /* don't use server-state-file directive for this backend */ |
| 3722 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 3723 | } |
| 3724 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3725 | ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 3726 | file, linenum, args[0], args[1]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3728 | goto out; |
| 3729 | } |
| 3730 | } |
| 3731 | else if (!strcmp(args[0], "server-state-file-name")) { |
| 3732 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3733 | err_code |= ERR_WARN; |
| 3734 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3735 | ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n", |
| 3736 | file, linenum, args[0]); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 3737 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3738 | goto out; |
| 3739 | } |
| 3740 | else if (!strcmp(args[1], "use-backend-name")) |
| 3741 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 3742 | else |
| 3743 | curproxy->server_state_file_name = strdup(args[1]); |
| 3744 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3745 | else if (!strcmp(args[0], "capture")) { |
Willy Tarreau | 3b6b1a9 | 2009-07-23 13:24:23 +0200 | [diff] [blame] | 3746 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3747 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3748 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3749 | if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */ |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3750 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3751 | 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] | 3752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3753 | goto out; |
| 3754 | } |
| 3755 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3756 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3757 | goto out; |
| 3758 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3759 | if (*(args[4]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3760 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 3761 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3763 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3764 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 3765 | free(curproxy->capture_name); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3766 | curproxy->capture_name = strdup(args[2]); |
| 3767 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 3768 | curproxy->capture_len = atol(args[4]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3769 | curproxy->to_log |= LW_COOKIE; |
| 3770 | } |
| 3771 | else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) { |
| 3772 | struct cap_hdr *hdr; |
| 3773 | |
| 3774 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3775 | 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] | 3776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3777 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3778 | } |
| 3779 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3780 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3781 | goto out; |
| 3782 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3783 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3784 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3785 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3787 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3788 | } |
| 3789 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3790 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3791 | hdr->next = curproxy->req_cap; |
| 3792 | hdr->name = strdup(args[3]); |
| 3793 | hdr->namelen = strlen(args[3]); |
| 3794 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3795 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3796 | hdr->index = curproxy->nb_req_cap++; |
| 3797 | curproxy->req_cap = hdr; |
| 3798 | curproxy->to_log |= LW_REQHDR; |
| 3799 | } |
| 3800 | else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) { |
| 3801 | struct cap_hdr *hdr; |
| 3802 | |
| 3803 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3804 | 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] | 3805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3806 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3807 | } |
| 3808 | |
William Lallemand | 1a748ae | 2015-05-19 16:37:23 +0200 | [diff] [blame] | 3809 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 3810 | goto out; |
| 3811 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3812 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3813 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 3814 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3815 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3816 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3817 | } |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 3818 | hdr = calloc(1, sizeof(*hdr)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3819 | hdr->next = curproxy->rsp_cap; |
| 3820 | hdr->name = strdup(args[3]); |
| 3821 | hdr->namelen = strlen(args[3]); |
| 3822 | hdr->len = atol(args[5]); |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 3823 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3824 | hdr->index = curproxy->nb_rsp_cap++; |
| 3825 | curproxy->rsp_cap = hdr; |
| 3826 | curproxy->to_log |= LW_RSPHDR; |
| 3827 | } |
| 3828 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3829 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 3830 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3832 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3833 | } |
| 3834 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3835 | else if (!strcmp(args[0], "retries")) { /* connection retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3836 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3837 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 3838 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 3839 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 3840 | goto out; |
| 3841 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3842 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3843 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 3844 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3845 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3846 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3847 | } |
| 3848 | curproxy->conn_retries = atol(args[1]); |
| 3849 | } |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3850 | 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] | 3851 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3852 | |
| 3853 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3854 | 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] | 3855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3856 | goto out; |
| 3857 | } |
| 3858 | |
Willy Tarreau | 20b0de5 | 2012-12-24 15:45:22 +0100 | [diff] [blame] | 3859 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3860 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3861 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3862 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_ACTION_DENY || |
| 3863 | LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->action == ACT_HTTP_REDIR || |
| 3864 | 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] | 3865 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3866 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3867 | err_code |= ERR_WARN; |
| 3868 | } |
| 3869 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3870 | 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] | 3871 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3872 | if (!rule) { |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3873 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3874 | goto out; |
| 3875 | } |
| 3876 | |
Willy Tarreau | 5002f57 | 2014-04-23 01:32:02 +0200 | [diff] [blame] | 3877 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3878 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3879 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3880 | file, linenum); |
| 3881 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 3882 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 59bb218 | 2010-01-29 17:58:21 +0100 | [diff] [blame] | 3883 | } |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3884 | else if (!strcmp(args[0], "http-response")) { /* response access control */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3885 | struct act_rule *rule; |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3886 | |
| 3887 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3888 | 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] | 3889 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3890 | goto out; |
| 3891 | } |
| 3892 | |
| 3893 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3894 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Thierry FOURNIER | 0ea5c7f | 2015-08-05 19:05:19 +0200 | [diff] [blame] | 3895 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->action == ACT_ACTION_ALLOW || |
| 3896 | 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] | 3897 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 3898 | file, linenum, args[0]); |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 3899 | err_code |= ERR_WARN; |
| 3900 | } |
| 3901 | |
| 3902 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 3903 | |
| 3904 | if (!rule) { |
| 3905 | err_code |= ERR_ALERT | ERR_ABORT; |
| 3906 | goto out; |
| 3907 | } |
| 3908 | |
| 3909 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3910 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 3911 | file, linenum); |
| 3912 | |
| 3913 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 3914 | } |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3915 | else if (!strcmp(args[0], "http-send-name-header")) { /* send server name in request header */ |
| 3916 | /* set the header name and length into the proxy structure */ |
| 3917 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 3918 | err_code |= ERR_WARN; |
| 3919 | |
| 3920 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3921 | ha_alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 3922 | file, linenum, args[0]); |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 3923 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3924 | goto out; |
| 3925 | } |
| 3926 | |
| 3927 | /* set the desired header name */ |
| 3928 | free(curproxy->server_id_hdr_name); |
| 3929 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 3930 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
| 3931 | } |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3932 | else if (!strcmp(args[0], "block")) { /* early blocking based on ACLs */ |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 3933 | struct act_rule *rule; |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3934 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3935 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3936 | 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] | 3937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3938 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3941 | /* emulate "block" using "http-request block". Since these rules are supposed to |
| 3942 | * be processed before all http-request rules, we put them into their own list |
| 3943 | * and will insert them at the end. |
| 3944 | */ |
| 3945 | rule = parse_http_req_cond((const char **)args, file, linenum, curproxy); |
| 3946 | if (!rule) { |
| 3947 | err_code |= ERR_ALERT | ERR_ABORT; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3948 | goto out; |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3949 | } |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 3950 | err_code |= warnif_misplaced_block(curproxy, file, linenum, args[0]); |
| 3951 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3952 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3953 | file, linenum); |
| 3954 | LIST_ADDQ(&curproxy->block_rules, &rule->list); |
Willy Tarreau | de9d2d7 | 2014-04-28 22:28:02 +0200 | [diff] [blame] | 3955 | |
| 3956 | if (!already_warned(WARN_BLOCK_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3957 | 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] | 3958 | |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 3959 | } |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3960 | else if (!strcmp(args[0], "redirect")) { |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3961 | struct redirect_rule *rule; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3962 | |
Cyril Bonté | 99ed327 | 2010-01-24 23:29:44 +0100 | [diff] [blame] | 3963 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3964 | 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] | 3965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3966 | goto out; |
| 3967 | } |
| 3968 | |
Willy Tarreau | be4653b | 2015-05-28 15:26:58 +0200 | [diff] [blame] | 3969 | 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] | 3970 | ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 3971 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3972 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3973 | goto out; |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3974 | } |
| 3975 | |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3976 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
Willy Tarreau | ee445d9 | 2014-04-23 01:39:04 +0200 | [diff] [blame] | 3977 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 3978 | err_code |= warnif_cond_conflicts(rule->cond, |
| 3979 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 3980 | file, linenum); |
Willy Tarreau | b463dfb | 2008-06-07 23:08:56 +0200 | [diff] [blame] | 3981 | } |
Krzysztof Piotr Oledzki | 7b723ef | 2009-01-27 21:09:41 +0100 | [diff] [blame] | 3982 | else if (!strcmp(args[0], "use_backend")) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3983 | struct switching_rule *rule; |
| 3984 | |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3985 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3986 | 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] | 3987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3988 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 3989 | } |
| 3990 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3991 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 3992 | err_code |= ERR_WARN; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3993 | |
| 3994 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 3995 | 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] | 3996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 3997 | goto out; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 3998 | } |
| 3999 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4000 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4001 | 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] | 4002 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4003 | file, linenum, errmsg); |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4005 | goto out; |
| 4006 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4007 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 4008 | 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] | 4009 | } |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4010 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4011 | ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 4012 | file, linenum, args[2]); |
Willy Tarreau | 4f86264 | 2017-02-28 09:34:39 +0100 | [diff] [blame] | 4013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4014 | goto out; |
| 4015 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4016 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4017 | rule = calloc(1, sizeof(*rule)); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4018 | if (!rule) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4019 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 5948b01 | 2016-11-24 23:58:32 +0100 | [diff] [blame] | 4020 | goto out; |
| 4021 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4022 | rule->cond = cond; |
| 4023 | rule->be.name = strdup(args[1]); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4024 | rule->line = linenum; |
| 4025 | rule->file = strdup(file); |
| 4026 | if (!rule->file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4027 | ha_alert("Out of memory error.\n"); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 4028 | goto out; |
| 4029 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 4030 | LIST_INIT(&rule->list); |
| 4031 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 4032 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4033 | else if (strcmp(args[0], "use-server") == 0) { |
| 4034 | struct server_rule *rule; |
| 4035 | |
| 4036 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4037 | 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] | 4038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4039 | goto out; |
| 4040 | } |
| 4041 | |
| 4042 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 4043 | err_code |= ERR_WARN; |
| 4044 | |
| 4045 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4046 | 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] | 4047 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4048 | goto out; |
| 4049 | } |
| 4050 | |
| 4051 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4052 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4053 | file, linenum, args[0]); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4055 | goto out; |
| 4056 | } |
| 4057 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4058 | 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] | 4059 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 4060 | file, linenum, errmsg); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4061 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4062 | goto out; |
| 4063 | } |
| 4064 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4065 | 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] | 4066 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4067 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 4068 | rule->cond = cond; |
| 4069 | rule->srv.name = strdup(args[1]); |
| 4070 | LIST_INIT(&rule->list); |
| 4071 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 4072 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 4073 | } |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4074 | else if ((!strcmp(args[0], "force-persist")) || |
| 4075 | (!strcmp(args[0], "ignore-persist"))) { |
| 4076 | struct persist_rule *rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4077 | |
| 4078 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4079 | 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] | 4080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4081 | goto out; |
| 4082 | } |
| 4083 | |
Cyril Bonté | 4288c5a | 2018-03-12 22:02:59 +0100 | [diff] [blame] | 4084 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4085 | err_code |= ERR_WARN; |
| 4086 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4087 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4088 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4089 | file, linenum, args[0]); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4090 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4091 | goto out; |
| 4092 | } |
| 4093 | |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4094 | 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] | 4095 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 4096 | file, linenum, args[0], errmsg); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4098 | goto out; |
| 4099 | } |
| 4100 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4101 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 4102 | * where force-persist is applied. |
| 4103 | */ |
| 4104 | 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] | 4105 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4106 | rule = calloc(1, sizeof(*rule)); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4107 | rule->cond = cond; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4108 | if (!strcmp(args[0], "force-persist")) { |
| 4109 | rule->type = PERSIST_TYPE_FORCE; |
| 4110 | } else { |
| 4111 | rule->type = PERSIST_TYPE_IGNORE; |
| 4112 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4113 | LIST_INIT(&rule->list); |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 4114 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 4115 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4116 | else if (!strcmp(args[0], "stick-table")) { |
| 4117 | int myidx = 1; |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4118 | struct proxy *other; |
| 4119 | |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 4120 | other = proxy_tbl_by_name(curproxy->id); |
Willy Tarreau | e45288c | 2015-05-26 10:49:46 +0200 | [diff] [blame] | 4121 | if (other) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4122 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
| 4123 | 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] | 4124 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4125 | goto out; |
| 4126 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4127 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4128 | curproxy->table.id = curproxy->id; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4129 | curproxy->table.type = (unsigned int)-1; |
| 4130 | while (*args[myidx]) { |
| 4131 | const char *err; |
| 4132 | |
| 4133 | if (strcmp(args[myidx], "size") == 0) { |
| 4134 | myidx++; |
| 4135 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4136 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4137 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4139 | goto out; |
| 4140 | } |
| 4141 | if ((err = parse_size_err(args[myidx], &curproxy->table.size))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4142 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4143 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4145 | goto out; |
| 4146 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4147 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4148 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4149 | else if (strcmp(args[myidx], "peers") == 0) { |
| 4150 | myidx++; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4151 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4152 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4153 | file, linenum, args[myidx-1]); |
Godbach | ff11554 | 2014-04-21 21:52:23 +0800 | [diff] [blame] | 4154 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4155 | goto out; |
Godbach | 5052316 | 2013-12-11 19:48:57 +0800 | [diff] [blame] | 4156 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 4157 | curproxy->table.peers.name = strdup(args[myidx++]); |
| 4158 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4159 | else if (strcmp(args[myidx], "expire") == 0) { |
| 4160 | myidx++; |
| 4161 | if (!*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4162 | ha_alert("parsing [%s:%d] : stick-table: missing argument after '%s'.\n", |
| 4163 | file, linenum, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4164 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4165 | goto out; |
| 4166 | } |
| 4167 | err = parse_time_err(args[myidx], &val, TIME_UNIT_MS); |
| 4168 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4169 | ha_alert("parsing [%s:%d] : stick-table: unexpected character '%c' in argument of '%s'.\n", |
| 4170 | file, linenum, *err, args[myidx-1]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4172 | goto out; |
| 4173 | } |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4174 | if (val > INT_MAX) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4175 | ha_alert("parsing [%s:%d] : Expire value [%u]ms exceeds maxmimum value of 24.85 days.\n", |
| 4176 | file, linenum, val); |
Ben Cabot | 3b90f0a | 2016-01-20 09:44:39 +0000 | [diff] [blame] | 4177 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4178 | goto out; |
| 4179 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4180 | curproxy->table.expire = val; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4181 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4182 | } |
| 4183 | else if (strcmp(args[myidx], "nopurge") == 0) { |
| 4184 | curproxy->table.nopurge = 1; |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4185 | myidx++; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4186 | } |
| 4187 | else if (strcmp(args[myidx], "type") == 0) { |
| 4188 | myidx++; |
| 4189 | 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] | 4190 | ha_alert("parsing [%s:%d] : stick-table: unknown type '%s'.\n", |
| 4191 | file, linenum, args[myidx]); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4193 | goto out; |
| 4194 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4195 | /* myidx already points to next arg */ |
| 4196 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4197 | else if (strcmp(args[myidx], "store") == 0) { |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4198 | int type, err; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4199 | char *cw, *nw, *sa; |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4200 | |
| 4201 | myidx++; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4202 | nw = args[myidx]; |
| 4203 | while (*nw) { |
| 4204 | /* the "store" keyword supports a comma-separated list */ |
| 4205 | cw = nw; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4206 | sa = NULL; /* store arg */ |
| 4207 | while (*nw && *nw != ',') { |
| 4208 | if (*nw == '(') { |
| 4209 | *nw = 0; |
| 4210 | sa = ++nw; |
| 4211 | while (*nw != ')') { |
| 4212 | if (!*nw) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4213 | ha_alert("parsing [%s:%d] : %s: missing closing parenthesis after store option '%s'.\n", |
| 4214 | file, linenum, args[0], cw); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4215 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4216 | goto out; |
| 4217 | } |
| 4218 | nw++; |
| 4219 | } |
| 4220 | *nw = '\0'; |
| 4221 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4222 | nw++; |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 4223 | } |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4224 | if (*nw) |
| 4225 | *nw++ = '\0'; |
| 4226 | type = stktable_get_data_type(cw); |
| 4227 | if (type < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4228 | ha_alert("parsing [%s:%d] : %s: unknown store option '%s'.\n", |
| 4229 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4230 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4231 | goto out; |
| 4232 | } |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4233 | |
| 4234 | err = stktable_alloc_data_type(&curproxy->table, type, sa); |
| 4235 | switch (err) { |
| 4236 | case PE_NONE: break; |
| 4237 | case PE_EXIST: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4238 | ha_warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", |
| 4239 | file, linenum, args[0], cw); |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4240 | err_code |= ERR_WARN; |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4241 | break; |
| 4242 | |
| 4243 | case PE_ARG_MISSING: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4244 | ha_alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", |
| 4245 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4246 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4247 | goto out; |
| 4248 | |
| 4249 | case PE_ARG_NOT_USED: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4250 | ha_alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", |
| 4251 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4252 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4253 | goto out; |
| 4254 | |
| 4255 | default: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4256 | ha_alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", |
| 4257 | file, linenum, args[0], cw); |
Willy Tarreau | ac78288 | 2010-06-20 10:41:54 +0200 | [diff] [blame] | 4258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4259 | goto out; |
Willy Tarreau | b084e9c | 2010-06-19 07:12:36 +0200 | [diff] [blame] | 4260 | } |
Willy Tarreau | 08d5f98 | 2010-06-06 13:34:54 +0200 | [diff] [blame] | 4261 | } |
| 4262 | myidx++; |
| 4263 | } |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4264 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4265 | ha_alert("parsing [%s:%d] : stick-table: unknown argument '%s'.\n", |
| 4266 | file, linenum, args[myidx]); |
Willy Tarreau | 0c55931 | 2010-01-26 18:36:26 +0100 | [diff] [blame] | 4267 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4268 | goto out; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4269 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | if (!curproxy->table.size) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4273 | ha_alert("parsing [%s:%d] : stick-table: missing size.\n", |
| 4274 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4275 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4276 | goto out; |
| 4277 | } |
| 4278 | |
| 4279 | if (curproxy->table.type == (unsigned int)-1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4280 | ha_alert("parsing [%s:%d] : stick-table: missing type.\n", |
| 4281 | file, linenum); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4282 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4283 | goto out; |
| 4284 | } |
| 4285 | } |
| 4286 | else if (!strcmp(args[0], "stick")) { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4287 | struct sticking_rule *rule; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 4288 | struct sample_expr *expr; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4289 | int myidx = 0; |
| 4290 | const char *name = NULL; |
| 4291 | int flags; |
| 4292 | |
| 4293 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4294 | 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] | 4295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4296 | goto out; |
| 4297 | } |
| 4298 | |
| 4299 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 4300 | err_code |= ERR_WARN; |
| 4301 | goto out; |
| 4302 | } |
| 4303 | |
| 4304 | myidx++; |
| 4305 | if ((strcmp(args[myidx], "store") == 0) || |
| 4306 | (strcmp(args[myidx], "store-request") == 0)) { |
| 4307 | myidx++; |
| 4308 | flags = STK_IS_STORE; |
| 4309 | } |
| 4310 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 4311 | myidx++; |
| 4312 | flags = STK_IS_STORE | STK_ON_RSP; |
| 4313 | } |
| 4314 | else if (strcmp(args[myidx], "match") == 0) { |
| 4315 | myidx++; |
| 4316 | flags = STK_IS_MATCH; |
| 4317 | } |
| 4318 | else if (strcmp(args[myidx], "on") == 0) { |
| 4319 | myidx++; |
| 4320 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 4321 | } |
| 4322 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4323 | 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] | 4324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4325 | goto out; |
| 4326 | } |
| 4327 | |
| 4328 | if (*(args[myidx]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4329 | 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] | 4330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4331 | goto out; |
| 4332 | } |
| 4333 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 4334 | curproxy->conf.args.ctx = ARGC_STK; |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 4335 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4336 | if (!expr) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4337 | 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] | 4338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4339 | goto out; |
| 4340 | } |
| 4341 | |
| 4342 | if (flags & STK_ON_RSP) { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4343 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4344 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 4345 | 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] | 4346 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4347 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4348 | goto out; |
| 4349 | } |
| 4350 | } else { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 4351 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4352 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 4353 | 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] | 4354 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4355 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4356 | goto out; |
| 4357 | } |
| 4358 | } |
| 4359 | |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4360 | /* 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] | 4361 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | 1b6c00c | 2012-10-05 22:41:26 +0200 | [diff] [blame] | 4362 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4363 | if (strcmp(args[myidx], "table") == 0) { |
| 4364 | myidx++; |
| 4365 | name = args[myidx++]; |
| 4366 | } |
| 4367 | |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4368 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4369 | 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] | 4370 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 4371 | file, linenum, args[0], errmsg); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4372 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4373 | free(expr); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4374 | goto out; |
| 4375 | } |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4376 | } |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4377 | else if (*(args[myidx])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4378 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 4379 | file, linenum, args[0], args[myidx]); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4380 | err_code |= ERR_ALERT | ERR_FATAL; |
Simon Horman | 5e55f5d | 2011-07-15 13:14:07 +0900 | [diff] [blame] | 4381 | free(expr); |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 4382 | goto out; |
| 4383 | } |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 4384 | if (flags & STK_ON_RSP) |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4385 | 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] | 4386 | else |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4387 | 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] | 4388 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4389 | rule = calloc(1, sizeof(*rule)); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 4390 | rule->cond = cond; |
| 4391 | rule->expr = expr; |
| 4392 | rule->flags = flags; |
| 4393 | rule->table.name = name ? strdup(name) : NULL; |
| 4394 | LIST_INIT(&rule->list); |
| 4395 | if (flags & STK_ON_RSP) |
| 4396 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 4397 | else |
| 4398 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 4399 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4400 | else if (!strcmp(args[0], "stats")) { |
| 4401 | if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth) |
| 4402 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 4403 | |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4404 | if (!*args[1]) { |
| 4405 | goto stats_error_parsing; |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4406 | } else if (!strcmp(args[1], "admin")) { |
| 4407 | struct stats_admin_rule *rule; |
| 4408 | |
| 4409 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4410 | 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] | 4411 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4412 | goto out; |
| 4413 | } |
| 4414 | |
| 4415 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4416 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4417 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4418 | goto out; |
| 4419 | } |
| 4420 | |
| 4421 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4422 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 4423 | 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 | } |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 4427 | 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] | 4428 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 4429 | file, linenum, args[0], args[1], errmsg); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4430 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4431 | goto out; |
| 4432 | } |
| 4433 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4434 | err_code |= warnif_cond_conflicts(cond, |
| 4435 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4436 | file, linenum); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4437 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4438 | rule = calloc(1, sizeof(*rule)); |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4439 | rule->cond = cond; |
| 4440 | LIST_INIT(&rule->list); |
| 4441 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4442 | } else if (!strcmp(args[1], "uri")) { |
| 4443 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4444 | 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] | 4445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4446 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4447 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4448 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4449 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4450 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4451 | } |
| 4452 | } else if (!strcmp(args[1], "realm")) { |
| 4453 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4454 | 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] | 4455 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4456 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4457 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4458 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4459 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4460 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4461 | } |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4462 | } else if (!strcmp(args[1], "refresh")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 4463 | unsigned interval; |
| 4464 | |
| 4465 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
| 4466 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4467 | ha_alert("parsing [%s:%d] : unexpected character '%c' in stats refresh interval.\n", |
| 4468 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4469 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4470 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4471 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4472 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4473 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4474 | goto out; |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 4475 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4476 | } 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] | 4477 | struct act_rule *rule; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4478 | |
| 4479 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4480 | 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] | 4481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4482 | goto out; |
| 4483 | } |
| 4484 | |
| 4485 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4486 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4487 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4488 | goto out; |
| 4489 | } |
| 4490 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4491 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 4492 | !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] | 4493 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 4494 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4495 | err_code |= ERR_WARN; |
| 4496 | } |
| 4497 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4498 | 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] | 4499 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4500 | if (!rule) { |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4501 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4502 | goto out; |
| 4503 | } |
| 4504 | |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 4505 | err_code |= warnif_cond_conflicts(rule->cond, |
| 4506 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 4507 | file, linenum); |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 4508 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 4509 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4510 | } else if (!strcmp(args[1], "auth")) { |
| 4511 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4512 | 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] | 4513 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4514 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4515 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4516 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4517 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4518 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4519 | } |
| 4520 | } else if (!strcmp(args[1], "scope")) { |
| 4521 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4522 | 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] | 4523 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4524 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4525 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4526 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4527 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4528 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4529 | } |
| 4530 | } else if (!strcmp(args[1], "enable")) { |
| 4531 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4532 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4533 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4534 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4535 | } |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4536 | } else if (!strcmp(args[1], "hide-version")) { |
| 4537 | if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4538 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4539 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4540 | goto out; |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 4541 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4542 | } else if (!strcmp(args[1], "show-legends")) { |
| 4543 | if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4544 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4545 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4546 | goto out; |
| 4547 | } |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4548 | } else if (!strcmp(args[1], "show-node")) { |
| 4549 | |
| 4550 | if (*args[2]) { |
| 4551 | int i; |
| 4552 | char c; |
| 4553 | |
| 4554 | for (i=0; args[2][i]; i++) { |
| 4555 | c = args[2][i]; |
Willy Tarreau | 88e0581 | 2010-03-03 00:16:00 +0100 | [diff] [blame] | 4556 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 4557 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4558 | break; |
| 4559 | } |
| 4560 | |
| 4561 | if (!i || args[2][i]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4562 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 4563 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 4564 | file, linenum, args[0], args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4565 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4566 | goto out; |
| 4567 | } |
| 4568 | } |
| 4569 | |
| 4570 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4571 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4572 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4573 | goto out; |
| 4574 | } |
| 4575 | } else if (!strcmp(args[1], "show-desc")) { |
| 4576 | char *desc = NULL; |
| 4577 | |
| 4578 | if (*args[2]) { |
| 4579 | int i, len=0; |
| 4580 | char *d; |
| 4581 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4582 | for (i = 2; *args[i]; i++) |
| 4583 | len += strlen(args[i]) + 1; |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4584 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4585 | desc = d = calloc(1, len); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4586 | |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 4587 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 4588 | for (i = 3; *args[i]; i++) |
| 4589 | d += snprintf(d, desc + len - d, " %s", args[i]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | if (!*args[2] && !global.desc) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4593 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 4594 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4595 | else { |
| 4596 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 4597 | free(desc); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4598 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 4599 | err_code |= ERR_ALERT | ERR_ABORT; |
| 4600 | goto out; |
| 4601 | } |
| 4602 | free(desc); |
| 4603 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4604 | } else { |
Krzysztof Piotr Oledzki | 260a3bb | 2010-01-06 16:25:05 +0100 | [diff] [blame] | 4605 | stats_error_parsing: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4606 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 4607 | 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] | 4608 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4609 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4610 | } |
| 4611 | } |
| 4612 | else if (!strcmp(args[0], "option")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4613 | int optnum; |
| 4614 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4615 | if (*(args[1]) == '\0') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4616 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 4617 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4618 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4619 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4620 | } |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4621 | |
| 4622 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 4623 | if (!strcmp(args[1], cfg_opts[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4624 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4625 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4626 | file, linenum, cfg_opts[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4627 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4628 | goto out; |
| 4629 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4630 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4631 | goto out; |
| 4632 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4633 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 4634 | err_code |= ERR_WARN; |
| 4635 | goto out; |
| 4636 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4637 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4638 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 4639 | curproxy->options &= ~cfg_opts[optnum].val; |
| 4640 | |
| 4641 | switch (kwm) { |
| 4642 | case KWM_STD: |
| 4643 | curproxy->options |= cfg_opts[optnum].val; |
| 4644 | break; |
| 4645 | case KWM_NO: |
| 4646 | curproxy->no_options |= cfg_opts[optnum].val; |
| 4647 | break; |
| 4648 | case KWM_DEF: /* already cleared */ |
| 4649 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4650 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4651 | |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4652 | goto out; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4653 | } |
| 4654 | } |
| 4655 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4656 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 4657 | if (!strcmp(args[1], cfg_opts2[optnum].name)) { |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4658 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4659 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 4660 | file, linenum, cfg_opts2[optnum].name); |
Cyril Bonté | 62846b2 | 2010-11-01 19:26:00 +0100 | [diff] [blame] | 4661 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4662 | goto out; |
| 4663 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4664 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4665 | goto out; |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4666 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 4667 | err_code |= ERR_WARN; |
| 4668 | goto out; |
| 4669 | } |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4670 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4671 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 4672 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 4673 | |
| 4674 | switch (kwm) { |
| 4675 | case KWM_STD: |
| 4676 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 4677 | break; |
| 4678 | case KWM_NO: |
| 4679 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 4680 | break; |
| 4681 | case KWM_DEF: /* already cleared */ |
| 4682 | break; |
Willy Tarreau | 84b57da | 2009-06-14 11:10:45 +0200 | [diff] [blame] | 4683 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4684 | goto out; |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 4685 | } |
| 4686 | } |
| 4687 | |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4688 | /* HTTP options override each other. They can be cancelled using |
| 4689 | * "no option xxx" which only switches to default mode if the mode |
| 4690 | * was this one (useful for cancelling options set in defaults |
| 4691 | * sections). |
| 4692 | */ |
| 4693 | if (strcmp(args[1], "httpclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4694 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4695 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4696 | if (kwm == KWM_STD) { |
| 4697 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4698 | curproxy->options |= PR_O_HTTP_PCL; |
| 4699 | goto out; |
| 4700 | } |
| 4701 | else if (kwm == KWM_NO) { |
| 4702 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL) |
| 4703 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4704 | goto out; |
| 4705 | } |
| 4706 | } |
| 4707 | else if (strcmp(args[1], "forceclose") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4708 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4709 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4710 | if (kwm == KWM_STD) { |
| 4711 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4712 | curproxy->options |= PR_O_HTTP_FCL; |
| 4713 | goto out; |
| 4714 | } |
| 4715 | else if (kwm == KWM_NO) { |
| 4716 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL) |
| 4717 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4718 | goto out; |
| 4719 | } |
| 4720 | } |
| 4721 | else if (strcmp(args[1], "http-server-close") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4722 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4723 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4724 | if (kwm == KWM_STD) { |
| 4725 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4726 | curproxy->options |= PR_O_HTTP_SCL; |
| 4727 | goto out; |
| 4728 | } |
| 4729 | else if (kwm == KWM_NO) { |
| 4730 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 4731 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4732 | goto out; |
| 4733 | } |
| 4734 | } |
| 4735 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4736 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4737 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4738 | if (kwm == KWM_STD) { |
| 4739 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4740 | curproxy->options |= PR_O_HTTP_KAL; |
| 4741 | goto out; |
| 4742 | } |
| 4743 | else if (kwm == KWM_NO) { |
| 4744 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 4745 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4746 | goto out; |
| 4747 | } |
| 4748 | } |
| 4749 | else if (strcmp(args[1], "http-tunnel") == 0) { |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4750 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4751 | goto out; |
Willy Tarreau | 02bce8b | 2014-01-30 00:15:28 +0100 | [diff] [blame] | 4752 | if (kwm == KWM_STD) { |
| 4753 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4754 | curproxy->options |= PR_O_HTTP_TUN; |
| 4755 | goto out; |
| 4756 | } |
| 4757 | else if (kwm == KWM_NO) { |
| 4758 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN) |
| 4759 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 4760 | goto out; |
| 4761 | } |
| 4762 | } |
| 4763 | |
Joseph Lynch | 726ab71 | 2015-05-11 23:25:34 -0700 | [diff] [blame] | 4764 | /* Redispatch can take an integer argument that control when the |
| 4765 | * resispatch occurs. All values are relative to the retries option. |
| 4766 | * This can be cancelled using "no option xxx". |
| 4767 | */ |
| 4768 | if (strcmp(args[1], "redispatch") == 0) { |
| 4769 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 4770 | err_code |= ERR_WARN; |
| 4771 | goto out; |
| 4772 | } |
| 4773 | |
| 4774 | curproxy->no_options &= ~PR_O_REDISP; |
| 4775 | curproxy->options &= ~PR_O_REDISP; |
| 4776 | |
| 4777 | switch (kwm) { |
| 4778 | case KWM_STD: |
| 4779 | curproxy->options |= PR_O_REDISP; |
| 4780 | curproxy->redispatch_after = -1; |
| 4781 | if(*args[2]) { |
| 4782 | curproxy->redispatch_after = atol(args[2]); |
| 4783 | } |
| 4784 | break; |
| 4785 | case KWM_NO: |
| 4786 | curproxy->no_options |= PR_O_REDISP; |
| 4787 | curproxy->redispatch_after = 0; |
| 4788 | break; |
| 4789 | case KWM_DEF: /* already cleared */ |
| 4790 | break; |
| 4791 | } |
| 4792 | goto out; |
| 4793 | } |
| 4794 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 4795 | if (kwm != KWM_STD) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4796 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 4797 | file, linenum, args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4799 | goto out; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4802 | if (!strcmp(args[1], "httplog")) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4803 | char *logformat; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4804 | /* generate a complete HTTP log */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4805 | logformat = default_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4806 | if (*(args[2]) != '\0') { |
| 4807 | if (!strcmp(args[2], "clf")) { |
| 4808 | curproxy->options2 |= PR_O2_CLFLOG; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 4809 | logformat = clf_http_log_format; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4810 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4811 | 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] | 4812 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4813 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4814 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4815 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 4816 | goto out; |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4817 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4818 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4819 | char *oldlogformat = "log-format"; |
| 4820 | char *clflogformat = ""; |
| 4821 | |
| 4822 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4823 | oldlogformat = "option httplog"; |
| 4824 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4825 | oldlogformat = "option tcplog"; |
| 4826 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4827 | oldlogformat = "option httplog clf"; |
| 4828 | if (logformat == clf_http_log_format) |
| 4829 | clflogformat = " clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4830 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 4831 | file, linenum, clflogformat, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4832 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4833 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4834 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4835 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4836 | free(curproxy->conf.logformat_string); |
| 4837 | curproxy->conf.logformat_string = logformat; |
| 4838 | |
| 4839 | free(curproxy->conf.lfs_file); |
| 4840 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4841 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4842 | |
| 4843 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4844 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 4845 | file, linenum, curproxy->id); |
| 4846 | err_code |= ERR_WARN; |
| 4847 | } |
Emeric Brun | 3a058f3 | 2009-06-30 18:26:00 +0200 | [diff] [blame] | 4848 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4849 | else if (!strcmp(args[1], "tcplog")) { |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4850 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 4851 | char *oldlogformat = "log-format"; |
| 4852 | |
| 4853 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 4854 | oldlogformat = "option httplog"; |
| 4855 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 4856 | oldlogformat = "option tcplog"; |
| 4857 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 4858 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4859 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 4860 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 4861 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4862 | /* generate a detailed TCP log */ |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 4863 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 4864 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 4865 | curproxy->conf.logformat_string != clf_http_log_format) |
| 4866 | free(curproxy->conf.logformat_string); |
| 4867 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 4868 | |
| 4869 | free(curproxy->conf.lfs_file); |
| 4870 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 4871 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4872 | |
| 4873 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4874 | goto out; |
Tim Duesterhus | 9ad9f35 | 2018-02-05 20:52:27 +0100 | [diff] [blame] | 4875 | |
| 4876 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
| 4877 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 4878 | file, linenum, curproxy->id); |
| 4879 | err_code |= ERR_WARN; |
| 4880 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 4881 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4882 | else if (!strcmp(args[1], "tcpka")) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4883 | /* enable TCP keep-alives on client and server streams */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4884 | 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] | 4885 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4886 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4887 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4888 | goto out; |
| 4889 | |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4890 | if (curproxy->cap & PR_CAP_FE) |
| 4891 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 4892 | if (curproxy->cap & PR_CAP_BE) |
| 4893 | curproxy->options |= PR_O_TCP_SRV_KA; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4894 | } |
| 4895 | else if (!strcmp(args[1], "httpchk")) { |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4896 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4897 | err_code |= ERR_WARN; |
| 4898 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4899 | /* use HTTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4900 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4901 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4902 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4903 | curproxy->options2 |= PR_O2_HTTP_CHK; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4904 | if (!*args[2]) { /* no argument */ |
| 4905 | curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */ |
| 4906 | curproxy->check_len = strlen(DEF_CHECK_REQ); |
| 4907 | } else if (!*args[3]) { /* one argument : URI */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4908 | 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] | 4909 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4910 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4911 | "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4912 | } else { /* more arguments : METHOD URI [HTTP_VER] */ |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4913 | int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n"); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4914 | if (*args[4]) |
| 4915 | reqlen += strlen(args[4]); |
| 4916 | else |
| 4917 | reqlen += strlen("HTTP/1.0"); |
| 4918 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4919 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4920 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 4921 | "%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] | 4922 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4923 | if (alertif_too_many_args_idx(3, 1, file, linenum, args, &err_code)) |
| 4924 | goto out; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 4925 | } |
| 4926 | else if (!strcmp(args[1], "ssl-hello-chk")) { |
| 4927 | /* use SSLv3 CLIENT HELLO to check servers' health */ |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4928 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 4929 | err_code |= ERR_WARN; |
Willy Tarreau | 13943ab | 2006-12-31 00:24:10 +0100 | [diff] [blame] | 4930 | |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4931 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4932 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4933 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 4934 | curproxy->options2 |= PR_O2_SSL3_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4935 | |
| 4936 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 4937 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 4938 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4939 | else if (!strcmp(args[1], "smtpchk")) { |
| 4940 | /* use SMTP request to check servers' health */ |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 4941 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 4942 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4943 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 4944 | curproxy->options2 |= PR_O2_SMTP_CHK; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4945 | |
| 4946 | if (!*args[2] || !*args[3]) { /* no argument or incomplete EHLO host */ |
| 4947 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4948 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4949 | } else { /* ESMTP EHLO, or SMTP HELO, and a hostname */ |
| 4950 | if (!strcmp(args[2], "EHLO") || !strcmp(args[2], "HELO")) { |
| 4951 | int reqlen = strlen(args[2]) + strlen(args[3]) + strlen(" \r\n") + 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4952 | curproxy->check_req = malloc(reqlen); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4953 | curproxy->check_len = snprintf(curproxy->check_req, reqlen, |
| 4954 | "%s %s\r\n", args[2], args[3]); /* HELO hostname */ |
| 4955 | } else { |
| 4956 | /* this just hits the default for now, but you could potentially expand it to allow for other stuff |
| 4957 | though, it's unlikely you'd want to send anything other than an EHLO or HELO */ |
| 4958 | curproxy->check_req = strdup(DEF_SMTP_CHECK_REQ); /* default request */ |
| 4959 | curproxy->check_len = strlen(DEF_SMTP_CHECK_REQ); |
| 4960 | } |
| 4961 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 4962 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 4963 | goto out; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 4964 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4965 | else if (!strcmp(args[1], "pgsql-check")) { |
| 4966 | /* use PostgreSQL request to check servers' health */ |
| 4967 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 4968 | err_code |= ERR_WARN; |
| 4969 | |
| 4970 | free(curproxy->check_req); |
| 4971 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 4972 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4973 | curproxy->options2 |= PR_O2_PGSQL_CHK; |
| 4974 | |
| 4975 | if (*(args[2])) { |
| 4976 | int cur_arg = 2; |
| 4977 | |
| 4978 | while (*(args[cur_arg])) { |
| 4979 | if (strcmp(args[cur_arg], "user") == 0) { |
| 4980 | char * packet; |
| 4981 | uint32_t packet_len; |
| 4982 | uint32_t pv; |
| 4983 | |
| 4984 | /* suboption header - needs additional argument for it */ |
| 4985 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 4986 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 4987 | file, linenum, args[0], args[1], args[cur_arg]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4989 | goto out; |
| 4990 | } |
| 4991 | |
| 4992 | /* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */ |
| 4993 | packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1; |
| 4994 | pv = htonl(0x30000); /* protocol version 3.0 */ |
| 4995 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 4996 | packet = calloc(1, packet_len); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 4997 | |
| 4998 | memcpy(packet + 4, &pv, 4); |
| 4999 | |
| 5000 | /* copy "user" */ |
| 5001 | memcpy(packet + 8, "user", 4); |
| 5002 | |
| 5003 | /* copy username */ |
| 5004 | memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1])); |
| 5005 | |
| 5006 | free(curproxy->check_req); |
| 5007 | curproxy->check_req = packet; |
| 5008 | curproxy->check_len = packet_len; |
| 5009 | |
| 5010 | packet_len = htonl(packet_len); |
| 5011 | memcpy(packet, &packet_len, 4); |
| 5012 | cur_arg += 2; |
| 5013 | } else { |
| 5014 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5015 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5016 | file, linenum, args[0], args[1]); |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5018 | goto out; |
| 5019 | } |
| 5020 | } /* end while loop */ |
| 5021 | } |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5022 | if (alertif_too_many_args_idx(2, 1, file, linenum, args, &err_code)) |
| 5023 | goto out; |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 5024 | } |
| 5025 | |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5026 | else if (!strcmp(args[1], "redis-check")) { |
| 5027 | /* use REDIS PING request to check servers' health */ |
| 5028 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5029 | err_code |= ERR_WARN; |
| 5030 | |
| 5031 | free(curproxy->check_req); |
| 5032 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5033 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5034 | curproxy->options2 |= PR_O2_REDIS_CHK; |
| 5035 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5036 | curproxy->check_req = malloc(sizeof(DEF_REDIS_CHECK_REQ) - 1); |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5037 | memcpy(curproxy->check_req, DEF_REDIS_CHECK_REQ, sizeof(DEF_REDIS_CHECK_REQ) - 1); |
| 5038 | curproxy->check_len = sizeof(DEF_REDIS_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5039 | |
| 5040 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5041 | goto out; |
Hervé COMMOWICK | ec032d6 | 2011-08-05 16:23:48 +0200 | [diff] [blame] | 5042 | } |
| 5043 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5044 | else if (!strcmp(args[1], "mysql-check")) { |
| 5045 | /* use MYSQL request to check servers' health */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5046 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5047 | err_code |= ERR_WARN; |
| 5048 | |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5049 | free(curproxy->check_req); |
Willy Tarreau | 54f6a58 | 2010-02-01 16:31:14 +0100 | [diff] [blame] | 5050 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5051 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5052 | curproxy->options2 |= PR_O2_MYSQL_CHK; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5053 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5054 | /* 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] | 5055 | * const char mysql40_client_auth_pkt[] = { |
| 5056 | * "\x0e\x00\x00" // packet length |
| 5057 | * "\x01" // packet number |
| 5058 | * "\x00\x00" // client capabilities |
| 5059 | * "\x00\x00\x01" // max packet |
| 5060 | * "haproxy\x00" // username (null terminated string) |
| 5061 | * "\x00" // filler (always 0x00) |
| 5062 | * "\x01\x00\x00" // packet length |
| 5063 | * "\x00" // packet number |
| 5064 | * "\x01" // COM_QUIT command |
| 5065 | * }; |
| 5066 | */ |
| 5067 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5068 | /* This is an example of a MySQL >=4.1 client Authentication packet provided by Nenad Merdanovic. |
| 5069 | * const char mysql41_client_auth_pkt[] = { |
| 5070 | * "\x0e\x00\x00\" // packet length |
| 5071 | * "\x01" // packet number |
| 5072 | * "\x00\x00\x00\x00" // client capabilities |
| 5073 | * "\x00\x00\x00\x01" // max packet |
| 5074 | * "\x21" // character set (UTF-8) |
| 5075 | * char[23] // All zeroes |
| 5076 | * "haproxy\x00" // username (null terminated string) |
| 5077 | * "\x00" // filler (always 0x00) |
| 5078 | * "\x01\x00\x00" // packet length |
| 5079 | * "\x00" // packet number |
| 5080 | * "\x01" // COM_QUIT command |
| 5081 | * }; |
| 5082 | */ |
| 5083 | |
| 5084 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5085 | if (*(args[2])) { |
| 5086 | int cur_arg = 2; |
| 5087 | |
| 5088 | while (*(args[cur_arg])) { |
| 5089 | if (strcmp(args[cur_arg], "user") == 0) { |
| 5090 | char *mysqluser; |
| 5091 | int packetlen, reqlen, userlen; |
| 5092 | |
| 5093 | /* suboption header - needs additional argument for it */ |
| 5094 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5095 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n", |
| 5096 | file, linenum, args[0], args[1], args[cur_arg]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5098 | goto out; |
| 5099 | } |
| 5100 | mysqluser = args[cur_arg + 1]; |
| 5101 | userlen = strlen(mysqluser); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5102 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5103 | if (*(args[cur_arg+2])) { |
| 5104 | if (!strcmp(args[cur_arg+2], "post-41")) { |
| 5105 | packetlen = userlen + 7 + 27; |
| 5106 | reqlen = packetlen + 9; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5107 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5108 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5109 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5110 | curproxy->check_len = reqlen; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5111 | |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5112 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5113 | ((unsigned char) packetlen & 0xff), |
| 5114 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5115 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5116 | |
| 5117 | curproxy->check_req[3] = 1; |
| 5118 | curproxy->check_req[5] = 130; |
| 5119 | curproxy->check_req[11] = 1; |
| 5120 | curproxy->check_req[12] = 33; |
| 5121 | memcpy(&curproxy->check_req[36], mysqluser, userlen); |
| 5122 | curproxy->check_req[36 + userlen + 1 + 1] = 1; |
| 5123 | curproxy->check_req[36 + userlen + 1 + 1 + 4] = 1; |
| 5124 | cur_arg += 3; |
| 5125 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5126 | 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] | 5127 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5128 | goto out; |
| 5129 | } |
| 5130 | } else { |
| 5131 | packetlen = userlen + 7; |
| 5132 | reqlen = packetlen + 9; |
| 5133 | |
| 5134 | free(curproxy->check_req); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5135 | curproxy->check_req = calloc(1, reqlen); |
Nenad Merdanovic | 6639a7c | 2014-05-30 14:26:32 +0200 | [diff] [blame] | 5136 | curproxy->check_len = reqlen; |
| 5137 | |
| 5138 | snprintf(curproxy->check_req, 4, "%c%c%c", |
| 5139 | ((unsigned char) packetlen & 0xff), |
| 5140 | ((unsigned char) (packetlen >> 8) & 0xff), |
| 5141 | ((unsigned char) (packetlen >> 16) & 0xff)); |
| 5142 | |
| 5143 | curproxy->check_req[3] = 1; |
| 5144 | curproxy->check_req[5] = 128; |
| 5145 | curproxy->check_req[8] = 1; |
| 5146 | memcpy(&curproxy->check_req[9], mysqluser, userlen); |
| 5147 | curproxy->check_req[9 + userlen + 1 + 1] = 1; |
| 5148 | curproxy->check_req[9 + userlen + 1 + 1 + 4] = 1; |
| 5149 | cur_arg += 2; |
| 5150 | } |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5151 | } else { |
| 5152 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5153 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n", |
| 5154 | file, linenum, args[0], args[1]); |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 5155 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5156 | goto out; |
| 5157 | } |
| 5158 | } /* end while loop */ |
| 5159 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 5160 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5161 | else if (!strcmp(args[1], "ldap-check")) { |
| 5162 | /* use LDAP request to check servers' health */ |
| 5163 | free(curproxy->check_req); |
| 5164 | curproxy->check_req = NULL; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5165 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5166 | curproxy->options2 |= PR_O2_LDAP_CHK; |
| 5167 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5168 | curproxy->check_req = malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1); |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5169 | memcpy(curproxy->check_req, DEF_LDAP_CHECK_REQ, sizeof(DEF_LDAP_CHECK_REQ) - 1); |
| 5170 | curproxy->check_len = sizeof(DEF_LDAP_CHECK_REQ) - 1; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5171 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5172 | goto out; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 5173 | } |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5174 | else if (!strcmp(args[1], "spop-check")) { |
| 5175 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5176 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", |
| 5177 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5178 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5179 | goto out; |
| 5180 | } |
| 5181 | if (curproxy->cap & PR_CAP_FE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5182 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'frontend' and 'listen' sections.\n", |
| 5183 | file, linenum, args[0], args[1]); |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 5184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5185 | goto out; |
| 5186 | } |
| 5187 | |
| 5188 | /* use SPOE request to check servers' health */ |
| 5189 | free(curproxy->check_req); |
| 5190 | curproxy->check_req = NULL; |
| 5191 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5192 | curproxy->options2 |= PR_O2_SPOP_CHK; |
| 5193 | |
Christopher Faulet | 8ef7525 | 2017-02-20 22:56:03 +0100 | [diff] [blame] | 5194 | if (spoe_prepare_healthcheck_request(&curproxy->check_req, &curproxy->check_len)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5195 | 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] | 5196 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5197 | goto out; |
| 5198 | } |
| 5199 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5200 | goto out; |
| 5201 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5202 | else if (!strcmp(args[1], "tcp-check")) { |
| 5203 | /* use raw TCPCHK send/expect to check servers' health */ |
| 5204 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) |
| 5205 | err_code |= ERR_WARN; |
| 5206 | |
| 5207 | free(curproxy->check_req); |
| 5208 | curproxy->check_req = NULL; |
| 5209 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5210 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5211 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5212 | goto out; |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5213 | } |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5214 | else if (!strcmp(args[1], "external-check")) { |
| 5215 | /* excute an external command to check servers' health */ |
| 5216 | free(curproxy->check_req); |
| 5217 | curproxy->check_req = NULL; |
| 5218 | curproxy->options2 &= ~PR_O2_CHK_ANY; |
| 5219 | curproxy->options2 |= PR_O2_EXT_CHK; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5220 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5221 | goto out; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 5222 | } |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5223 | else if (!strcmp(args[1], "forwardfor")) { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5224 | int cur_arg; |
| 5225 | |
| 5226 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
| 5227 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5228 | */ |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5229 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5230 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5231 | |
| 5232 | free(curproxy->fwdfor_hdr_name); |
| 5233 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 5234 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 5235 | |
| 5236 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 5237 | cur_arg = 2; |
| 5238 | while (*(args[cur_arg])) { |
| 5239 | if (!strcmp(args[cur_arg], "except")) { |
| 5240 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5241 | 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] | 5242 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5243 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5245 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5246 | } |
| 5247 | /* flush useless bits */ |
| 5248 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5249 | cur_arg += 2; |
| 5250 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5251 | /* suboption header - needs additional argument for it */ |
| 5252 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5253 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5254 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5255 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5256 | goto out; |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5257 | } |
| 5258 | free(curproxy->fwdfor_hdr_name); |
| 5259 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 5260 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 5261 | cur_arg += 2; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5262 | } else if (!strcmp(args[cur_arg], "if-none")) { |
| 5263 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 5264 | cur_arg += 1; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5265 | } else { |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5266 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5267 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 5268 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5270 | goto out; |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5271 | } |
Ross West | af72a1d | 2008-08-03 10:51:45 +0200 | [diff] [blame] | 5272 | } /* end while loop */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 5273 | } |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5274 | else if (!strcmp(args[1], "originalto")) { |
| 5275 | int cur_arg; |
| 5276 | |
| 5277 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 5278 | * set default options (ie: bitfield, header name, etc) |
| 5279 | */ |
| 5280 | |
| 5281 | curproxy->options |= PR_O_ORGTO; |
| 5282 | |
| 5283 | free(curproxy->orgto_hdr_name); |
| 5284 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 5285 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 5286 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 5287 | /* 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] | 5288 | cur_arg = 2; |
| 5289 | while (*(args[cur_arg])) { |
| 5290 | if (!strcmp(args[cur_arg], "except")) { |
| 5291 | /* suboption except - needs additional argument for it */ |
Thierry FOURNIER | fc7ac7b | 2014-02-11 15:23:04 +0100 | [diff] [blame] | 5292 | 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] | 5293 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 5294 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5296 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5297 | } |
| 5298 | /* flush useless bits */ |
| 5299 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 5300 | cur_arg += 2; |
| 5301 | } else if (!strcmp(args[cur_arg], "header")) { |
| 5302 | /* suboption header - needs additional argument for it */ |
| 5303 | if (*(args[cur_arg+1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5304 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 5305 | file, linenum, args[0], args[1], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5306 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5307 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5308 | } |
| 5309 | free(curproxy->orgto_hdr_name); |
| 5310 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 5311 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 5312 | cur_arg += 2; |
| 5313 | } else { |
| 5314 | /* unknown suboption - catchall */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5315 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 5316 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5317 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5318 | goto out; |
Maik Broemme | 2850cb4 | 2009-04-17 18:53:21 +0200 | [diff] [blame] | 5319 | } |
| 5320 | } /* end while loop */ |
| 5321 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5322 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5323 | 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] | 5324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5325 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5326 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5327 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5328 | } |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5329 | else if (!strcmp(args[0], "default_backend")) { |
| 5330 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5331 | err_code |= ERR_WARN; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5332 | |
| 5333 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5334 | 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] | 5335 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5336 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5337 | } |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 5338 | free(curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5339 | curproxy->defbe.name = strdup(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5340 | |
| 5341 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5342 | goto out; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 5343 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5344 | else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) { |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5345 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5346 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5347 | |
Willy Tarreau | a3c504c | 2014-04-28 22:37:32 +0200 | [diff] [blame] | 5348 | if (!already_warned(WARN_REDISPATCH_DEPRECATED)) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5349 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'option redispatch', and will not be supported by future versions.\n", |
| 5350 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5351 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5352 | /* enable reconnections to dispatch */ |
| 5353 | curproxy->options |= PR_O_REDISP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5354 | |
| 5355 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 5356 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5357 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5358 | else if (!strcmp(args[0], "http-reuse")) { |
| 5359 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5360 | err_code |= ERR_WARN; |
| 5361 | |
| 5362 | if (strcmp(args[1], "never") == 0) { |
| 5363 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5364 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5365 | curproxy->options |= PR_O_REUSE_NEVR; |
| 5366 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5367 | goto out; |
| 5368 | } |
Willy Tarreau | 161d45f | 2015-08-05 16:02:46 +0200 | [diff] [blame] | 5369 | else if (strcmp(args[1], "safe") == 0) { |
| 5370 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5371 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5372 | curproxy->options |= PR_O_REUSE_SAFE; |
| 5373 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5374 | goto out; |
| 5375 | } |
Willy Tarreau | 449d74a | 2015-08-05 17:16:33 +0200 | [diff] [blame] | 5376 | else if (strcmp(args[1], "aggressive") == 0) { |
| 5377 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 5378 | curproxy->options |= PR_O_REUSE_AGGR; |
| 5379 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5380 | goto out; |
| 5381 | } |
Willy Tarreau | d8fecee | 2015-08-05 14:12:31 +0200 | [diff] [blame] | 5382 | else if (strcmp(args[1], "always") == 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_ALWS; |
| 5386 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5387 | goto out; |
| 5388 | } |
| 5389 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5390 | 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] | 5391 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5392 | goto out; |
| 5393 | } |
| 5394 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5395 | else if (!strcmp(args[0], "http-check")) { |
| 5396 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5397 | err_code |= ERR_WARN; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5398 | |
| 5399 | if (strcmp(args[1], "disable-on-404") == 0) { |
| 5400 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 5401 | curproxy->options |= PR_O_DISABLE404; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5402 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5403 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5404 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5405 | else if (strcmp(args[1], "send-state") == 0) { |
| 5406 | /* enable emission of the apparent state of a server in HTTP checks */ |
| 5407 | curproxy->options2 |= PR_O2_CHK_SNDST; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5408 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 5409 | goto out; |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 5410 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5411 | else if (strcmp(args[1], "expect") == 0) { |
| 5412 | const char *ptr_arg; |
| 5413 | int cur_arg; |
| 5414 | |
| 5415 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5416 | 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] | 5417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5418 | goto out; |
| 5419 | } |
| 5420 | |
| 5421 | cur_arg = 2; |
| 5422 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5423 | while (*(ptr_arg = args[cur_arg])) { |
| 5424 | while (*ptr_arg == '!') { |
| 5425 | curproxy->options2 ^= PR_O2_EXP_INV; |
| 5426 | ptr_arg++; |
| 5427 | } |
| 5428 | if (*ptr_arg) |
| 5429 | break; |
| 5430 | cur_arg++; |
| 5431 | } |
| 5432 | /* now ptr_arg points to the beginning of a word past any possible |
| 5433 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5434 | */ |
| 5435 | if (strcmp(ptr_arg, "status") == 0) { |
| 5436 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5437 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5438 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5439 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5440 | goto out; |
| 5441 | } |
| 5442 | curproxy->options2 |= PR_O2_EXP_STS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5443 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5444 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5445 | } |
| 5446 | else if (strcmp(ptr_arg, "string") == 0) { |
| 5447 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5448 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5449 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5450 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5451 | goto out; |
| 5452 | } |
| 5453 | curproxy->options2 |= PR_O2_EXP_STR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5454 | free(curproxy->expect_str); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5455 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
| 5456 | } |
| 5457 | else if (strcmp(ptr_arg, "rstatus") == 0) { |
| 5458 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5459 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5460 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5461 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5462 | goto out; |
| 5463 | } |
| 5464 | curproxy->options2 |= PR_O2_EXP_RSTS; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5465 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5466 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5467 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5468 | free(curproxy->expect_regex); |
| 5469 | curproxy->expect_regex = NULL; |
| 5470 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5471 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5472 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5473 | error = NULL; |
| 5474 | 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] | 5475 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5476 | 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] | 5477 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5479 | goto out; |
| 5480 | } |
| 5481 | } |
| 5482 | else if (strcmp(ptr_arg, "rstring") == 0) { |
| 5483 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5484 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5485 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5487 | goto out; |
| 5488 | } |
| 5489 | curproxy->options2 |= PR_O2_EXP_RSTR; |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5490 | free(curproxy->expect_str); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5491 | if (curproxy->expect_regex) { |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5492 | regex_free(curproxy->expect_regex); |
Thierry FOURNIER | 148f408 | 2014-06-11 14:45:31 +0200 | [diff] [blame] | 5493 | free(curproxy->expect_regex); |
| 5494 | curproxy->expect_regex = NULL; |
| 5495 | } |
Willy Tarreau | 1ee51a6 | 2011-08-19 20:04:17 +0200 | [diff] [blame] | 5496 | curproxy->expect_str = strdup(args[cur_arg + 1]); |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5497 | curproxy->expect_regex = calloc(1, sizeof(*curproxy->expect_regex)); |
| 5498 | error = NULL; |
| 5499 | 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] | 5500 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5501 | 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] | 5502 | free(error); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5503 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5504 | goto out; |
| 5505 | } |
| 5506 | } |
| 5507 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5508 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'status', 'string', 'rstatus', 'rstring', found '%s'.\n", |
| 5509 | file, linenum, args[0], args[1], ptr_arg); |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 5510 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5511 | goto out; |
| 5512 | } |
| 5513 | } |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5514 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5515 | 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] | 5516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5517 | goto out; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 5518 | } |
| 5519 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5520 | else if (!strcmp(args[0], "tcp-check")) { |
| 5521 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 5522 | err_code |= ERR_WARN; |
| 5523 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5524 | if (strcmp(args[1], "comment") == 0) { |
| 5525 | int cur_arg; |
| 5526 | struct tcpcheck_rule *tcpcheck; |
| 5527 | |
| 5528 | cur_arg = 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5529 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5530 | tcpcheck->action = TCPCHK_ACT_COMMENT; |
| 5531 | |
| 5532 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5533 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5534 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5536 | goto out; |
| 5537 | } |
| 5538 | |
| 5539 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5540 | |
| 5541 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5542 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 5543 | goto out; |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5544 | } |
| 5545 | else if (strcmp(args[1], "connect") == 0) { |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5546 | const char *ptr_arg; |
| 5547 | int cur_arg; |
| 5548 | struct tcpcheck_rule *tcpcheck; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5549 | |
| 5550 | /* check if first rule is also a 'connect' action */ |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5551 | tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list); |
| 5552 | while (&tcpcheck->list != &curproxy->tcpcheck_rules && |
| 5553 | tcpcheck->action == TCPCHK_ACT_COMMENT) { |
| 5554 | tcpcheck = LIST_NEXT(&tcpcheck->list, struct tcpcheck_rule *, list); |
| 5555 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5556 | |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5557 | if (&tcpcheck->list != &curproxy->tcpcheck_rules |
| 5558 | && tcpcheck->action != TCPCHK_ACT_CONNECT) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5559 | ha_alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n", |
| 5560 | file, linenum); |
Willy Tarreau | 5581c27 | 2015-05-13 12:24:53 +0200 | [diff] [blame] | 5561 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5562 | goto out; |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | cur_arg = 2; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5566 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5567 | tcpcheck->action = TCPCHK_ACT_CONNECT; |
| 5568 | |
| 5569 | /* parsing each parameters to fill up the rule */ |
| 5570 | while (*(ptr_arg = args[cur_arg])) { |
| 5571 | /* tcp port */ |
| 5572 | if (strcmp(args[cur_arg], "port") == 0) { |
| 5573 | if ( (atol(args[cur_arg + 1]) > 65535) || |
| 5574 | (atol(args[cur_arg + 1]) < 1) ){ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5575 | ha_alert("parsing [%s:%d] : '%s %s %s' expects a valid TCP port (from range 1 to 65535), got %s.\n", |
| 5576 | file, linenum, args[0], args[1], "port", args[cur_arg + 1]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5577 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5578 | goto out; |
| 5579 | } |
| 5580 | tcpcheck->port = atol(args[cur_arg + 1]); |
| 5581 | cur_arg += 2; |
| 5582 | } |
| 5583 | /* send proxy protocol */ |
| 5584 | else if (strcmp(args[cur_arg], "send-proxy") == 0) { |
| 5585 | tcpcheck->conn_opts |= TCPCHK_OPT_SEND_PROXY; |
| 5586 | cur_arg++; |
| 5587 | } |
| 5588 | #ifdef USE_OPENSSL |
| 5589 | else if (strcmp(args[cur_arg], "ssl") == 0) { |
| 5590 | curproxy->options |= PR_O_TCPCHK_SSL; |
| 5591 | tcpcheck->conn_opts |= TCPCHK_OPT_SSL; |
| 5592 | cur_arg++; |
| 5593 | } |
| 5594 | #endif /* USE_OPENSSL */ |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5595 | /* comment for this tcpcheck line */ |
| 5596 | else if (strcmp(args[cur_arg], "comment") == 0) { |
| 5597 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5598 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5599 | file, linenum, args[cur_arg]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5600 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5601 | goto out; |
| 5602 | } |
| 5603 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5604 | cur_arg += 2; |
| 5605 | } |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5606 | else { |
| 5607 | #ifdef USE_OPENSSL |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5608 | 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] | 5609 | #else /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5610 | 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] | 5611 | #endif /* USE_OPENSSL */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5612 | file, linenum, args[0], args[1], args[cur_arg]); |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 5613 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5614 | goto out; |
| 5615 | } |
| 5616 | |
| 5617 | } |
| 5618 | |
| 5619 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5620 | } |
| 5621 | else if (strcmp(args[1], "send") == 0) { |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5622 | if (! *(args[2]) ) { |
| 5623 | /* SEND string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5624 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <STRING> as argument.\n", |
| 5625 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5627 | goto out; |
| 5628 | } else { |
| 5629 | struct tcpcheck_rule *tcpcheck; |
| 5630 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5631 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5632 | |
| 5633 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5634 | tcpcheck->string_len = strlen(args[2]); |
| 5635 | tcpcheck->string = strdup(args[2]); |
| 5636 | tcpcheck->expect_regex = NULL; |
| 5637 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5638 | /* comment for this tcpcheck line */ |
| 5639 | if (strcmp(args[3], "comment") == 0) { |
| 5640 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5641 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5642 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5643 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5644 | goto out; |
| 5645 | } |
| 5646 | tcpcheck->comment = strdup(args[4]); |
| 5647 | } |
| 5648 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5649 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5650 | } |
| 5651 | } |
| 5652 | else if (strcmp(args[1], "send-binary") == 0) { |
| 5653 | if (! *(args[2]) ) { |
| 5654 | /* SEND binary string expected */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5655 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument.\n", |
| 5656 | file, linenum, args[0], args[1], args[2]); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5657 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5658 | goto out; |
| 5659 | } else { |
| 5660 | struct tcpcheck_rule *tcpcheck; |
| 5661 | char *err = NULL; |
| 5662 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5663 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5664 | |
| 5665 | tcpcheck->action = TCPCHK_ACT_SEND; |
| 5666 | if (parse_binary(args[2], &tcpcheck->string, &tcpcheck->string_len, &err) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5667 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5668 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5670 | goto out; |
| 5671 | } |
| 5672 | tcpcheck->expect_regex = NULL; |
| 5673 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5674 | /* comment for this tcpcheck line */ |
| 5675 | if (strcmp(args[3], "comment") == 0) { |
| 5676 | if (!*args[4]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5677 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5678 | file, linenum, args[3]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5680 | goto out; |
| 5681 | } |
| 5682 | tcpcheck->comment = strdup(args[4]); |
| 5683 | } |
| 5684 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5685 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5686 | } |
| 5687 | } |
| 5688 | else if (strcmp(args[1], "expect") == 0) { |
| 5689 | const char *ptr_arg; |
| 5690 | int cur_arg; |
| 5691 | int inverse = 0; |
| 5692 | |
| 5693 | if (curproxy->options2 & PR_O2_EXP_TYPE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5694 | 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] | 5695 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5696 | goto out; |
| 5697 | } |
| 5698 | |
| 5699 | cur_arg = 2; |
| 5700 | /* consider exclamation marks, sole or at the beginning of a word */ |
| 5701 | while (*(ptr_arg = args[cur_arg])) { |
| 5702 | while (*ptr_arg == '!') { |
| 5703 | inverse = !inverse; |
| 5704 | ptr_arg++; |
| 5705 | } |
| 5706 | if (*ptr_arg) |
| 5707 | break; |
| 5708 | cur_arg++; |
| 5709 | } |
| 5710 | /* now ptr_arg points to the beginning of a word past any possible |
| 5711 | * exclamation mark, and cur_arg is the argument which holds this word. |
| 5712 | */ |
| 5713 | if (strcmp(ptr_arg, "binary") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5714 | struct tcpcheck_rule *tcpcheck; |
| 5715 | char *err = NULL; |
| 5716 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5717 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5718 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <binary string> as an argument.\n", |
| 5719 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5720 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5721 | goto out; |
| 5722 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5723 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5724 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5725 | |
| 5726 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5727 | 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] | 5728 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <BINARY STRING> as argument, but %s\n", |
| 5729 | file, linenum, args[0], args[1], args[2], err); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5730 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5731 | goto out; |
| 5732 | } |
| 5733 | tcpcheck->expect_regex = NULL; |
| 5734 | tcpcheck->inverse = inverse; |
| 5735 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5736 | /* tcpcheck comment */ |
| 5737 | cur_arg += 2; |
| 5738 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5739 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5740 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5741 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5742 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5743 | goto out; |
| 5744 | } |
| 5745 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5746 | } |
| 5747 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5748 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5749 | } |
| 5750 | else if (strcmp(ptr_arg, "string") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5751 | struct tcpcheck_rule *tcpcheck; |
| 5752 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5753 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5754 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <string> as an argument.\n", |
| 5755 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5757 | goto out; |
| 5758 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5759 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5760 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5761 | |
| 5762 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5763 | tcpcheck->string_len = strlen(args[cur_arg + 1]); |
| 5764 | tcpcheck->string = strdup(args[cur_arg + 1]); |
| 5765 | tcpcheck->expect_regex = NULL; |
| 5766 | tcpcheck->inverse = inverse; |
| 5767 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5768 | /* tcpcheck comment */ |
| 5769 | cur_arg += 2; |
| 5770 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5771 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5772 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5773 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5774 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5775 | goto out; |
| 5776 | } |
| 5777 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5778 | } |
| 5779 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5780 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5781 | } |
| 5782 | else if (strcmp(ptr_arg, "rstring") == 0) { |
Willy Tarreau | e7acee7 | 2015-02-27 16:37:05 +0100 | [diff] [blame] | 5783 | struct tcpcheck_rule *tcpcheck; |
| 5784 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5785 | if (!*(args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5786 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n", |
| 5787 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5789 | goto out; |
| 5790 | } |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5791 | |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 5792 | tcpcheck = calloc(1, sizeof(*tcpcheck)); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5793 | |
| 5794 | tcpcheck->action = TCPCHK_ACT_EXPECT; |
| 5795 | tcpcheck->string_len = 0; |
| 5796 | tcpcheck->string = NULL; |
Thierry FOURNIER | 09af0d6 | 2014-06-18 11:35:54 +0200 | [diff] [blame] | 5797 | tcpcheck->expect_regex = calloc(1, sizeof(*tcpcheck->expect_regex)); |
| 5798 | error = NULL; |
| 5799 | 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] | 5800 | ha_alert("parsing [%s:%d] : '%s %s %s' : bad regular expression '%s': %s.\n", |
| 5801 | 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] | 5802 | free(error); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5803 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5804 | goto out; |
| 5805 | } |
| 5806 | tcpcheck->inverse = inverse; |
| 5807 | |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5808 | /* tcpcheck comment */ |
| 5809 | cur_arg += 2; |
| 5810 | if (strcmp(args[cur_arg], "comment") == 0) { |
| 5811 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5812 | ha_alert("parsing [%s:%d] : '%s' expects a comment string.\n", |
| 5813 | file, linenum, args[cur_arg + 1]); |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 5814 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5815 | goto out; |
| 5816 | } |
| 5817 | tcpcheck->comment = strdup(args[cur_arg + 1]); |
| 5818 | } |
| 5819 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5820 | LIST_ADDQ(&curproxy->tcpcheck_rules, &tcpcheck->list); |
| 5821 | } |
| 5822 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5823 | ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n", |
| 5824 | file, linenum, args[0], args[1], ptr_arg); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 5825 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5826 | goto out; |
| 5827 | } |
| 5828 | } |
| 5829 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5830 | 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] | 5831 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5832 | goto out; |
| 5833 | } |
| 5834 | } |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5835 | else if (!strcmp(args[0], "monitor")) { |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5836 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5837 | 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] | 5838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5839 | goto out; |
Willy Tarreau | b099aca | 2008-10-12 17:26:37 +0200 | [diff] [blame] | 5840 | } |
| 5841 | |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5842 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5843 | err_code |= ERR_WARN; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5844 | |
| 5845 | if (strcmp(args[1], "fail") == 0) { |
| 5846 | /* add a condition to fail monitor requests */ |
Willy Tarreau | ef6494c | 2010-01-28 17:12:36 +0100 | [diff] [blame] | 5847 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5848 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 5849 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5850 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5851 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5852 | } |
| 5853 | |
Willy Tarreau | 721d8e0 | 2017-12-01 18:25:08 +0100 | [diff] [blame] | 5854 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 5855 | 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] | 5856 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 5857 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5859 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5860 | } |
| 5861 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 5862 | } |
| 5863 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5864 | 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] | 5865 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5866 | goto out; |
Willy Tarreau | b80c230 | 2007-11-30 20:51:32 +0100 | [diff] [blame] | 5867 | } |
| 5868 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5869 | #ifdef TPROXY |
| 5870 | else if (!strcmp(args[0], "transparent")) { |
| 5871 | /* enable transparent proxy connections */ |
| 5872 | curproxy->options |= PR_O_TRANSP; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5873 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 5874 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5875 | } |
| 5876 | #endif |
| 5877 | else if (!strcmp(args[0], "maxconn")) { /* maxconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5878 | 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] | 5879 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5880 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5881 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5882 | 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] | 5883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5884 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5885 | } |
| 5886 | curproxy->maxconn = atol(args[1]); |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5887 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5888 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5889 | } |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5890 | else if (!strcmp(args[0], "backlog")) { /* backlog */ |
| 5891 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5892 | err_code |= ERR_WARN; |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5893 | |
| 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 | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5898 | } |
| 5899 | curproxy->backlog = 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 | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 5902 | } |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5903 | else if (!strcmp(args[0], "fullconn")) { /* fullconn */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5904 | 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] | 5905 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5906 | |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 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 | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5911 | } |
| 5912 | curproxy->fullconn = 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 | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 5915 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5916 | else if (!strcmp(args[0], "grace")) { /* grace time (ms) */ |
| 5917 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5918 | 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] | 5919 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5920 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5921 | } |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5922 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
| 5923 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5924 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 5925 | file, linenum, *err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5926 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5927 | goto out; |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 5928 | } |
| 5929 | curproxy->grace = val; |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5930 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5931 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5932 | } |
| 5933 | else if (!strcmp(args[0], "dispatch")) { /* dispatch address */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 5934 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5935 | int port1, port2; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5936 | struct protocol *proto; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5937 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5938 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5939 | 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] | 5940 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5941 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5942 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5943 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5944 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5945 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 5946 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5947 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5948 | 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] | 5949 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5950 | goto out; |
| 5951 | } |
Willy Tarreau | f3559bf | 2013-03-06 16:52:04 +0100 | [diff] [blame] | 5952 | |
| 5953 | proto = protocol_by_family(sk->ss_family); |
| 5954 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5955 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 5956 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5958 | goto out; |
| 5959 | } |
| 5960 | |
| 5961 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5962 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'.\n", |
| 5963 | file, linenum, args[0], args[1]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5964 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5965 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5966 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5967 | |
| 5968 | if (!port1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5969 | ha_alert("parsing [%s:%d] : '%s' : missing port number in '%s', <addr:port> expected.\n", |
| 5970 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5972 | goto out; |
| 5973 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 5974 | |
William Lallemand | df1425a | 2015-04-28 20:17:49 +0200 | [diff] [blame] | 5975 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 5976 | goto out; |
| 5977 | |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 5978 | curproxy->dispatch_addr = *sk; |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 5979 | curproxy->options |= PR_O_DISPATCH; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5980 | } |
| 5981 | else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5982 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 5983 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 5984 | |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 5985 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 5986 | 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] | 5987 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5988 | goto out; |
Willy Tarreau | 2fcb500 | 2007-05-08 13:35:26 +0200 | [diff] [blame] | 5989 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5990 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 5991 | else if (!strcmp(args[0], "hash-type")) { /* set hashing method */ |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 5992 | /** |
| 5993 | * The syntax for hash-type config element is |
| 5994 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 5995 | * |
| 5996 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 5997 | */ |
| 5998 | 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] | 5999 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6000 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 6001 | err_code |= ERR_WARN; |
| 6002 | |
| 6003 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6004 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 6005 | } |
| 6006 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6007 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 6008 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6009 | else if (strcmp(args[1], "avalanche") == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6010 | 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] | 6011 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6012 | goto out; |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 6013 | } |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 6014 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6015 | 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] | 6016 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6017 | goto out; |
| 6018 | } |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6019 | |
| 6020 | /* set the hash function to use */ |
| 6021 | if (!*args[2]) { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6022 | /* the default algo is sdbm */ |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6023 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6024 | |
| 6025 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 6026 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 6027 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
Bhaskar | 98634f0 | 2013-10-29 23:30:51 -0400 | [diff] [blame] | 6028 | } else { |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6029 | /* set the hash function */ |
| 6030 | if (!strcmp(args[2], "sdbm")) { |
| 6031 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 6032 | } |
| 6033 | else if (!strcmp(args[2], "djb2")) { |
| 6034 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6035 | } |
| 6036 | else if (!strcmp(args[2], "wt6")) { |
Willy Tarreau | a0f4271 | 2013-11-14 14:30:35 +0100 | [diff] [blame] | 6037 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6038 | } |
Willy Tarreau | 324f07f | 2015-01-20 19:44:50 +0100 | [diff] [blame] | 6039 | else if (!strcmp(args[2], "crc32")) { |
| 6040 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 6041 | } |
Bhaskar Maddala | b6c0ac9 | 2013-11-05 11:54:02 -0500 | [diff] [blame] | 6042 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6043 | 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] | 6044 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6045 | goto out; |
| 6046 | } |
| 6047 | |
| 6048 | /* set the hash modifier */ |
| 6049 | if (!strcmp(args[3], "avalanche")) { |
| 6050 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 6051 | } |
| 6052 | else if (*args[3]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6053 | 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] | 6054 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6055 | goto out; |
| 6056 | } |
Krzysztof Piotr Oledzki | c6df066 | 2010-01-05 16:38:49 +0100 | [diff] [blame] | 6057 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6058 | } |
Andrew Rodland | b1f48e3 | 2016-10-25 12:49:05 -0400 | [diff] [blame] | 6059 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 6060 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6061 | 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] | 6062 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6063 | goto out; |
| 6064 | } |
| 6065 | curproxy->lbprm.chash.balance_factor = atol(args[1]); |
| 6066 | 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] | 6067 | 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] | 6068 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6069 | goto out; |
| 6070 | } |
| 6071 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6072 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 6073 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6074 | 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] | 6075 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6076 | goto out; |
| 6077 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6078 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6079 | 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] | 6080 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6081 | goto out; |
| 6082 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6083 | free(curproxy->conf.uniqueid_format_string); |
| 6084 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6085 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6086 | free(curproxy->conf.uif_file); |
| 6087 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 6088 | curproxy->conf.uif_line = curproxy->conf.args.line; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6089 | } |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 6090 | |
| 6091 | else if (strcmp(args[0], "unique-id-header") == 0) { |
| 6092 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6093 | 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] | 6094 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6095 | goto out; |
| 6096 | } |
| 6097 | free(curproxy->header_unique_id); |
| 6098 | curproxy->header_unique_id = strdup(args[1]); |
| 6099 | } |
| 6100 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 6101 | else if (strcmp(args[0], "log-format") == 0) { |
| 6102 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6103 | 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] | 6104 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6105 | goto out; |
| 6106 | } |
William Lallemand | 3203ff4 | 2012-11-11 17:30:56 +0100 | [diff] [blame] | 6107 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6108 | 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] | 6109 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6110 | goto out; |
| 6111 | } |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6112 | if (curproxy->conf.logformat_string && curproxy == &defproxy) { |
| 6113 | char *oldlogformat = "log-format"; |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 6114 | |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6115 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 6116 | oldlogformat = "option httplog"; |
| 6117 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 6118 | oldlogformat = "option tcplog"; |
| 6119 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 6120 | oldlogformat = "option httplog clf"; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6121 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 6122 | file, linenum, oldlogformat); |
Guillaume de Lafond | ea5b0e6 | 2017-03-31 19:54:09 +0200 | [diff] [blame] | 6123 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 6124 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 6125 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 6126 | curproxy->conf.logformat_string != clf_http_log_format) |
| 6127 | free(curproxy->conf.logformat_string); |
| 6128 | curproxy->conf.logformat_string = strdup(args[1]); |
| 6129 | |
| 6130 | free(curproxy->conf.lfs_file); |
| 6131 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 6132 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6133 | |
| 6134 | /* get a chance to improve log-format error reporting by |
| 6135 | * reporting the correct line-number when possible. |
| 6136 | */ |
| 6137 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6138 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 6139 | file, linenum, curproxy->id); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 6140 | err_code |= ERR_WARN; |
| 6141 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6142 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6143 | else if (!strcmp(args[0], "log-format-sd")) { |
| 6144 | if (!*(args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6145 | 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] | 6146 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6147 | goto out; |
| 6148 | } |
| 6149 | if (*(args[2])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6150 | 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] | 6151 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6152 | goto out; |
| 6153 | } |
| 6154 | |
| 6155 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 6156 | free(curproxy->conf.logformat_sd_string); |
| 6157 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 6158 | |
| 6159 | free(curproxy->conf.lfsd_file); |
| 6160 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 6161 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 6162 | |
| 6163 | /* get a chance to improve log-format-sd error reporting by |
| 6164 | * reporting the correct line-number when possible. |
| 6165 | */ |
| 6166 | if (curproxy != &defproxy && !(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6167 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 6168 | file, linenum, curproxy->id); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 6169 | err_code |= ERR_WARN; |
| 6170 | } |
| 6171 | } |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6172 | else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */ |
| 6173 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6174 | 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] | 6175 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6176 | goto out; |
| 6177 | } |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 6178 | chunk_destroy(&curproxy->log_tag); |
| 6179 | chunk_initstr(&curproxy->log_tag, strdup(args[1])); |
Willy Tarreau | 094af4e | 2015-01-07 15:03:42 +0100 | [diff] [blame] | 6180 | } |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 6181 | else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */ |
| 6182 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 6183 | 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] | 6184 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6185 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6186 | } |
| 6187 | } |
| 6188 | 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] | 6189 | int cur_arg; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6190 | int port1, port2; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 6191 | struct sockaddr_storage *sk; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6192 | struct protocol *proto; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6193 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6194 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6195 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6196 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6197 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6198 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 6199 | file, linenum, "source", "usesrc", "interface"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6200 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6201 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6202 | } |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6203 | |
| 6204 | /* we must first clear any optional default setting */ |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6205 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6206 | free(curproxy->conn_src.iface_name); |
| 6207 | curproxy->conn_src.iface_name = NULL; |
| 6208 | curproxy->conn_src.iface_len = 0; |
Willy Tarreau | 368480c | 2009-03-01 08:27:21 +0100 | [diff] [blame] | 6209 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6210 | sk = str2sa_range(args[1], NULL, &port1, &port2, &errmsg, NULL, NULL, 1); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6211 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6212 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6213 | file, linenum, args[0], args[1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6214 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6215 | goto out; |
| 6216 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6217 | |
| 6218 | proto = protocol_by_family(sk->ss_family); |
| 6219 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6220 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6221 | file, linenum, args[0], args[1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6223 | goto out; |
| 6224 | } |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6225 | |
| 6226 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6227 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6228 | file, linenum, args[0], args[1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6230 | goto out; |
| 6231 | } |
| 6232 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6233 | curproxy->conn_src.source_addr = *sk; |
| 6234 | curproxy->conn_src.opts |= CO_SRC_BIND; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6235 | |
| 6236 | cur_arg = 2; |
| 6237 | while (*(args[cur_arg])) { |
| 6238 | if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */ |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 6239 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6240 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6241 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 6242 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6243 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6244 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | if (!strcmp(args[cur_arg + 1], "client")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6248 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6249 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6250 | } else if (!strcmp(args[cur_arg + 1], "clientip")) { |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6251 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 6252 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6253 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 6254 | char *name, *end; |
| 6255 | |
| 6256 | name = args[cur_arg+1] + 7; |
| 6257 | while (isspace(*name)) |
| 6258 | name++; |
| 6259 | |
| 6260 | end = name; |
| 6261 | while (*end && !isspace(*end) && *end != ',' && *end != ')') |
| 6262 | end++; |
| 6263 | |
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_DYN; |
| 6266 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 6267 | curproxy->conn_src.bind_hdr_len = end - name; |
| 6268 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 6269 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 6270 | curproxy->conn_src.bind_hdr_occ = -1; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6271 | |
| 6272 | /* now look for an occurrence number */ |
| 6273 | while (isspace(*end)) |
| 6274 | end++; |
| 6275 | if (*end == ',') { |
| 6276 | end++; |
| 6277 | name = end; |
| 6278 | if (*end == '-') |
| 6279 | end++; |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 6280 | while (isdigit((int)*end)) |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6281 | end++; |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6282 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6283 | } |
| 6284 | |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6285 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6286 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 6287 | " occurrences values smaller than %d.\n", |
| 6288 | file, linenum, MAX_HDR_HISTORY); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 6289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6290 | goto out; |
| 6291 | } |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6292 | } else { |
Willy Tarreau | 902636f | 2013-03-10 19:44:48 +0100 | [diff] [blame] | 6293 | struct sockaddr_storage *sk; |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6294 | |
Willy Tarreau | 48ef4c9 | 2017-01-06 18:32:38 +0100 | [diff] [blame] | 6295 | 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] | 6296 | if (!sk) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6297 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 6298 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6299 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6300 | goto out; |
| 6301 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6302 | |
| 6303 | proto = protocol_by_family(sk->ss_family); |
| 6304 | if (!proto || !proto->connect) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6305 | ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", |
| 6306 | file, linenum, args[cur_arg], args[cur_arg+1]); |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6308 | goto out; |
| 6309 | } |
Willy Tarreau | 2de5dae | 2013-03-10 18:51:54 +0100 | [diff] [blame] | 6310 | |
Willy Tarreau | 6d03cc3 | 2013-02-20 17:26:02 +0100 | [diff] [blame] | 6311 | if (port1 != port2) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6312 | ha_alert("parsing [%s:%d] : '%s' : port ranges and offsets are not allowed in '%s'\n", |
| 6313 | file, linenum, args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d5191e7 | 2010-02-09 20:50:45 +0100 | [diff] [blame] | 6314 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6315 | goto out; |
| 6316 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6317 | curproxy->conn_src.tproxy_addr = *sk; |
| 6318 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6319 | } |
| 6320 | global.last_checks |= LSTCHK_NETADM; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6321 | #else /* no TPROXY support */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6322 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 6323 | file, linenum, "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6325 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6326 | #endif |
| 6327 | cur_arg += 2; |
| 6328 | continue; |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 6329 | } |
| 6330 | |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6331 | if (!strcmp(args[cur_arg], "interface")) { /* specifically bind to this interface */ |
| 6332 | #ifdef SO_BINDTODEVICE |
| 6333 | if (!*args[cur_arg + 1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6334 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 6335 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6337 | goto out; |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6338 | } |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 6339 | free(curproxy->conn_src.iface_name); |
| 6340 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 6341 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6342 | global.last_checks |= LSTCHK_NETADM; |
| 6343 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6344 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 6345 | file, linenum, args[0], args[cur_arg]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6347 | goto out; |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 6348 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 6349 | cur_arg += 2; |
| 6350 | continue; |
| 6351 | } |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6352 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 6353 | file, linenum, args[0], "interface", "usesrc"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6354 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6355 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6356 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6357 | } |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6358 | 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] | 6359 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 6360 | file, linenum, "usesrc", "source"); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6362 | goto out; |
Willy Tarreau | 8d9246d | 2007-03-24 12:47:24 +0100 | [diff] [blame] | 6363 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6364 | 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] | 6365 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6366 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6367 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6368 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6369 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6370 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6371 | |
| 6372 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6373 | SMP_OPT_DIR_REQ, ACT_REPLACE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6374 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6375 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6376 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6377 | } |
| 6378 | else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6379 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6380 | SMP_OPT_DIR_REQ, ACT_REMOVE, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6381 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6382 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6383 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6384 | } |
| 6385 | 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] | 6386 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6387 | SMP_OPT_DIR_REQ, ACT_DENY, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6388 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6389 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6390 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6391 | } |
| 6392 | else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6393 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6394 | SMP_OPT_DIR_REQ, ACT_PASS, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6395 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6396 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6397 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6398 | } |
| 6399 | else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6400 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6401 | SMP_OPT_DIR_REQ, ACT_ALLOW, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6402 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6403 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6404 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6405 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6406 | 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] | 6407 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6408 | SMP_OPT_DIR_REQ, ACT_TARPIT, 0, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6409 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6410 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6411 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6412 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6413 | 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] | 6414 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6415 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6416 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6417 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6418 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6419 | } |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6420 | |
| 6421 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6422 | SMP_OPT_DIR_REQ, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6423 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6424 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6425 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6426 | } |
| 6427 | 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] | 6428 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6429 | SMP_OPT_DIR_REQ, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6430 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6431 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6432 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6433 | } |
| 6434 | 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] | 6435 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6436 | SMP_OPT_DIR_REQ, ACT_DENY, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6437 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6438 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6439 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6440 | } |
| 6441 | 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] | 6442 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6443 | SMP_OPT_DIR_REQ, ACT_PASS, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6444 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6445 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6446 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6447 | } |
| 6448 | 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] | 6449 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6450 | SMP_OPT_DIR_REQ, ACT_ALLOW, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6451 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6452 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6453 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6454 | } |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6455 | 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] | 6456 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6457 | SMP_OPT_DIR_REQ, ACT_TARPIT, REG_ICASE, |
Willy Tarreau | 5321c42 | 2010-01-28 20:35:13 +0100 | [diff] [blame] | 6458 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6459 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6460 | goto out; |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 6461 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6462 | else if (!strcmp(args[0], "reqadd")) { /* add request header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6463 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6464 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6465 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6466 | 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] | 6467 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6468 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6469 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6470 | 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] | 6471 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6472 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6473 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6474 | 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] | 6475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6476 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6477 | } |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6478 | |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6479 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6480 | 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] | 6481 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6482 | file, linenum, args[0], errmsg); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6484 | goto out; |
| 6485 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6486 | err_code |= warnif_cond_conflicts(cond, |
| 6487 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 6488 | file, linenum); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6489 | } |
| 6490 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6491 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6492 | file, linenum, args[0], args[2]); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6493 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6494 | goto out; |
| 6495 | } |
| 6496 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6497 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | 8abd4cd | 2010-01-31 14:30:44 +0100 | [diff] [blame] | 6498 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6499 | wl->s = strdup(args[1]); |
| 6500 | LIST_ADDQ(&curproxy->req_add, &wl->list); |
Willy Tarreau | 61d1889 | 2009-03-31 10:49:21 +0200 | [diff] [blame] | 6501 | warnif_misplaced_reqadd(curproxy, file, linenum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6502 | } |
| 6503 | 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] | 6504 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6505 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6506 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6507 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6508 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6509 | } |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6510 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6511 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6512 | SMP_OPT_DIR_RES, ACT_REPLACE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6513 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6514 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6515 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6516 | } |
| 6517 | else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6518 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6519 | SMP_OPT_DIR_RES, ACT_REMOVE, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6520 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6521 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6522 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6523 | } |
| 6524 | else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */ |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6525 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6526 | SMP_OPT_DIR_RES, ACT_DENY, 0, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6527 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6528 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6529 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6530 | } |
| 6531 | 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] | 6532 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6533 | ha_alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n", |
| 6534 | file, linenum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6535 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6536 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6537 | } |
| 6538 | |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6539 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6540 | SMP_OPT_DIR_RES, ACT_REPLACE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6541 | args[0], args[1], args[2], (const char **)args+3); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6542 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6543 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6544 | } |
| 6545 | 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] | 6546 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6547 | SMP_OPT_DIR_RES, ACT_REMOVE, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6548 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6549 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6550 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6551 | } |
| 6552 | 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] | 6553 | err_code |= create_cond_regex_rule(file, linenum, curproxy, |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 6554 | SMP_OPT_DIR_RES, ACT_DENY, REG_ICASE, |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6555 | args[0], args[1], NULL, (const char **)args+2); |
Willy Tarreau | ade5ec4 | 2010-01-28 19:33:49 +0100 | [diff] [blame] | 6556 | if (err_code & ERR_FATAL) |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6557 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6558 | } |
| 6559 | else if (!strcmp(args[0], "rspadd")) { /* add response header */ |
Willy Tarreau | f4f0412 | 2010-01-28 18:10:50 +0100 | [diff] [blame] | 6560 | struct cond_wordlist *wl; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6561 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6562 | if (curproxy == &defproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6563 | 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] | 6564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6565 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6566 | } |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 6567 | 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] | 6568 | err_code |= ERR_WARN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6569 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6570 | if (*(args[1]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6571 | 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] | 6572 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6573 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6574 | } |
| 6575 | |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6576 | if ((strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0)) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 6577 | 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] | 6578 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' condition : %s.\n", |
| 6579 | file, linenum, args[0], errmsg); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6581 | goto out; |
| 6582 | } |
Willy Tarreau | a91d0a5 | 2013-03-25 08:12:18 +0100 | [diff] [blame] | 6583 | err_code |= warnif_cond_conflicts(cond, |
| 6584 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 6585 | file, linenum); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6586 | } |
| 6587 | else if (*args[2]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6588 | ha_alert("parsing [%s:%d] : '%s' : Expecting nothing, 'if', or 'unless', got '%s'.\n", |
| 6589 | file, linenum, args[0], args[2]); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6590 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6591 | goto out; |
| 6592 | } |
| 6593 | |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6594 | wl = calloc(1, sizeof(*wl)); |
Willy Tarreau | fdb563c | 2010-01-31 15:43:27 +0100 | [diff] [blame] | 6595 | wl->cond = cond; |
Willy Tarreau | deb9ed8 | 2010-01-03 21:03:22 +0100 | [diff] [blame] | 6596 | wl->s = strdup(args[1]); |
| 6597 | LIST_ADDQ(&curproxy->rsp_add, &wl->list); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6598 | } |
| 6599 | else if (!strcmp(args[0], "errorloc") || |
| 6600 | !strcmp(args[0], "errorloc302") || |
| 6601 | !strcmp(args[0], "errorloc303")) { /* error location */ |
| 6602 | int errnum, errlen; |
| 6603 | char *err; |
| 6604 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6605 | 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] | 6606 | err_code |= ERR_WARN; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 6607 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6608 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6609 | 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] | 6610 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6611 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | errnum = atol(args[1]); |
| 6615 | if (!strcmp(args[0], "errorloc303")) { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6616 | errlen = strlen(HTTP_303) + strlen(args[2]) + 5; |
| 6617 | err = malloc(errlen); |
| 6618 | 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] | 6619 | } else { |
Willy Tarreau | 348acfe | 2014-04-14 15:00:39 +0200 | [diff] [blame] | 6620 | errlen = strlen(HTTP_302) + strlen(args[2]) + 5; |
| 6621 | err = malloc(errlen); |
| 6622 | 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] | 6623 | } |
| 6624 | |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6625 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6626 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6627 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6628 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6629 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6630 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6631 | } |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 6632 | |
| 6633 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6634 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error relocation will be ignored.\n", |
| 6635 | file, linenum, errnum, args[0]); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6636 | free(err); |
| 6637 | } |
| 6638 | } |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6639 | else if (!strcmp(args[0], "errorfile")) { /* error message from a file */ |
| 6640 | int errnum, errlen, fd; |
| 6641 | char *err; |
| 6642 | struct stat stat; |
| 6643 | |
| 6644 | 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] | 6645 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6646 | |
| 6647 | if (*(args[2]) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6648 | 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] | 6649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6650 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | fd = open(args[2], O_RDONLY); |
| 6654 | if ((fd < 0) || (fstat(fd, &stat) < 0)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6655 | ha_alert("parsing [%s:%d] : error opening file <%s> for custom error message <%s>.\n", |
| 6656 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6657 | if (fd >= 0) |
| 6658 | close(fd); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6660 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6661 | } |
| 6662 | |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6663 | if (stat.st_size <= global.tune.bufsize) { |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6664 | errlen = stat.st_size; |
| 6665 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6666 | ha_warning("parsing [%s:%d] : custom error message file <%s> larger than %d bytes. Truncating.\n", |
| 6667 | file, linenum, args[2], global.tune.bufsize); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6668 | err_code |= ERR_WARN; |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 6669 | errlen = global.tune.bufsize; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | err = malloc(errlen); /* malloc() must succeed during parsing */ |
| 6673 | errnum = read(fd, err, errlen); |
| 6674 | if (errnum != errlen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6675 | ha_alert("parsing [%s:%d] : error reading file <%s> for custom error message <%s>.\n", |
| 6676 | file, linenum, args[2], args[1]); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6677 | close(fd); |
| 6678 | free(err); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6679 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6680 | goto out; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6681 | } |
| 6682 | close(fd); |
| 6683 | |
| 6684 | errnum = atol(args[1]); |
| 6685 | for (rc = 0; rc < HTTP_ERR_SIZE; rc++) { |
| 6686 | if (http_err_codes[rc] == errnum) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6687 | chunk_destroy(&curproxy->errmsg[rc]); |
| 6688 | chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen); |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6689 | break; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | if (rc >= HTTP_ERR_SIZE) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6694 | ha_warning("parsing [%s:%d] : status code %d not handled by '%s', error customization will be ignored.\n", |
| 6695 | file, linenum, errnum, args[0]); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6696 | err_code |= ERR_WARN; |
Willy Tarreau | 3f49b30 | 2007-06-11 00:29:26 +0200 | [diff] [blame] | 6697 | free(err); |
| 6698 | } |
| 6699 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6700 | else { |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6701 | struct cfg_kw_list *kwl; |
| 6702 | int index; |
| 6703 | |
| 6704 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 6705 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 6706 | if (kwl->kw[index].section != CFG_LISTEN) |
| 6707 | continue; |
| 6708 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 6709 | /* prepare error message just in case */ |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 6710 | 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] | 6711 | if (rc < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6712 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6713 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6714 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6715 | } |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6716 | else if (rc > 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6717 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6718 | err_code |= ERR_WARN; |
| 6719 | goto out; |
Willy Tarreau | 39f23b6 | 2008-07-09 20:22:56 +0200 | [diff] [blame] | 6720 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6721 | goto out; |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 6722 | } |
| 6723 | } |
| 6724 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 6725 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6726 | 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] | 6727 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6728 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6729 | } |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6730 | out: |
Willy Tarreau | f4068b6 | 2012-05-08 17:37:49 +0200 | [diff] [blame] | 6731 | free(errmsg); |
Willy Tarreau | 9389379 | 2009-07-23 13:19:11 +0200 | [diff] [blame] | 6732 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6733 | } |
| 6734 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6735 | int |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6736 | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
| 6737 | { |
| 6738 | #ifdef CONFIG_HAP_NS |
| 6739 | const char *err; |
| 6740 | const char *item = args[0]; |
| 6741 | |
| 6742 | if (!strcmp(item, "namespace_list")) { |
| 6743 | return 0; |
| 6744 | } |
| 6745 | else if (!strcmp(item, "namespace")) { |
| 6746 | size_t idx = 1; |
| 6747 | const char *current; |
| 6748 | while (*(current = args[idx++])) { |
| 6749 | err = invalid_char(current); |
| 6750 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6751 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6752 | file, linenum, *err, item, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6753 | return ERR_ALERT | ERR_FATAL; |
| 6754 | } |
| 6755 | |
| 6756 | if (netns_store_lookup(current, strlen(current))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6757 | ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
| 6758 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6759 | return ERR_ALERT | ERR_FATAL; |
| 6760 | } |
| 6761 | if (!netns_store_insert(current)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6762 | ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
| 6763 | file, linenum, current); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6764 | return ERR_ALERT | ERR_FATAL; |
| 6765 | } |
| 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | return 0; |
| 6770 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6771 | ha_alert("parsing [%s:%d]: namespace support is not compiled in.", |
| 6772 | file, linenum); |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 6773 | return ERR_ALERT | ERR_FATAL; |
| 6774 | #endif |
| 6775 | } |
| 6776 | |
| 6777 | int |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6778 | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
| 6779 | { |
| 6780 | |
| 6781 | int err_code = 0; |
| 6782 | const char *err; |
| 6783 | |
| 6784 | if (!strcmp(args[0], "userlist")) { /* new userlist */ |
| 6785 | struct userlist *newul; |
| 6786 | |
| 6787 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6788 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6789 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6790 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6791 | goto out; |
| 6792 | } |
William Lallemand | 6e62fb6 | 2015-04-28 16:55:23 +0200 | [diff] [blame] | 6793 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 6794 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6795 | |
| 6796 | err = invalid_char(args[1]); |
| 6797 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6798 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6799 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6800 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6801 | goto out; |
| 6802 | } |
| 6803 | |
| 6804 | for (newul = userlist; newul; newul = newul->next) |
| 6805 | if (!strcmp(newul->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6806 | ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
| 6807 | file, linenum, args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6808 | err_code |= ERR_WARN; |
| 6809 | goto out; |
| 6810 | } |
| 6811 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6812 | newul = calloc(1, sizeof(*newul)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6813 | if (!newul) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6814 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6815 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6816 | goto out; |
| 6817 | } |
| 6818 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6819 | newul->name = strdup(args[1]); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6820 | if (!newul->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6821 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6822 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 6823 | free(newul); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6824 | goto out; |
| 6825 | } |
| 6826 | |
| 6827 | newul->next = userlist; |
| 6828 | userlist = newul; |
| 6829 | |
| 6830 | } else if (!strcmp(args[0], "group")) { /* new group */ |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6831 | int cur_arg; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6832 | const char *err; |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6833 | struct auth_groups *ag; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6834 | |
| 6835 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6836 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6837 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6838 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6839 | goto out; |
| 6840 | } |
| 6841 | |
| 6842 | err = invalid_char(args[1]); |
| 6843 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6844 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
| 6845 | file, linenum, *err, args[0], args[1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6847 | goto out; |
| 6848 | } |
| 6849 | |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6850 | if (!userlist) |
| 6851 | goto out; |
| 6852 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6853 | for (ag = userlist->groups; ag; ag = ag->next) |
| 6854 | if (!strcmp(ag->name, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6855 | ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
| 6856 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6857 | err_code |= ERR_ALERT; |
| 6858 | goto out; |
| 6859 | } |
| 6860 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6861 | ag = calloc(1, sizeof(*ag)); |
| 6862 | if (!ag) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6863 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6864 | err_code |= ERR_ALERT | ERR_ABORT; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6865 | goto out; |
| 6866 | } |
| 6867 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6868 | ag->name = strdup(args[1]); |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6869 | if (!ag->name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6870 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6871 | err_code |= ERR_ALERT | ERR_ABORT; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6872 | free(ag); |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6873 | goto out; |
| 6874 | } |
| 6875 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6876 | cur_arg = 2; |
| 6877 | |
| 6878 | while (*args[cur_arg]) { |
| 6879 | if (!strcmp(args[cur_arg], "users")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6880 | ag->groupusers = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6881 | cur_arg += 2; |
| 6882 | continue; |
| 6883 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6884 | ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
| 6885 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6886 | err_code |= ERR_ALERT | ERR_FATAL; |
David Carlier | 70d6045 | 2016-08-22 23:27:42 +0100 | [diff] [blame] | 6887 | free(ag->groupusers); |
| 6888 | free(ag->name); |
| 6889 | free(ag); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6890 | goto out; |
| 6891 | } |
| 6892 | } |
| 6893 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6894 | ag->next = userlist->groups; |
| 6895 | userlist->groups = ag; |
| 6896 | |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6897 | } else if (!strcmp(args[0], "user")) { /* new user */ |
| 6898 | struct auth_users *newuser; |
| 6899 | int cur_arg; |
| 6900 | |
| 6901 | if (!*args[1]) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6902 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
| 6903 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6905 | goto out; |
| 6906 | } |
William Lallemand | 4ac9f54 | 2015-05-28 18:03:51 +0200 | [diff] [blame] | 6907 | if (!userlist) |
| 6908 | goto out; |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6909 | |
| 6910 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
| 6911 | if (!strcmp(newuser->user, args[1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6912 | ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
| 6913 | file, linenum, args[1], userlist->name); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6914 | err_code |= ERR_ALERT; |
| 6915 | goto out; |
| 6916 | } |
| 6917 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 6918 | newuser = calloc(1, sizeof(*newuser)); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6919 | if (!newuser) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6920 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6921 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6922 | goto out; |
| 6923 | } |
| 6924 | |
| 6925 | newuser->user = strdup(args[1]); |
| 6926 | |
| 6927 | newuser->next = userlist->users; |
| 6928 | userlist->users = newuser; |
| 6929 | |
| 6930 | cur_arg = 2; |
| 6931 | |
| 6932 | while (*args[cur_arg]) { |
| 6933 | if (!strcmp(args[cur_arg], "password")) { |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6934 | #ifdef CONFIG_HAP_CRYPT |
| 6935 | if (!crypt("", args[cur_arg + 1])) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6936 | ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
| 6937 | file, linenum, newuser->user); |
Cyril Bonté | 1a0191d | 2014-08-29 20:20:02 +0200 | [diff] [blame] | 6938 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6939 | goto out; |
| 6940 | } |
| 6941 | #else |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6942 | ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
| 6943 | file, linenum); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6944 | err_code |= ERR_ALERT; |
| 6945 | #endif |
| 6946 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6947 | cur_arg += 2; |
| 6948 | continue; |
| 6949 | } else if (!strcmp(args[cur_arg], "insecure-password")) { |
| 6950 | newuser->pass = strdup(args[cur_arg + 1]); |
| 6951 | newuser->flags |= AU_O_INSECURE; |
| 6952 | cur_arg += 2; |
| 6953 | continue; |
| 6954 | } else if (!strcmp(args[cur_arg], "groups")) { |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 6955 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6956 | cur_arg += 2; |
| 6957 | continue; |
| 6958 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6959 | ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
| 6960 | file, linenum, args[0]); |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 6961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6962 | goto out; |
| 6963 | } |
| 6964 | } |
| 6965 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6966 | 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] | 6967 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6968 | } |
| 6969 | |
| 6970 | out: |
| 6971 | return err_code; |
| 6972 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6973 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6974 | int |
| 6975 | cfg_parse_scope(const char *file, int linenum, char *line) |
| 6976 | { |
| 6977 | char *beg, *end, *scope = NULL; |
| 6978 | int err_code = 0; |
| 6979 | const char *err; |
| 6980 | |
| 6981 | beg = line + 1; |
| 6982 | end = strchr(beg, ']'); |
| 6983 | |
| 6984 | /* Detect end of scope declaration */ |
| 6985 | if (!end || end == beg) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6986 | ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
| 6987 | file, linenum); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 6989 | goto out; |
| 6990 | } |
| 6991 | |
| 6992 | /* Get scope name and check its validity */ |
| 6993 | scope = my_strndup(beg, end-beg); |
| 6994 | err = invalid_char(scope); |
| 6995 | if (err) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 6996 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
| 6997 | file, linenum, *err); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 6998 | err_code |= ERR_ALERT | ERR_ABORT; |
| 6999 | goto out; |
| 7000 | } |
| 7001 | |
| 7002 | /* Be sure to have a scope declaration alone on its line */ |
| 7003 | line = end+1; |
| 7004 | while (isspace((unsigned char)*line)) |
| 7005 | line++; |
| 7006 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7007 | ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
| 7008 | file, linenum, *line); |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7009 | err_code |= ERR_ALERT | ERR_ABORT; |
| 7010 | goto out; |
| 7011 | } |
| 7012 | |
| 7013 | /* We have a valid scope declaration, save it */ |
| 7014 | free(cfg_scope); |
| 7015 | cfg_scope = scope; |
| 7016 | scope = NULL; |
| 7017 | |
| 7018 | out: |
| 7019 | free(scope); |
| 7020 | return err_code; |
| 7021 | } |
| 7022 | |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 7023 | int |
| 7024 | cfg_parse_track_sc_num(unsigned int *track_sc_num, |
| 7025 | const char *arg, const char *end, char **errmsg) |
| 7026 | { |
| 7027 | const char *p; |
| 7028 | unsigned int num; |
| 7029 | |
| 7030 | p = arg; |
| 7031 | num = read_uint64(&arg, end); |
| 7032 | |
| 7033 | if (arg != end) { |
| 7034 | memprintf(errmsg, "Wrong track-sc number '%s'", p); |
| 7035 | return -1; |
| 7036 | } |
| 7037 | |
| 7038 | if (num >= MAX_SESS_STKCTR) { |
| 7039 | memprintf(errmsg, "%u track-sc number exceeding " |
| 7040 | "%d (MAX_SESS_STKCTR-1) value", num, MAX_SESS_STKCTR - 1); |
| 7041 | return -1; |
| 7042 | } |
| 7043 | |
| 7044 | *track_sc_num = num; |
| 7045 | return 0; |
| 7046 | } |
| 7047 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7048 | /* |
| 7049 | * This function reads and parses the configuration file given in the argument. |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7050 | * Returns the error code, 0 if OK, or any combination of : |
| 7051 | * - ERR_ABORT: must abort ASAP |
| 7052 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7053 | * - ERR_WARN: a warning has been emitted |
| 7054 | * - ERR_ALERT: an alert has been emitted |
| 7055 | * Only the two first ones can stop processing, the two others are just |
| 7056 | * indicators. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7057 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 7058 | int readcfgfile(const char *file) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7059 | { |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7060 | char *thisline; |
| 7061 | int linesize = LINESIZE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7062 | FILE *f; |
| 7063 | int linenum = 0; |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7064 | int err_code = 0; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7065 | struct cfg_section *cs = NULL, *pcs = NULL; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7066 | struct cfg_section *ics; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7067 | int readbytes = 0; |
| 7068 | |
| 7069 | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7070 | ha_alert("parsing [%s] : out of memory.\n", file); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7071 | return -1; |
| 7072 | } |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7073 | |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7074 | if ((f=fopen(file,"r")) == NULL) { |
| 7075 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7076 | return -1; |
David Carlier | 97880bb | 2016-04-08 10:35:26 +0100 | [diff] [blame] | 7077 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7078 | |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7079 | next_line: |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7080 | while (fgets(thisline + readbytes, linesize - readbytes, f) != NULL) { |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7081 | int arg, kwm = KWM_STD; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7082 | char *end; |
| 7083 | char *args[MAX_LINE_ARGS + 1]; |
| 7084 | char *line = thisline; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7085 | int dquote = 0; /* double quote */ |
| 7086 | int squote = 0; /* simple quote */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7087 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7088 | linenum++; |
| 7089 | |
| 7090 | end = line + strlen(line); |
| 7091 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7092 | if (end-line == linesize-1 && *(end-1) != '\n') { |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7093 | /* Check if we reached the limit and the last char is not \n. |
| 7094 | * Watch out for the last line without the terminating '\n'! |
| 7095 | */ |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7096 | char *newline; |
| 7097 | int newlinesize = linesize * 2; |
| 7098 | |
| 7099 | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
| 7100 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7101 | ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
| 7102 | file, linenum); |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7103 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7104 | continue; |
| 7105 | } |
| 7106 | |
| 7107 | readbytes = linesize - 1; |
| 7108 | linesize = newlinesize; |
| 7109 | thisline = newline; |
| 7110 | continue; |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7111 | } |
| 7112 | |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7113 | readbytes = 0; |
| 7114 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7115 | /* skip leading spaces */ |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7116 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7117 | line++; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7118 | |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7119 | |
| 7120 | if (*line == '[') {/* This is the begining if a scope */ |
| 7121 | err_code |= cfg_parse_scope(file, linenum, line); |
| 7122 | goto next_line; |
| 7123 | } |
| 7124 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7125 | arg = 0; |
| 7126 | args[arg] = line; |
| 7127 | |
| 7128 | while (*line && arg < MAX_LINE_ARGS) { |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7129 | if (*line == '"' && !squote) { /* double quote outside single quotes */ |
| 7130 | if (dquote) |
| 7131 | dquote = 0; |
| 7132 | else |
| 7133 | dquote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7134 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7135 | end--; |
| 7136 | } |
| 7137 | else if (*line == '\'' && !dquote) { /* single quote outside double quotes */ |
| 7138 | if (squote) |
| 7139 | squote = 0; |
| 7140 | else |
| 7141 | squote = 1; |
William Lallemand | 3f41560 | 2015-05-12 14:01:09 +0200 | [diff] [blame] | 7142 | memmove(line, line + 1, end - line); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7143 | end--; |
| 7144 | } |
| 7145 | else if (*line == '\\' && !squote) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7146 | /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their |
| 7147 | * C equivalent value. Other combinations left unchanged (eg: \1). |
| 7148 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7149 | int skip = 0; |
| 7150 | if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') { |
| 7151 | *line = line[1]; |
| 7152 | skip = 1; |
| 7153 | } |
| 7154 | else if (line[1] == 'r') { |
| 7155 | *line = '\r'; |
| 7156 | skip = 1; |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7157 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7158 | else if (line[1] == 'n') { |
| 7159 | *line = '\n'; |
| 7160 | skip = 1; |
| 7161 | } |
| 7162 | else if (line[1] == 't') { |
| 7163 | *line = '\t'; |
| 7164 | skip = 1; |
| 7165 | } |
| 7166 | else if (line[1] == 'x') { |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7167 | if ((line + 3 < end) && ishex(line[2]) && ishex(line[3])) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7168 | unsigned char hex1, hex2; |
| 7169 | hex1 = toupper(line[2]) - '0'; |
| 7170 | hex2 = toupper(line[3]) - '0'; |
| 7171 | if (hex1 > 9) hex1 -= 'A' - '9' - 1; |
| 7172 | if (hex2 > 9) hex2 -= 'A' - '9' - 1; |
| 7173 | *line = (hex1<<4) + hex2; |
| 7174 | skip = 3; |
| 7175 | } |
| 7176 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7177 | 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] | 7178 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7179 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7180 | } else if (line[1] == '"') { |
| 7181 | *line = '"'; |
| 7182 | skip = 1; |
| 7183 | } else if (line[1] == '\'') { |
| 7184 | *line = '\''; |
| 7185 | skip = 1; |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7186 | } else if (line[1] == '$' && dquote) { /* escaping of $ only inside double quotes */ |
| 7187 | *line = '$'; |
| 7188 | skip = 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7189 | } |
| 7190 | if (skip) { |
Cyril Bonté | dd1b01d | 2009-12-06 13:43:42 +0100 | [diff] [blame] | 7191 | memmove(line + 1, line + 1 + skip, end - (line + skip)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7192 | end -= skip; |
| 7193 | } |
| 7194 | line++; |
| 7195 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7196 | else if ((!squote && !dquote && *line == '#') || *line == '\n' || *line == '\r') { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7197 | /* end of string, end of loop */ |
| 7198 | *line = 0; |
| 7199 | break; |
| 7200 | } |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7201 | else if (!squote && !dquote && isspace((unsigned char)*line)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7202 | /* a non-escaped space is an argument separator */ |
Krzysztof Piotr Oledzki | e6bbd74 | 2007-11-01 00:33:12 +0100 | [diff] [blame] | 7203 | *line++ = '\0'; |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 7204 | while (isspace((unsigned char)*line)) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7205 | line++; |
| 7206 | args[++arg] = line; |
| 7207 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7208 | else if (dquote && *line == '$') { |
| 7209 | /* environment variables are evaluated inside double quotes */ |
| 7210 | char *var_beg; |
| 7211 | char *var_end; |
| 7212 | char save_char; |
| 7213 | char *value; |
| 7214 | int val_len; |
| 7215 | int newlinesize; |
| 7216 | int braces = 0; |
| 7217 | |
| 7218 | var_beg = line + 1; |
| 7219 | var_end = var_beg; |
| 7220 | |
| 7221 | if (*var_beg == '{') { |
| 7222 | var_beg++; |
| 7223 | var_end++; |
| 7224 | braces = 1; |
| 7225 | } |
| 7226 | |
| 7227 | if (!isalpha((int)(unsigned char)*var_beg) && *var_beg != '_') { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7228 | 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] | 7229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7230 | goto next_line; /* skip current line */ |
| 7231 | } |
| 7232 | |
| 7233 | while (isalnum((int)(unsigned char)*var_end) || *var_end == '_') |
| 7234 | var_end++; |
| 7235 | |
| 7236 | save_char = *var_end; |
| 7237 | *var_end = '\0'; |
| 7238 | value = getenv(var_beg); |
| 7239 | *var_end = save_char; |
| 7240 | val_len = value ? strlen(value) : 0; |
| 7241 | |
| 7242 | if (braces) { |
| 7243 | if (*var_end == '}') { |
| 7244 | var_end++; |
| 7245 | braces = 0; |
| 7246 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7247 | ha_alert("parsing [%s:%d] : Variable expansion: Mismatched braces.\n", file, linenum); |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7248 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7249 | goto next_line; /* skip current line */ |
| 7250 | } |
| 7251 | } |
| 7252 | |
| 7253 | newlinesize = (end - thisline) - (var_end - line) + val_len + 1; |
| 7254 | |
| 7255 | /* if not enough space in thisline */ |
| 7256 | if (newlinesize > linesize) { |
| 7257 | char *newline; |
| 7258 | |
| 7259 | newline = realloc(thisline, newlinesize * sizeof(*thisline)); |
| 7260 | if (newline == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7261 | 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] | 7262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7263 | goto next_line; /* slip current line */ |
| 7264 | } |
| 7265 | /* recompute pointers if realloc returns a new pointer */ |
| 7266 | if (newline != thisline) { |
| 7267 | int i; |
| 7268 | int diff; |
| 7269 | |
| 7270 | for (i = 0; i <= arg; i++) { |
| 7271 | diff = args[i] - thisline; |
| 7272 | args[i] = newline + diff; |
| 7273 | } |
| 7274 | |
| 7275 | diff = var_end - thisline; |
| 7276 | var_end = newline + diff; |
| 7277 | diff = end - thisline; |
| 7278 | end = newline + diff; |
| 7279 | diff = line - thisline; |
| 7280 | line = newline + diff; |
| 7281 | thisline = newline; |
| 7282 | } |
| 7283 | linesize = newlinesize; |
| 7284 | } |
| 7285 | |
| 7286 | /* insert value inside the line */ |
| 7287 | memmove(line + val_len, var_end, end - var_end + 1); |
| 7288 | memcpy(line, value, val_len); |
| 7289 | end += val_len - (var_end - line); |
| 7290 | line += val_len; |
| 7291 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7292 | else { |
| 7293 | line++; |
| 7294 | } |
| 7295 | } |
William Lallemand | b2f0745 | 2015-05-12 14:27:13 +0200 | [diff] [blame] | 7296 | |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7297 | if (dquote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7298 | ha_alert("parsing [%s:%d] : Mismatched double quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7300 | } |
| 7301 | |
| 7302 | if (squote) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7303 | ha_alert("parsing [%s:%d] : Mismatched simple quotes.\n", file, linenum); |
William Lallemand | f9873ba | 2015-05-05 17:37:14 +0200 | [diff] [blame] | 7304 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7305 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7306 | |
| 7307 | /* empty line */ |
| 7308 | if (!**args) |
| 7309 | continue; |
| 7310 | |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7311 | if (*line) { |
| 7312 | /* we had to stop due to too many args. |
| 7313 | * Let's terminate the string, print the offending part then cut the |
| 7314 | * last arg. |
| 7315 | */ |
| 7316 | while (*line && *line != '#' && *line != '\n' && *line != '\r') |
| 7317 | line++; |
| 7318 | *line = '\0'; |
| 7319 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7320 | ha_alert("parsing [%s:%d]: line too long, truncating at word %d, position %ld: <%s>.\n", |
| 7321 | file, linenum, arg + 1, (long)(args[arg] - thisline + 1), args[arg]); |
Willy Tarreau | 7bb651e | 2009-11-09 21:16:53 +0100 | [diff] [blame] | 7322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 7323 | args[arg] = line; |
| 7324 | } |
| 7325 | |
Willy Tarreau | 540abe4 | 2007-05-02 20:50:16 +0200 | [diff] [blame] | 7326 | /* zero out remaining args and ensure that at least one entry |
| 7327 | * is zeroed out. |
| 7328 | */ |
| 7329 | while (++arg <= MAX_LINE_ARGS) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7330 | args[arg] = line; |
| 7331 | } |
| 7332 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7333 | /* check for keyword modifiers "no" and "default" */ |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7334 | if (!strcmp(args[0], "no")) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7335 | char *tmp; |
| 7336 | |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7337 | kwm = KWM_NO; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7338 | tmp = args[0]; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7339 | for (arg=0; *args[arg+1]; arg++) |
| 7340 | args[arg] = args[arg+1]; // shift args after inversion |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7341 | *tmp = '\0'; // fix the next arg to \0 |
| 7342 | args[arg] = tmp; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7343 | } |
Willy Tarreau | 3842f00 | 2009-06-14 11:39:52 +0200 | [diff] [blame] | 7344 | else if (!strcmp(args[0], "default")) { |
| 7345 | kwm = KWM_DEF; |
| 7346 | for (arg=0; *args[arg+1]; arg++) |
| 7347 | args[arg] = args[arg+1]; // shift args after inversion |
| 7348 | } |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7349 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 7350 | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && \ |
| 7351 | strcmp(args[0], "log") != 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7352 | 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] | 7353 | err_code |= ERR_ALERT | ERR_FATAL; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 7354 | } |
| 7355 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 7356 | /* detect section start */ |
| 7357 | list_for_each_entry(ics, §ions, list) { |
| 7358 | if (strcmp(args[0], ics->section_name) == 0) { |
| 7359 | cursection = ics->section_name; |
| 7360 | cs = ics; |
| 7361 | break; |
| 7362 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 7363 | } |
| 7364 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7365 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7366 | 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] | 7367 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7368 | } else { |
| 7369 | /* else it's a section keyword */ |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7370 | |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7371 | if (pcs != cs && pcs && pcs->post_section_parser) { |
| 7372 | err_code |= pcs->post_section_parser(); |
| 7373 | if (err_code & ERR_ABORT) |
| 7374 | goto err; |
| 7375 | } |
| 7376 | |
| 7377 | err_code |= cs->section_parser(file, linenum, args, kwm); |
| 7378 | if (err_code & ERR_ABORT) |
| 7379 | goto err; |
| 7380 | } |
| 7381 | pcs = cs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7382 | } |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 7383 | |
| 7384 | if (pcs == cs && pcs && pcs->post_section_parser) |
| 7385 | err_code |= pcs->post_section_parser(); |
| 7386 | |
| 7387 | err: |
Christopher Faulet | 79bdef3 | 2016-11-04 22:36:15 +0100 | [diff] [blame] | 7388 | free(cfg_scope); |
| 7389 | cfg_scope = NULL; |
Willy Tarreau | 6daf343 | 2008-01-22 16:44:08 +0100 | [diff] [blame] | 7390 | cursection = NULL; |
William Lallemand | 64e8451 | 2015-05-12 14:25:37 +0200 | [diff] [blame] | 7391 | free(thisline); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7392 | fclose(f); |
Willy Tarreau | 058e907 | 2009-07-20 09:30:05 +0200 | [diff] [blame] | 7393 | return err_code; |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7394 | } |
| 7395 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7396 | /* This function propagates processes from frontend <from> to backend <to> so |
| 7397 | * that it is always guaranteed that a backend pointed to by a frontend is |
| 7398 | * bound to all of its processes. After that, if the target is a "listen" |
| 7399 | * instance, the function recursively descends the target's own targets along |
Willy Tarreau | 98d0485 | 2015-05-26 12:18:29 +0200 | [diff] [blame] | 7400 | * default_backend and use_backend rules. Since the bits are |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7401 | * checked first to ensure that <to> is already bound to all processes of |
| 7402 | * <from>, there is no risk of looping and we ensure to follow the shortest |
| 7403 | * path to the destination. |
| 7404 | * |
| 7405 | * It is possible to set <to> to NULL for the first call so that the function |
| 7406 | * takes care of visiting the initial frontend in <from>. |
| 7407 | * |
| 7408 | * It is important to note that the function relies on the fact that all names |
| 7409 | * have already been resolved. |
| 7410 | */ |
| 7411 | void propagate_processes(struct proxy *from, struct proxy *to) |
| 7412 | { |
| 7413 | struct switching_rule *rule; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7414 | |
| 7415 | if (to) { |
| 7416 | /* check whether we need to go down */ |
| 7417 | if (from->bind_proc && |
| 7418 | (from->bind_proc & to->bind_proc) == from->bind_proc) |
| 7419 | return; |
| 7420 | |
| 7421 | if (!from->bind_proc && !to->bind_proc) |
| 7422 | return; |
| 7423 | |
| 7424 | to->bind_proc = from->bind_proc ? |
| 7425 | (to->bind_proc | from->bind_proc) : 0; |
| 7426 | |
| 7427 | /* now propagate down */ |
| 7428 | from = to; |
| 7429 | } |
| 7430 | |
Willy Tarreau | 8a95d8c | 2014-12-18 13:56:26 +0100 | [diff] [blame] | 7431 | if (!(from->cap & PR_CAP_FE)) |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7432 | return; |
| 7433 | |
Willy Tarreau | f6b7001 | 2014-12-18 14:00:43 +0100 | [diff] [blame] | 7434 | if (from->state == PR_STSTOPPED) |
| 7435 | return; |
| 7436 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7437 | /* default_backend */ |
| 7438 | if (from->defbe.be) |
| 7439 | propagate_processes(from, from->defbe.be); |
| 7440 | |
| 7441 | /* use_backend */ |
| 7442 | list_for_each_entry(rule, &from->switching_rules, list) { |
Cyril Bonté | 5163969 | 2014-10-02 19:56:25 +0200 | [diff] [blame] | 7443 | if (rule->dynamic) |
| 7444 | continue; |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7445 | to = rule->be.backend; |
| 7446 | propagate_processes(from, to); |
| 7447 | } |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7448 | } |
| 7449 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7450 | /* |
| 7451 | * Returns the error code, 0 if OK, or any combination of : |
| 7452 | * - ERR_ABORT: must abort ASAP |
| 7453 | * - ERR_FATAL: we can continue parsing but not start the service |
| 7454 | * - ERR_WARN: a warning has been emitted |
| 7455 | * - ERR_ALERT: an alert has been emitted |
| 7456 | * Only the two first ones can stop processing, the two others are just |
| 7457 | * indicators. |
| 7458 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7459 | int check_config_validity() |
| 7460 | { |
| 7461 | int cfgerr = 0; |
| 7462 | struct proxy *curproxy = NULL; |
| 7463 | struct server *newsrv = NULL; |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7464 | int err_code = 0; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7465 | unsigned int next_pxid = 1; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7466 | struct bind_conf *bind_conf; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7467 | char *err; |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 7468 | struct cfg_postparser *postparser; |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 7469 | struct dns_resolvers *curr_resolvers = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7470 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 7471 | bind_conf = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7472 | /* |
| 7473 | * Now, check for the integrity of all that we have collected. |
| 7474 | */ |
| 7475 | |
| 7476 | /* will be needed further to delay some tasks */ |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 7477 | tv_update_date(0,1); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7478 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 7479 | if (!global.tune.max_http_hdr) |
| 7480 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
| 7481 | |
| 7482 | if (!global.tune.cookie_len) |
| 7483 | global.tune.cookie_len = CAPTURE_LEN; |
| 7484 | |
Stéphane Cottin | 23e9e93 | 2017-05-18 08:58:41 +0200 | [diff] [blame] | 7485 | if (!global.tune.requri_len) |
| 7486 | global.tune.requri_len = REQURI_LEN; |
| 7487 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7488 | 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] | 7489 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 7490 | 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] | 7491 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 7492 | /* Post initialisation of the users and groups lists. */ |
| 7493 | err_code = userlist_postinit(); |
| 7494 | if (err_code != ERR_NONE) |
| 7495 | goto out; |
| 7496 | |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7497 | /* first, we will invert the proxy list order */ |
| 7498 | curproxy = NULL; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7499 | while (proxies_list) { |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7500 | struct proxy *next; |
| 7501 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7502 | next = proxies_list->next; |
| 7503 | proxies_list->next = curproxy; |
| 7504 | curproxy = proxies_list; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7505 | if (!next) |
| 7506 | break; |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7507 | proxies_list = next; |
Willy Tarreau | 55bc0f8 | 2009-03-15 14:51:53 +0100 | [diff] [blame] | 7508 | } |
| 7509 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 7510 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7511 | struct switching_rule *rule; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7512 | struct server_rule *srule; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7513 | struct sticking_rule *mrule; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7514 | struct act_rule *arule; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 7515 | struct logsrv *tmplogsrv; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7516 | unsigned int next_id; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 7517 | int nbproc; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7518 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 7519 | if (curproxy->uuid < 0) { |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7520 | /* proxy ID not set, use automatic numbering with first |
| 7521 | * spare entry starting with next_pxid. |
| 7522 | */ |
| 7523 | next_pxid = get_next_id(&used_proxy_id, next_pxid); |
| 7524 | curproxy->conf.id.key = curproxy->uuid = next_pxid; |
| 7525 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 7526 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 7527 | next_pxid++; |
| 7528 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7529 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7530 | if (curproxy->state == PR_STSTOPPED) { |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 7531 | /* ensure we don't keep listeners uselessly bound */ |
| 7532 | stop_proxy(curproxy); |
Willy Tarreau | 02df774 | 2015-05-01 19:59:56 +0200 | [diff] [blame] | 7533 | free((void *)curproxy->table.peers.name); |
| 7534 | curproxy->table.peers.p = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7535 | continue; |
| 7536 | } |
| 7537 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7538 | /* Check multi-process mode compatibility for the current proxy */ |
| 7539 | |
| 7540 | if (curproxy->bind_proc) { |
| 7541 | /* an explicit bind-process was specified, let's check how many |
| 7542 | * processes remain. |
| 7543 | */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7544 | nbproc = my_popcountl(curproxy->bind_proc); |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 7545 | |
| 7546 | curproxy->bind_proc &= nbits(global.nbproc); |
| 7547 | if (!curproxy->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7548 | 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] | 7549 | curproxy->bind_proc = 1; |
| 7550 | } |
| 7551 | else if (!curproxy->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7552 | 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] | 7553 | curproxy->bind_proc = 0; |
| 7554 | } |
| 7555 | } |
| 7556 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7557 | /* check and reduce the bind-proc of each listener */ |
| 7558 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 7559 | unsigned long mask; |
| 7560 | |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7561 | /* HTTP frontends with "h2" as ALPN/NPN will work in |
| 7562 | * HTTP/2 and absolutely require buffers 16kB or larger. |
| 7563 | */ |
| 7564 | #ifdef USE_OPENSSL |
| 7565 | if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) { |
| 7566 | #ifdef OPENSSL_NPN_NEGOTIATED |
| 7567 | /* check NPN */ |
| 7568 | 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] | 7569 | 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", |
| 7570 | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7571 | cfgerr++; |
| 7572 | } |
| 7573 | #endif |
| 7574 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 7575 | /* check ALPN */ |
| 7576 | 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] | 7577 | 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", |
| 7578 | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
Willy Tarreau | 45a66cc | 2017-11-24 11:28:00 +0100 | [diff] [blame] | 7579 | cfgerr++; |
| 7580 | } |
| 7581 | #endif |
| 7582 | } /* HTTP && bufsize < 16384 */ |
| 7583 | #endif |
| 7584 | |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7585 | if (!bind_conf->bind_proc) |
| 7586 | continue; |
| 7587 | |
| 7588 | mask = nbits(global.nbproc); |
| 7589 | if (curproxy->bind_proc) |
| 7590 | mask &= curproxy->bind_proc; |
| 7591 | /* mask cannot be null here thanks to the previous checks */ |
| 7592 | |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 7593 | nbproc = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7594 | bind_conf->bind_proc &= mask; |
| 7595 | |
| 7596 | if (!bind_conf->bind_proc && nbproc == 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7597 | 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", |
| 7598 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7599 | bind_conf->bind_proc = mask & ~(mask - 1); |
| 7600 | } |
| 7601 | else if (!bind_conf->bind_proc && nbproc > 1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7602 | 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", |
| 7603 | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
Willy Tarreau | 3d20958 | 2014-05-09 17:06:11 +0200 | [diff] [blame] | 7604 | bind_conf->bind_proc = 0; |
| 7605 | } |
| 7606 | } |
| 7607 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7608 | switch (curproxy->mode) { |
| 7609 | case PR_MODE_HEALTH: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7610 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7611 | if (!(curproxy->cap & PR_CAP_FE)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7612 | ha_alert("config : %s '%s' cannot be in health mode as it has no frontend capability.\n", |
| 7613 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7614 | cfgerr++; |
| 7615 | } |
| 7616 | |
| 7617 | if (curproxy->srv != NULL) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7618 | ha_warning("config : servers will be ignored for %s '%s'.\n", |
| 7619 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7620 | break; |
| 7621 | |
| 7622 | case PR_MODE_TCP: |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 7623 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7624 | break; |
| 7625 | |
| 7626 | case PR_MODE_HTTP: |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 7627 | curproxy->http_needed = 1; |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 7628 | break; |
| 7629 | } |
| 7630 | |
Willy Tarreau | 58aa5cc | 2018-02-08 09:55:09 +0100 | [diff] [blame] | 7631 | 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] | 7632 | ha_warning("config : %s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
| 7633 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | f3934b8 | 2015-08-11 11:36:45 +0200 | [diff] [blame] | 7634 | err_code |= ERR_WARN; |
| 7635 | } |
| 7636 | |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7637 | if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) { |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 7638 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7639 | if (curproxy->options & PR_O_TRANSP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7640 | ha_alert("config : %s '%s' cannot use both transparent and balance mode.\n", |
| 7641 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7642 | cfgerr++; |
| 7643 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7644 | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7645 | else if (curproxy->srv == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7646 | ha_alert("config : %s '%s' needs at least 1 server in balance mode.\n", |
| 7647 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7648 | cfgerr++; |
| 7649 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7650 | #endif |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7651 | else if (curproxy->options & PR_O_DISPATCH) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7652 | ha_warning("config : dispatch address of %s '%s' will be ignored in balance mode.\n", |
| 7653 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7654 | err_code |= ERR_WARN; |
Willy Tarreau | 3cd9af2 | 2009-03-15 14:06:41 +0100 | [diff] [blame] | 7655 | } |
| 7656 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7657 | 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] | 7658 | /* If no LB algo is set in a backend, and we're not in |
| 7659 | * transparent mode, dispatch mode nor proxy mode, we |
| 7660 | * want to use balance roundrobin by default. |
| 7661 | */ |
| 7662 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 7663 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7664 | } |
| 7665 | } |
Willy Tarreau | 193cf93 | 2007-09-17 10:17:23 +0200 | [diff] [blame] | 7666 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7667 | if (curproxy->options & PR_O_DISPATCH) |
| 7668 | curproxy->options &= ~(PR_O_TRANSP | PR_O_HTTP_PROXY); |
| 7669 | else if (curproxy->options & PR_O_HTTP_PROXY) |
| 7670 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_TRANSP); |
| 7671 | else if (curproxy->options & PR_O_TRANSP) |
| 7672 | curproxy->options &= ~(PR_O_DISPATCH | PR_O_HTTP_PROXY); |
Willy Tarreau | 8293658 | 2007-11-30 15:20:09 +0100 | [diff] [blame] | 7673 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7674 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_HTTP_CHK) { |
| 7675 | if (curproxy->options & PR_O_DISABLE404) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7676 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7677 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7678 | err_code |= ERR_WARN; |
| 7679 | curproxy->options &= ~PR_O_DISABLE404; |
| 7680 | } |
| 7681 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7682 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
| 7683 | "send-state", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 7684 | err_code |= ERR_WARN; |
| 7685 | curproxy->options &= ~PR_O2_CHK_SNDST; |
| 7686 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 7687 | } |
| 7688 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7689 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 7690 | if (!global.external_check) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7691 | ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
| 7692 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7693 | cfgerr++; |
| 7694 | } |
| 7695 | if (!curproxy->check_command) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7696 | ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
| 7697 | curproxy->id, "option external-check"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7698 | cfgerr++; |
| 7699 | } |
| 7700 | } |
| 7701 | |
Simon Horman | 64e3416 | 2015-02-06 11:11:57 +0900 | [diff] [blame] | 7702 | if (curproxy->email_alert.set) { |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7703 | 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] | 7704 | ha_warning("config : 'email-alert' will be ignored for %s '%s' (the presence any of " |
| 7705 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
| 7706 | "'email-alert myhostname', or 'email-alert to' " |
| 7707 | "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' " |
| 7708 | "to be present).\n", |
| 7709 | proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 7710 | err_code |= ERR_WARN; |
| 7711 | free_email_alert(curproxy); |
| 7712 | } |
| 7713 | if (!curproxy->email_alert.myhostname) |
Cyril Bonté | e22bfd6 | 2015-12-04 03:07:07 +0100 | [diff] [blame] | 7714 | curproxy->email_alert.myhostname = strdup(hostname); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 7715 | } |
| 7716 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7717 | if (curproxy->check_command) { |
| 7718 | int clear = 0; |
| 7719 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7720 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7721 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7722 | err_code |= ERR_WARN; |
| 7723 | clear = 1; |
| 7724 | } |
| 7725 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7726 | ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n", |
| 7727 | curproxy->id, "external-check command"); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7728 | cfgerr++; |
| 7729 | } |
| 7730 | if (clear) { |
| 7731 | free(curproxy->check_command); |
| 7732 | curproxy->check_command = NULL; |
| 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | if (curproxy->check_path) { |
| 7737 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7738 | ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
| 7739 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 7740 | err_code |= ERR_WARN; |
| 7741 | free(curproxy->check_path); |
| 7742 | curproxy->check_path = NULL; |
| 7743 | } |
| 7744 | } |
| 7745 | |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7746 | /* if a default backend was specified, let's find it */ |
| 7747 | if (curproxy->defbe.name) { |
| 7748 | struct proxy *target; |
| 7749 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7750 | target = proxy_be_by_name(curproxy->defbe.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7751 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7752 | ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
| 7753 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7754 | cfgerr++; |
| 7755 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7756 | ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
| 7757 | curproxy->id, curproxy->defbe.name); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 7758 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7759 | } else if (target->mode != curproxy->mode && |
| 7760 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7761 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7762 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
| 7763 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7764 | curproxy->conf.file, curproxy->conf.line, |
| 7765 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7766 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7767 | cfgerr++; |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 7768 | } else { |
| 7769 | free(curproxy->defbe.name); |
| 7770 | curproxy->defbe.be = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7771 | /* Update tot_fe_maxconn for a further fullconn's computation */ |
| 7772 | target->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7773 | /* Emit a warning if this proxy also has some servers */ |
| 7774 | if (curproxy->srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7775 | ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
| 7776 | curproxy->id); |
Willy Tarreau | ff67813 | 2012-02-13 14:32:34 +0100 | [diff] [blame] | 7777 | err_code |= ERR_WARN; |
| 7778 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7779 | } |
| 7780 | } |
| 7781 | |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7782 | if (!curproxy->defbe.be && (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) { |
| 7783 | /* Case of listen without default backend |
| 7784 | * The curproxy will be its own default backend |
| 7785 | * so we update tot_fe_maxconn for a further |
| 7786 | * fullconn's computation */ |
| 7787 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 7788 | } |
| 7789 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7790 | /* find the target proxy for 'use_backend' rules */ |
| 7791 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7792 | struct proxy *target; |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7793 | struct logformat_node *node; |
| 7794 | char *pxname; |
| 7795 | |
| 7796 | /* Try to parse the string as a log format expression. If the result |
| 7797 | * of the parsing is only one entry containing a simple string, then |
| 7798 | * it's a standard string corresponding to a static rule, thus the |
| 7799 | * parsing is cancelled and be.name is restored to be resolved. |
| 7800 | */ |
| 7801 | pxname = rule->be.name; |
| 7802 | LIST_INIT(&rule->be.expr); |
Thierry FOURNIER / OZON.IO | 4ed1c95 | 2016-11-24 23:57:54 +0100 | [diff] [blame] | 7803 | curproxy->conf.args.ctx = ARGC_UBK; |
| 7804 | curproxy->conf.args.file = rule->file; |
| 7805 | curproxy->conf.args.line = rule->line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7806 | err = NULL; |
| 7807 | 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] | 7808 | ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
| 7809 | rule->file, rule->line, pxname, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 7810 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 7811 | cfgerr++; |
| 7812 | continue; |
| 7813 | } |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 7814 | node = LIST_NEXT(&rule->be.expr, struct logformat_node *, list); |
| 7815 | |
| 7816 | if (!LIST_ISEMPTY(&rule->be.expr)) { |
| 7817 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr) { |
| 7818 | rule->dynamic = 1; |
| 7819 | free(pxname); |
| 7820 | continue; |
| 7821 | } |
| 7822 | /* simple string: free the expression and fall back to static rule */ |
| 7823 | free(node->arg); |
| 7824 | free(node); |
| 7825 | } |
| 7826 | |
| 7827 | rule->dynamic = 0; |
| 7828 | rule->be.name = pxname; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7829 | |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7830 | target = proxy_be_by_name(rule->be.name); |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 7831 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7832 | ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
| 7833 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7834 | cfgerr++; |
| 7835 | } else if (target == curproxy) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7836 | ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
| 7837 | curproxy->id, rule->be.name); |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7838 | cfgerr++; |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7839 | } else if (target->mode != curproxy->mode && |
| 7840 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
| 7841 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7842 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
| 7843 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
| 7844 | curproxy->conf.file, curproxy->conf.line, |
| 7845 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
| 7846 | target->conf.file, target->conf.line); |
Willy Tarreau | afb3992 | 2015-05-26 12:04:09 +0200 | [diff] [blame] | 7847 | cfgerr++; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7848 | } else { |
| 7849 | free((void *)rule->be.name); |
| 7850 | rule->be.backend = target; |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 7851 | /* For each target of switching rules, we update |
| 7852 | * their tot_fe_maxconn, except if a previous rule point |
| 7853 | * on the same backend or on the default backend */ |
| 7854 | if (rule->be.backend != curproxy->defbe.be) { |
| 7855 | struct switching_rule *swrule; |
| 7856 | |
| 7857 | list_for_each_entry(swrule, &curproxy->switching_rules, list) { |
| 7858 | if (rule == swrule) { |
| 7859 | target->tot_fe_maxconn += curproxy->maxconn; |
| 7860 | break; |
| 7861 | } |
| 7862 | else if (!swrule->dynamic && swrule->be.backend == rule->be.backend) { |
| 7863 | /* there is multiple ref of this backend */ |
| 7864 | break; |
| 7865 | } |
| 7866 | } |
| 7867 | } |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7868 | } |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7869 | } |
| 7870 | |
Willy Tarreau | 64ab607 | 2014-09-16 12:17:36 +0200 | [diff] [blame] | 7871 | /* find the target server for 'use_server' rules */ |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7872 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
| 7873 | struct server *target = findserver(curproxy, srule->srv.name); |
| 7874 | |
| 7875 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7876 | ha_alert("config : %s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
| 7877 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 7878 | cfgerr++; |
| 7879 | continue; |
| 7880 | } |
| 7881 | free((void *)srule->srv.name); |
| 7882 | srule->srv.ptr = target; |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 7883 | } |
| 7884 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7885 | /* find the target table for 'stick' rules */ |
| 7886 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
| 7887 | struct proxy *target; |
| 7888 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7889 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
| 7890 | if (mrule->flags & STK_IS_STORE) |
| 7891 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7892 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7893 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7894 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7895 | else |
| 7896 | target = curproxy; |
| 7897 | |
| 7898 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7899 | ha_alert("Proxy '%s': unable to find stick-table '%s'.\n", |
| 7900 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7901 | cfgerr++; |
| 7902 | } |
| 7903 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7904 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7905 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7906 | cfgerr++; |
| 7907 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7908 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7909 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7910 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7911 | cfgerr++; |
| 7912 | } |
| 7913 | else { |
| 7914 | free((void *)mrule->table.name); |
| 7915 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7916 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7917 | } |
| 7918 | } |
| 7919 | |
| 7920 | /* find the target table for 'store response' rules */ |
| 7921 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
| 7922 | struct proxy *target; |
| 7923 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 7924 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
| 7925 | |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7926 | if (mrule->table.name) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 7927 | target = proxy_tbl_by_name(mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7928 | else |
| 7929 | target = curproxy; |
| 7930 | |
| 7931 | if (!target) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7932 | ha_alert("Proxy '%s': unable to find store table '%s'.\n", |
| 7933 | curproxy->id, mrule->table.name); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7934 | cfgerr++; |
| 7935 | } |
| 7936 | else if (target->table.size == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7937 | ha_alert("Proxy '%s': stick-table '%s' used but not configured.\n", |
| 7938 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7939 | cfgerr++; |
| 7940 | } |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 7941 | else if (!stktable_compatible_sample(mrule->expr, target->table.type)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7942 | ha_alert("Proxy '%s': type of fetch not usable with type of stick-table '%s'.\n", |
| 7943 | curproxy->id, mrule->table.name ? mrule->table.name : curproxy->id); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7944 | cfgerr++; |
| 7945 | } |
| 7946 | else { |
| 7947 | free((void *)mrule->table.name); |
| 7948 | mrule->table.t = &(target->table); |
Willy Tarreau | 888617d | 2010-06-20 09:11:39 +0200 | [diff] [blame] | 7949 | stktable_alloc_data_type(&target->table, STKTABLE_DT_SERVER_ID, NULL); |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 7950 | } |
| 7951 | } |
| 7952 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7953 | /* check validity for 'tcp-request' layer 4 rules */ |
| 7954 | list_for_each_entry(arule, &curproxy->tcp_req.l4_rules, list) { |
| 7955 | err = NULL; |
| 7956 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7957 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7958 | free(err); |
Willy Tarreau | 5f53de7 | 2012-12-12 00:25:44 +0100 | [diff] [blame] | 7959 | cfgerr++; |
| 7960 | } |
Willy Tarreau | d1f9652 | 2010-08-03 19:34:32 +0200 | [diff] [blame] | 7961 | } |
| 7962 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7963 | /* check validity for 'tcp-request' layer 5 rules */ |
| 7964 | list_for_each_entry(arule, &curproxy->tcp_req.l5_rules, list) { |
| 7965 | err = NULL; |
| 7966 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7967 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7968 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7969 | cfgerr++; |
| 7970 | } |
| 7971 | } |
| 7972 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7973 | /* check validity for 'tcp-request' layer 6 rules */ |
| 7974 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 7975 | err = NULL; |
| 7976 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7977 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7978 | free(err); |
Baptiste Assmann | e954493 | 2015-11-03 23:31:35 +0100 | [diff] [blame] | 7979 | cfgerr++; |
| 7980 | } |
| 7981 | } |
| 7982 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7983 | /* check validity for 'http-request' layer 7 rules */ |
| 7984 | list_for_each_entry(arule, &curproxy->http_req_rules, list) { |
| 7985 | err = NULL; |
| 7986 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7987 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7988 | free(err); |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7989 | cfgerr++; |
| 7990 | } |
Ruoshan Huang | e4edc6b | 2016-07-14 15:07:45 +0800 | [diff] [blame] | 7991 | } |
| 7992 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7993 | /* check validity for 'http-response' layer 7 rules */ |
| 7994 | list_for_each_entry(arule, &curproxy->http_res_rules, list) { |
| 7995 | err = NULL; |
| 7996 | if (arule->check_ptr && !arule->check_ptr(arule, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 7997 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 7998 | free(err); |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 7999 | cfgerr++; |
| 8000 | } |
Willy Tarreau | 09448f7 | 2014-06-25 18:12:15 +0200 | [diff] [blame] | 8001 | } |
| 8002 | |
Willy Tarreau | b3dc39d | 2014-04-28 22:06:57 +0200 | [diff] [blame] | 8003 | /* move any "block" rules at the beginning of the http-request rules */ |
| 8004 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
| 8005 | /* insert block_rules into http_req_rules at the beginning */ |
| 8006 | curproxy->block_rules.p->n = curproxy->http_req_rules.n; |
| 8007 | curproxy->http_req_rules.n->p = curproxy->block_rules.p; |
| 8008 | curproxy->block_rules.n->p = &curproxy->http_req_rules; |
| 8009 | curproxy->http_req_rules.n = curproxy->block_rules.n; |
| 8010 | LIST_INIT(&curproxy->block_rules); |
| 8011 | } |
| 8012 | |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8013 | if (curproxy->table.peers.name) { |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8014 | struct peers *curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8015 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8016 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8017 | if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) { |
| 8018 | free((void *)curproxy->table.peers.name); |
Willy Tarreau | 973ca49 | 2013-01-17 21:34:52 +0100 | [diff] [blame] | 8019 | curproxy->table.peers.p = curpeers; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8020 | break; |
| 8021 | } |
| 8022 | } |
| 8023 | |
| 8024 | if (!curpeers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8025 | ha_alert("Proxy '%s': unable to find sync peers '%s'.\n", |
| 8026 | curproxy->id, curproxy->table.peers.name); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8027 | free((void *)curproxy->table.peers.name); |
| 8028 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8029 | cfgerr++; |
| 8030 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 8031 | else if (curpeers->state == PR_STSTOPPED) { |
| 8032 | /* silently disable this peers section */ |
| 8033 | curproxy->table.peers.p = NULL; |
| 8034 | } |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8035 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8036 | ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
| 8037 | curproxy->id, localpeer, curpeers->id); |
Willy Tarreau | d66bf96 | 2011-10-28 14:16:49 +0200 | [diff] [blame] | 8038 | curproxy->table.peers.p = NULL; |
Emeric Brun | 32da3c4 | 2010-09-23 18:39:19 +0200 | [diff] [blame] | 8039 | cfgerr++; |
| 8040 | } |
| 8041 | } |
| 8042 | |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8043 | |
| 8044 | if (curproxy->email_alert.mailers.name) { |
| 8045 | struct mailers *curmailers = mailers; |
| 8046 | |
| 8047 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8048 | if (!strcmp(curmailers->id, curproxy->email_alert.mailers.name)) |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8049 | break; |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8050 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8051 | if (!curmailers) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8052 | ha_alert("Proxy '%s': unable to find mailers '%s'.\n", |
| 8053 | curproxy->id, curproxy->email_alert.mailers.name); |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8054 | free_email_alert(curproxy); |
| 8055 | cfgerr++; |
| 8056 | } |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8057 | else { |
| 8058 | err = NULL; |
| 8059 | if (init_email_alert(curmailers, curproxy, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8060 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
Christopher Faulet | 0108bb3 | 2017-10-20 21:34:32 +0200 | [diff] [blame] | 8061 | free(err); |
| 8062 | cfgerr++; |
| 8063 | } |
| 8064 | } |
Simon Horman | 9dc4996 | 2015-01-30 11:22:59 +0900 | [diff] [blame] | 8065 | } |
| 8066 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8067 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & ST_CONVDONE) && |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8068 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8069 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8070 | ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
| 8071 | "proxy", curproxy->id); |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8072 | cfgerr++; |
| 8073 | goto out_uri_auth_compat; |
| 8074 | } |
| 8075 | |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8076 | 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] | 8077 | const char *uri_auth_compat_req[10]; |
Thierry FOURNIER | a28a942 | 2015-08-04 19:35:46 +0200 | [diff] [blame] | 8078 | struct act_rule *rule; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8079 | int i = 0; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8080 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8081 | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
| 8082 | uri_auth_compat_req[i++] = "auth"; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8083 | |
| 8084 | if (curproxy->uri_auth->auth_realm) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8085 | uri_auth_compat_req[i++] = "realm"; |
| 8086 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
| 8087 | } |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8088 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8089 | uri_auth_compat_req[i++] = "unless"; |
| 8090 | uri_auth_compat_req[i++] = "{"; |
| 8091 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
| 8092 | uri_auth_compat_req[i++] = "}"; |
| 8093 | uri_auth_compat_req[i++] = ""; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8094 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8095 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
| 8096 | if (!rule) { |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8097 | cfgerr++; |
| 8098 | break; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8099 | } |
| 8100 | |
Willy Tarreau | ff011f2 | 2011-01-06 17:51:27 +0100 | [diff] [blame] | 8101 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 8102 | |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8103 | if (curproxy->uri_auth->auth_realm) { |
| 8104 | free(curproxy->uri_auth->auth_realm); |
| 8105 | curproxy->uri_auth->auth_realm = NULL; |
| 8106 | } |
Krzysztof Piotr Oledzki | 329f74d | 2010-02-22 20:27:23 +0100 | [diff] [blame] | 8107 | |
| 8108 | curproxy->uri_auth->flags |= ST_CONVDONE; |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 8109 | } |
| 8110 | out_uri_auth_compat: |
| 8111 | |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8112 | /* check whether we have a log server that uses RFC5424 log format */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8113 | list_for_each_entry(tmplogsrv, &curproxy->logsrvs, list) { |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 8114 | if (tmplogsrv->format == LOG_FORMAT_RFC5424) { |
| 8115 | if (!curproxy->conf.logformat_sd_string) { |
| 8116 | /* set the default logformat_sd_string */ |
| 8117 | curproxy->conf.logformat_sd_string = default_rfc5424_sd_log_format; |
| 8118 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8119 | break; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8120 | } |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 8121 | } |
Dragan Dosen | 68d2e3a | 2015-09-19 22:35:44 +0200 | [diff] [blame] | 8122 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8123 | /* compile the log format */ |
| 8124 | if (!(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8125 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 8126 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 8127 | curproxy->conf.logformat_string != clf_http_log_format) |
| 8128 | free(curproxy->conf.logformat_string); |
| 8129 | curproxy->conf.logformat_string = NULL; |
| 8130 | free(curproxy->conf.lfs_file); |
| 8131 | curproxy->conf.lfs_file = NULL; |
| 8132 | curproxy->conf.lfs_line = 0; |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8133 | |
| 8134 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 8135 | free(curproxy->conf.logformat_sd_string); |
| 8136 | curproxy->conf.logformat_sd_string = NULL; |
| 8137 | free(curproxy->conf.lfsd_file); |
| 8138 | curproxy->conf.lfsd_file = NULL; |
| 8139 | curproxy->conf.lfsd_line = 0; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8140 | } |
| 8141 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8142 | if (curproxy->conf.logformat_string) { |
| 8143 | curproxy->conf.args.ctx = ARGC_LOG; |
| 8144 | curproxy->conf.args.file = curproxy->conf.lfs_file; |
| 8145 | curproxy->conf.args.line = curproxy->conf.lfs_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8146 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8147 | 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] | 8148 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8149 | ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
| 8150 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8151 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8152 | cfgerr++; |
| 8153 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8154 | curproxy->conf.args.file = NULL; |
| 8155 | curproxy->conf.args.line = 0; |
| 8156 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8157 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8158 | if (curproxy->conf.logformat_sd_string) { |
| 8159 | curproxy->conf.args.ctx = ARGC_LOGSD; |
| 8160 | curproxy->conf.args.file = curproxy->conf.lfsd_file; |
| 8161 | curproxy->conf.args.line = curproxy->conf.lfsd_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8162 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8163 | 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] | 8164 | SMP_VAL_FE_LOG_END, &err)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8165 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8166 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8167 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8168 | cfgerr++; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8169 | } 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] | 8170 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
| 8171 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8172 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8173 | cfgerr++; |
| 8174 | } |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8175 | curproxy->conf.args.file = NULL; |
| 8176 | curproxy->conf.args.line = 0; |
| 8177 | } |
| 8178 | |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8179 | if (curproxy->conf.uniqueid_format_string) { |
| 8180 | curproxy->conf.args.ctx = ARGC_UIF; |
| 8181 | curproxy->conf.args.file = curproxy->conf.uif_file; |
| 8182 | curproxy->conf.args.line = curproxy->conf.uif_line; |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8183 | err = NULL; |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8184 | 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] | 8185 | (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] | 8186 | ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
| 8187 | curproxy->conf.uif_file, curproxy->conf.uif_line, err); |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 8188 | free(err); |
Thierry FOURNIER / OZON.IO | 59fd511 | 2016-11-22 23:50:02 +0100 | [diff] [blame] | 8189 | cfgerr++; |
| 8190 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 8191 | curproxy->conf.args.file = NULL; |
| 8192 | curproxy->conf.args.line = 0; |
| 8193 | } |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8194 | |
Thierry FOURNIER | 9eec0a6 | 2014-01-22 18:38:02 +0100 | [diff] [blame] | 8195 | /* only now we can check if some args remain unresolved. |
| 8196 | * This must be done after the users and groups resolution. |
| 8197 | */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 8198 | cfgerr += smp_resolve_args(curproxy); |
| 8199 | if (!cfgerr) |
| 8200 | cfgerr += acl_find_targets(curproxy); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 8201 | |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8202 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8203 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 8204 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 8205 | (!curproxy->timeout.connect || |
| 8206 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8207 | ha_warning("config : missing timeouts for %s '%s'.\n" |
| 8208 | " | While not properly invalid, you will certainly encounter various problems\n" |
| 8209 | " | with such a configuration. To fix this, please ensure that all following\n" |
| 8210 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
| 8211 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8212 | err_code |= ERR_WARN; |
Willy Tarreau | 2738a14 | 2006-07-08 17:28:09 +0200 | [diff] [blame] | 8213 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8214 | |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8215 | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
| 8216 | * We must still support older configurations, so let's find out whether those |
| 8217 | * parameters have been set or must be copied from contimeouts. |
| 8218 | */ |
| 8219 | if (curproxy != &defproxy) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8220 | if (!curproxy->timeout.tarpit || |
| 8221 | curproxy->timeout.tarpit == defproxy.timeout.tarpit) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8222 | /* tarpit timeout not set. We search in the following order: |
| 8223 | * default.tarpit, curr.connect, default.connect. |
| 8224 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8225 | if (defproxy.timeout.tarpit) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8226 | curproxy->timeout.tarpit = defproxy.timeout.tarpit; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8227 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8228 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8229 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8230 | curproxy->timeout.tarpit = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8231 | } |
| 8232 | if ((curproxy->cap & PR_CAP_BE) && |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8233 | (!curproxy->timeout.queue || |
| 8234 | curproxy->timeout.queue == defproxy.timeout.queue)) { |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8235 | /* queue timeout not set. We search in the following order: |
| 8236 | * default.queue, curr.connect, default.connect. |
| 8237 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8238 | if (defproxy.timeout.queue) |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8239 | curproxy->timeout.queue = defproxy.timeout.queue; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8240 | else if (curproxy->timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8241 | curproxy->timeout.queue = curproxy->timeout.connect; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 8242 | else if (defproxy.timeout.connect) |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 8243 | curproxy->timeout.queue = defproxy.timeout.connect; |
Willy Tarreau | 1fa3126 | 2007-12-03 00:36:16 +0100 | [diff] [blame] | 8244 | } |
| 8245 | } |
| 8246 | |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 8247 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) { |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8248 | curproxy->check_len = sizeof(sslv3_client_hello_pkt) - 1; |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 8249 | curproxy->check_req = malloc(curproxy->check_len); |
Willy Tarreau | 137325d | 2010-02-01 16:38:17 +0100 | [diff] [blame] | 8250 | memcpy(curproxy->check_req, sslv3_client_hello_pkt, curproxy->check_len); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 8251 | } |
| 8252 | |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8253 | if (!LIST_ISEMPTY(&curproxy->tcpcheck_rules) && |
| 8254 | (curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_TCPCHK_CHK) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8255 | ha_warning("config : %s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
| 8256 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 215663d | 2014-06-13 18:30:23 +0200 | [diff] [blame] | 8257 | err_code |= ERR_WARN; |
| 8258 | } |
| 8259 | |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8260 | /* ensure that cookie capture length is not too large */ |
| 8261 | if (curproxy->capture_len >= global.tune.cookie_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8262 | ha_warning("config : truncating capture length to %d bytes for %s '%s'.\n", |
| 8263 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 193b8c6 | 2012-11-22 00:17:38 +0100 | [diff] [blame] | 8264 | err_code |= ERR_WARN; |
| 8265 | curproxy->capture_len = global.tune.cookie_len - 1; |
| 8266 | } |
| 8267 | |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8268 | /* The small pools required for the capture lists */ |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8269 | if (curproxy->nb_req_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8270 | curproxy->req_cap_pool = create_pool("ptrcap", |
| 8271 | curproxy->nb_req_cap * sizeof(char *), |
| 8272 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8273 | } |
| 8274 | |
| 8275 | if (curproxy->nb_rsp_cap) { |
Willy Tarreau | d9ed3d2 | 2014-06-13 12:23:06 +0200 | [diff] [blame] | 8276 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
| 8277 | curproxy->nb_rsp_cap * sizeof(char *), |
| 8278 | MEM_F_SHARED); |
Willy Tarreau | 9a54e13 | 2012-03-24 08:33:05 +0100 | [diff] [blame] | 8279 | } |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 8280 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8281 | switch (curproxy->load_server_state_from_file) { |
| 8282 | case PR_SRV_STATE_FILE_UNSPEC: |
| 8283 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 8284 | break; |
| 8285 | case PR_SRV_STATE_FILE_GLOBAL: |
| 8286 | if (!global.server_state_file) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8287 | 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", |
| 8288 | curproxy->id); |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 8289 | err_code |= ERR_WARN; |
| 8290 | } |
| 8291 | break; |
| 8292 | } |
| 8293 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8294 | /* first, we will invert the servers list order */ |
| 8295 | newsrv = NULL; |
| 8296 | while (curproxy->srv) { |
| 8297 | struct server *next; |
| 8298 | |
| 8299 | next = curproxy->srv->next; |
| 8300 | curproxy->srv->next = newsrv; |
| 8301 | newsrv = curproxy->srv; |
| 8302 | if (!next) |
| 8303 | break; |
| 8304 | curproxy->srv = next; |
| 8305 | } |
| 8306 | |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8307 | /* Check that no server name conflicts. This causes trouble in the stats. |
| 8308 | * We only emit a warning for the first conflict affecting each server, |
| 8309 | * in order to avoid combinatory explosion if all servers have the same |
| 8310 | * name. We do that only for servers which do not have an explicit ID, |
| 8311 | * because these IDs were made also for distinguishing them and we don't |
| 8312 | * want to annoy people who correctly manage them. |
| 8313 | */ |
| 8314 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
| 8315 | struct server *other_srv; |
| 8316 | |
| 8317 | if (newsrv->puid) |
| 8318 | continue; |
| 8319 | |
| 8320 | for (other_srv = curproxy->srv; other_srv && other_srv != newsrv; other_srv = other_srv->next) { |
| 8321 | if (!other_srv->puid && strcmp(other_srv->id, newsrv->id) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8322 | 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", |
| 8323 | newsrv->conf.file, newsrv->conf.line, |
| 8324 | proxy_type_str(curproxy), curproxy->id, |
| 8325 | newsrv->id, other_srv->conf.line); |
Willy Tarreau | 17edc81 | 2014-01-03 12:14:34 +0100 | [diff] [blame] | 8326 | break; |
| 8327 | } |
| 8328 | } |
| 8329 | } |
| 8330 | |
Willy Tarreau | dd70165 | 2010-05-25 23:03:02 +0200 | [diff] [blame] | 8331 | /* assign automatic UIDs to servers which don't have one yet */ |
| 8332 | next_id = 1; |
| 8333 | newsrv = curproxy->srv; |
| 8334 | while (newsrv != NULL) { |
| 8335 | if (!newsrv->puid) { |
| 8336 | /* server ID not set, use automatic numbering with first |
| 8337 | * spare entry starting with next_svid. |
| 8338 | */ |
| 8339 | next_id = get_next_id(&curproxy->conf.used_server_id, next_id); |
| 8340 | newsrv->conf.id.key = newsrv->puid = next_id; |
| 8341 | eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id); |
| 8342 | } |
| 8343 | next_id++; |
| 8344 | newsrv = newsrv->next; |
| 8345 | } |
| 8346 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 8347 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 8348 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8349 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8350 | /* |
| 8351 | * If this server supports a maxconn parameter, it needs a dedicated |
| 8352 | * tasks to fill the emptied slots when a connection leaves. |
| 8353 | * Also, resolve deferred tracking dependency if needed. |
| 8354 | */ |
| 8355 | newsrv = curproxy->srv; |
| 8356 | while (newsrv != NULL) { |
| 8357 | if (newsrv->minconn > newsrv->maxconn) { |
| 8358 | /* Only 'minconn' was specified, or it was higher than or equal |
| 8359 | * to 'maxconn'. Let's turn this into maxconn and clean it, as |
| 8360 | * this will avoid further useless expensive computations. |
| 8361 | */ |
| 8362 | newsrv->maxconn = newsrv->minconn; |
| 8363 | } else if (newsrv->maxconn && !newsrv->minconn) { |
| 8364 | /* minconn was not specified, so we set it to maxconn */ |
| 8365 | newsrv->minconn = newsrv->maxconn; |
| 8366 | } |
| 8367 | |
Willy Tarreau | 17d4538 | 2016-12-22 21:16:08 +0100 | [diff] [blame] | 8368 | /* this will also properly set the transport layer for prod and checks */ |
| 8369 | if (newsrv->use_ssl || newsrv->check.use_ssl) { |
| 8370 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
| 8371 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
| 8372 | } |
Emeric Brun | 94324a4 | 2012-10-11 14:00:19 +0200 | [diff] [blame] | 8373 | |
Willy Tarreau | 2f075e9 | 2013-12-03 11:11:34 +0100 | [diff] [blame] | 8374 | /* set the check type on the server */ |
| 8375 | newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; |
| 8376 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8377 | if (newsrv->trackit) { |
| 8378 | struct proxy *px; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8379 | struct server *srv, *loop; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8380 | char *pname, *sname; |
| 8381 | |
| 8382 | pname = newsrv->trackit; |
| 8383 | sname = strrchr(pname, '/'); |
| 8384 | |
| 8385 | if (sname) |
| 8386 | *sname++ = '\0'; |
| 8387 | else { |
| 8388 | sname = pname; |
| 8389 | pname = NULL; |
| 8390 | } |
| 8391 | |
| 8392 | if (pname) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 8393 | px = proxy_be_by_name(pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8394 | if (!px) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8395 | ha_alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", |
| 8396 | proxy_type_str(curproxy), curproxy->id, |
| 8397 | newsrv->id, pname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8398 | cfgerr++; |
| 8399 | goto next_srv; |
| 8400 | } |
| 8401 | } else |
| 8402 | px = curproxy; |
| 8403 | |
| 8404 | srv = findserver(px, sname); |
| 8405 | if (!srv) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8406 | ha_alert("config : %s '%s', server '%s': unable to find required server '%s' for tracking.\n", |
| 8407 | proxy_type_str(curproxy), curproxy->id, |
| 8408 | newsrv->id, sname); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8409 | cfgerr++; |
| 8410 | goto next_srv; |
| 8411 | } |
| 8412 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8413 | if (!(srv->check.state & CHK_ST_CONFIGURED) && |
| 8414 | !(srv->agent.state & CHK_ST_CONFIGURED) && |
| 8415 | !srv->track && !srv->trackit) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8416 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for " |
| 8417 | "tracking as it does not have any check nor agent enabled.\n", |
| 8418 | proxy_type_str(curproxy), curproxy->id, |
| 8419 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 8420 | cfgerr++; |
| 8421 | goto next_srv; |
| 8422 | } |
| 8423 | |
| 8424 | for (loop = srv->track; loop && loop != newsrv; loop = loop->track); |
| 8425 | |
Frédéric Lécaille | 2efc649 | 2017-03-14 14:32:17 +0100 | [diff] [blame] | 8426 | if (newsrv == srv || loop) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8427 | ha_alert("config : %s '%s', server '%s': unable to track %s/%s as it " |
| 8428 | "belongs to a tracking chain looping back to %s/%s.\n", |
| 8429 | proxy_type_str(curproxy), curproxy->id, |
| 8430 | newsrv->id, px->id, srv->id, px->id, |
| 8431 | newsrv == srv ? srv->id : loop->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8432 | cfgerr++; |
| 8433 | goto next_srv; |
| 8434 | } |
| 8435 | |
| 8436 | if (curproxy != px && |
| 8437 | (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8438 | ha_alert("config : %s '%s', server '%s': unable to use %s/%s for" |
| 8439 | "tracking: disable-on-404 option inconsistency.\n", |
| 8440 | proxy_type_str(curproxy), curproxy->id, |
| 8441 | newsrv->id, px->id, srv->id); |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8442 | cfgerr++; |
| 8443 | goto next_srv; |
| 8444 | } |
| 8445 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8446 | newsrv->track = srv; |
Willy Tarreau | 1a53a3a | 2013-12-11 15:27:05 +0100 | [diff] [blame] | 8447 | newsrv->tracknext = srv->trackers; |
| 8448 | srv->trackers = newsrv; |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8449 | |
| 8450 | free(newsrv->trackit); |
| 8451 | newsrv->trackit = NULL; |
| 8452 | } |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 8453 | |
Willy Tarreau | 62c3be2 | 2012-01-20 13:12:32 +0100 | [diff] [blame] | 8454 | next_srv: |
| 8455 | newsrv = newsrv->next; |
| 8456 | } |
| 8457 | |
Olivier Houchard | 4e69404 | 2017-03-14 20:01:29 +0100 | [diff] [blame] | 8458 | /* |
| 8459 | * Try to generate dynamic cookies for servers now. |
| 8460 | * It couldn't be done earlier, since at the time we parsed |
| 8461 | * the server line, we may not have known yet that we |
| 8462 | * should use dynamic cookies, or the secret key may not |
| 8463 | * have been provided yet. |
| 8464 | */ |
| 8465 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
| 8466 | newsrv = curproxy->srv; |
| 8467 | while (newsrv != NULL) { |
| 8468 | srv_set_dyncookie(newsrv); |
| 8469 | newsrv = newsrv->next; |
| 8470 | } |
| 8471 | |
| 8472 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8473 | /* We have to initialize the server lookup mechanism depending |
| 8474 | * on what LB algorithm was choosen. |
| 8475 | */ |
| 8476 | |
| 8477 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
| 8478 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
| 8479 | case BE_LB_KIND_RR: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8480 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
| 8481 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8482 | init_server_map(curproxy); |
Willy Tarreau | 760e81d | 2018-05-03 07:20:40 +0200 | [diff] [blame] | 8483 | } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) { |
| 8484 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8485 | chash_init_server_tree(curproxy); |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 8486 | } else { |
| 8487 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
| 8488 | fwrr_init_server_groups(curproxy); |
| 8489 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8490 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8491 | |
Willy Tarreau | 3ebb116 | 2012-02-13 16:57:44 +0100 | [diff] [blame] | 8492 | case BE_LB_KIND_CB: |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 8493 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
| 8494 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
| 8495 | fwlc_init_server_tree(curproxy); |
| 8496 | } else { |
| 8497 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
| 8498 | fas_init_server_tree(curproxy); |
| 8499 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8500 | break; |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8501 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8502 | case BE_LB_KIND_HI: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 8503 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
| 8504 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
| 8505 | chash_init_server_tree(curproxy); |
| 8506 | } else { |
| 8507 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
| 8508 | init_server_map(curproxy); |
| 8509 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 8510 | break; |
| 8511 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 8512 | HA_SPIN_INIT(&curproxy->lbprm.lock); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8513 | |
| 8514 | if (curproxy->options & PR_O_LOGASAP) |
| 8515 | curproxy->to_log &= ~LW_BYTES; |
| 8516 | |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8517 | if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 8518 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->logsrvs) && |
| 8519 | (!LIST_ISEMPTY(&curproxy->logformat) || !LIST_ISEMPTY(&curproxy->logformat_sd))) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8520 | ha_warning("config : log format ignored for %s '%s' since it has no log address.\n", |
| 8521 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e7ded1f | 2009-08-09 10:11:45 +0200 | [diff] [blame] | 8522 | err_code |= ERR_WARN; |
| 8523 | } |
| 8524 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8525 | if (curproxy->mode != PR_MODE_HTTP) { |
| 8526 | int optnum; |
| 8527 | |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8528 | if (curproxy->uri_auth) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8529 | ha_warning("config : 'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8530 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8531 | err_code |= ERR_WARN; |
| 8532 | curproxy->uri_auth = NULL; |
| 8533 | } |
| 8534 | |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8535 | if (curproxy->capture_name) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8536 | ha_warning("config : 'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
| 8537 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8538 | err_code |= ERR_WARN; |
| 8539 | } |
| 8540 | |
| 8541 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8542 | ha_warning("config : 'http-request' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8543 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8544 | err_code |= ERR_WARN; |
| 8545 | } |
| 8546 | |
| 8547 | if (!LIST_ISEMPTY(&curproxy->http_res_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8548 | ha_warning("config : 'http-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8549 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8550 | err_code |= ERR_WARN; |
| 8551 | } |
| 8552 | |
| 8553 | if (!LIST_ISEMPTY(&curproxy->block_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8554 | ha_warning("config : 'block' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8555 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8556 | err_code |= ERR_WARN; |
| 8557 | } |
| 8558 | |
| 8559 | if (!LIST_ISEMPTY(&curproxy->redirect_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8560 | ha_warning("config : 'redirect' rules ignored for %s '%s' as they require HTTP mode.\n", |
| 8561 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | de7dc88 | 2017-03-10 11:49:21 +0100 | [diff] [blame] | 8562 | err_code |= ERR_WARN; |
| 8563 | } |
| 8564 | |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8565 | if (curproxy->options & (PR_O_FWDFOR | PR_O_FF_ALWAYS)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8566 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8567 | "forwardfor", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8568 | err_code |= ERR_WARN; |
Willy Tarreau | 87cf514 | 2011-08-19 22:57:24 +0200 | [diff] [blame] | 8569 | curproxy->options &= ~(PR_O_FWDFOR | PR_O_FF_ALWAYS); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8570 | } |
| 8571 | |
| 8572 | if (curproxy->options & PR_O_ORGTO) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8573 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8574 | "originalto", proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8575 | err_code |= ERR_WARN; |
| 8576 | curproxy->options &= ~PR_O_ORGTO; |
| 8577 | } |
| 8578 | |
| 8579 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
| 8580 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
| 8581 | (curproxy->cap & cfg_opts[optnum].cap) && |
| 8582 | (curproxy->options & cfg_opts[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8583 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8584 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8585 | err_code |= ERR_WARN; |
| 8586 | curproxy->options &= ~cfg_opts[optnum].val; |
| 8587 | } |
| 8588 | } |
| 8589 | |
| 8590 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
| 8591 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
| 8592 | (curproxy->cap & cfg_opts2[optnum].cap) && |
| 8593 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8594 | ha_warning("config : 'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
| 8595 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8596 | err_code |= ERR_WARN; |
| 8597 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 8598 | } |
| 8599 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8600 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8601 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8602 | if (curproxy->conn_src.bind_hdr_occ) { |
| 8603 | curproxy->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8604 | ha_warning("config : %s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
| 8605 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8606 | err_code |= ERR_WARN; |
| 8607 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8608 | #endif |
Willy Tarreau | e24fdfb | 2010-03-25 07:22:56 +0100 | [diff] [blame] | 8609 | } |
| 8610 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 8611 | /* |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8612 | * ensure that we're not cross-dressing a TCP server into HTTP. |
| 8613 | */ |
| 8614 | newsrv = curproxy->srv; |
| 8615 | while (newsrv != NULL) { |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8616 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8617 | ha_alert("config : %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
| 8618 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 8619 | cfgerr++; |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8620 | } |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 8621 | |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8622 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8623 | ha_warning("config : %s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
| 8624 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 0cec331 | 2011-10-31 13:49:26 +0100 | [diff] [blame] | 8625 | err_code |= ERR_WARN; |
| 8626 | } |
| 8627 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 8628 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8629 | ha_warning("config : %s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
| 8630 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 82ffa39 | 2013-08-13 17:19:08 +0200 | [diff] [blame] | 8631 | err_code |= ERR_WARN; |
| 8632 | } |
| 8633 | |
Willy Tarreau | 29fbe51 | 2015-08-20 19:35:14 +0200 | [diff] [blame] | 8634 | #if defined(CONFIG_HAP_TRANSPARENT) |
Willy Tarreau | ef9a360 | 2012-12-08 22:29:20 +0100 | [diff] [blame] | 8635 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
| 8636 | newsrv->conn_src.bind_hdr_occ = 0; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8637 | ha_warning("config : %s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
| 8638 | 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] | 8639 | err_code |= ERR_WARN; |
| 8640 | } |
Willy Tarreau | efa5f51 | 2010-03-30 20:13:29 +0200 | [diff] [blame] | 8641 | #endif |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8642 | |
Willy Tarreau | 46deab6 | 2018-04-28 07:18:15 +0200 | [diff] [blame] | 8643 | if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) |
| 8644 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 8645 | |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8646 | if ((curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) { |
| 8647 | if ((curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8648 | (curproxy->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP || |
| 8649 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CLI || |
| 8650 | (newsrv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_CIP) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8651 | 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", |
| 8652 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8653 | err_code |= ERR_WARN; |
| 8654 | } |
| 8655 | |
| 8656 | |
| 8657 | if (newsrv->pp_opts & (SRV_PP_V1|SRV_PP_V2)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8658 | 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", |
| 8659 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
Willy Tarreau | 4c18346 | 2017-01-06 12:21:38 +0100 | [diff] [blame] | 8660 | err_code |= ERR_WARN; |
| 8661 | } |
| 8662 | } |
| 8663 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 8664 | newsrv = newsrv->next; |
| 8665 | } |
| 8666 | |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8667 | /* check if we have a frontend with "tcp-request content" looking at L7 |
| 8668 | * with no inspect-delay |
| 8669 | */ |
| 8670 | if ((curproxy->cap & PR_CAP_FE) && !curproxy->tcp_req.inspect_delay) { |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8671 | list_for_each_entry(arule, &curproxy->tcp_req.inspect_rules, list) { |
| 8672 | if (arule->action == ACT_TCP_CAPTURE && |
| 8673 | !(arule->arg.cap.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8674 | break; |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8675 | if ((arule->action >= ACT_ACTION_TRK_SC0 && arule->action <= ACT_ACTION_TRK_SCMAX) && |
| 8676 | !(arule->arg.trk_ctr.expr->fetch->val & SMP_VAL_FE_SES_ACC)) |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8677 | break; |
| 8678 | } |
| 8679 | |
Christopher Faulet | e4e830d | 2017-09-18 14:51:41 +0200 | [diff] [blame] | 8680 | if (&arule->list != &curproxy->tcp_req.inspect_rules) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8681 | ha_warning("config : %s '%s' : some 'tcp-request content' rules explicitly depending on request" |
| 8682 | " contents were found in a frontend without any 'tcp-request inspect-delay' setting." |
| 8683 | " This means that these rules will randomly find their contents. This can be fixed by" |
| 8684 | " setting the tcp-request inspect-delay.\n", |
| 8685 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | e42bd96 | 2014-09-16 16:21:19 +0200 | [diff] [blame] | 8686 | err_code |= ERR_WARN; |
| 8687 | } |
| 8688 | } |
| 8689 | |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8690 | /* Check filter configuration, if any */ |
| 8691 | cfgerr += flt_check(curproxy); |
| 8692 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8693 | if (curproxy->cap & PR_CAP_FE) { |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 8694 | if (!curproxy->accept) |
| 8695 | curproxy->accept = frontend_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 8696 | |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8697 | if (curproxy->tcp_req.inspect_delay || |
| 8698 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8699 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8700 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8701 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8702 | 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] | 8703 | 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] | 8704 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8705 | |
| 8706 | /* both TCP and HTTP must check switching rules */ |
| 8707 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8708 | |
| 8709 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8710 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8711 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8712 | 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] | 8713 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8714 | curproxy->fe_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8715 | curproxy->fe_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8716 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8717 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8718 | } |
| 8719 | |
| 8720 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 8721 | if (curproxy->tcp_req.inspect_delay || |
| 8722 | !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules)) |
| 8723 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
| 8724 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 8725 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules)) |
| 8726 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
| 8727 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 8728 | if (curproxy->mode == PR_MODE_HTTP) { |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8729 | 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] | 8730 | 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] | 8731 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8732 | |
| 8733 | /* If the backend does requires RDP cookie persistence, we have to |
| 8734 | * enable the corresponding analyser. |
| 8735 | */ |
| 8736 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
| 8737 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8738 | |
| 8739 | /* Add filters analyzers if needed */ |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 8740 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8741 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
| 8742 | 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] | 8743 | if (curproxy->mode == PR_MODE_HTTP) { |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 8744 | curproxy->be_req_ana |= AN_REQ_FLT_HTTP_HDRS; |
| 8745 | curproxy->be_rsp_ana |= AN_RES_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 8746 | } |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 8747 | } |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8748 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8749 | } |
| 8750 | |
| 8751 | /***********************************************************/ |
| 8752 | /* At this point, target names have already been resolved. */ |
| 8753 | /***********************************************************/ |
| 8754 | |
| 8755 | /* Check multi-process mode compatibility */ |
| 8756 | |
| 8757 | if (global.nbproc > 1 && global.stats_fe) { |
| 8758 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8759 | unsigned long mask; |
| 8760 | |
| 8761 | mask = nbits(global.nbproc); |
| 8762 | if (global.stats_fe->bind_proc) |
| 8763 | mask &= global.stats_fe->bind_proc; |
| 8764 | |
| 8765 | if (bind_conf->bind_proc) |
| 8766 | mask &= bind_conf->bind_proc; |
| 8767 | |
| 8768 | /* stop here if more than one process is used */ |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8769 | if (my_popcountl(mask) > 1) |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8770 | break; |
| 8771 | } |
| 8772 | if (&bind_conf->by_fe != &global.stats_fe->conf.bind) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8773 | 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] | 8774 | } |
| 8775 | } |
| 8776 | |
| 8777 | /* Make each frontend inherit bind-process from its listeners when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8778 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8779 | if (curproxy->bind_proc) |
| 8780 | continue; |
| 8781 | |
| 8782 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
| 8783 | unsigned long mask; |
| 8784 | |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8785 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8786 | curproxy->bind_proc |= mask; |
| 8787 | } |
| 8788 | |
| 8789 | if (!curproxy->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8790 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8791 | } |
| 8792 | |
| 8793 | if (global.stats_fe) { |
| 8794 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 8795 | unsigned long mask; |
| 8796 | |
Cyril Bonté | 0618195 | 2016-02-24 00:14:54 +0100 | [diff] [blame] | 8797 | mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8798 | global.stats_fe->bind_proc |= mask; |
| 8799 | } |
| 8800 | if (!global.stats_fe->bind_proc) |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8801 | global.stats_fe->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8802 | } |
| 8803 | |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8804 | /* propagate bindings from frontends to backends. Don't do it if there |
| 8805 | * are any fatal errors as we must not call it with unresolved proxies. |
| 8806 | */ |
| 8807 | if (!cfgerr) { |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8808 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | acbe8ab | 2014-10-01 20:50:17 +0200 | [diff] [blame] | 8809 | if (curproxy->cap & PR_CAP_FE) |
| 8810 | propagate_processes(curproxy, NULL); |
| 8811 | } |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8812 | } |
| 8813 | |
| 8814 | /* Bind each unbound backend to all processes when not specified. */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8815 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8816 | if (curproxy->bind_proc) |
| 8817 | continue; |
Willy Tarreau | e428b08 | 2015-05-04 21:57:58 +0200 | [diff] [blame] | 8818 | curproxy->bind_proc = nbits(global.nbproc); |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8819 | } |
| 8820 | |
| 8821 | /*******************************************************/ |
| 8822 | /* At this step, all proxies have a non-null bind_proc */ |
| 8823 | /*******************************************************/ |
| 8824 | |
| 8825 | /* perform the final checks before creating tasks */ |
| 8826 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8827 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 419ead8 | 2014-09-16 13:41:21 +0200 | [diff] [blame] | 8828 | struct listener *listener; |
| 8829 | unsigned int next_id; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8830 | |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8831 | /* Configure SSL for each bind line. |
| 8832 | * Note: if configuration fails at some point, the ->ctx member |
| 8833 | * remains NULL so that listeners can later detach. |
| 8834 | */ |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8835 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 55d3791 | 2016-12-21 23:38:39 +0100 | [diff] [blame] | 8836 | if (bind_conf->xprt->prepare_bind_conf && |
| 8837 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8838 | cfgerr++; |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8839 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8840 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8841 | /* adjust this proxy's listeners */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8842 | next_id = 1; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 8843 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8844 | int nbproc; |
| 8845 | |
| 8846 | nbproc = my_popcountl(curproxy->bind_proc & |
Cyril Bonté | 4920d70 | 2016-04-15 07:58:43 +0200 | [diff] [blame] | 8847 | (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] | 8848 | nbits(global.nbproc)); |
| 8849 | |
| 8850 | if (!nbproc) /* no intersection between listener and frontend */ |
| 8851 | nbproc = 1; |
| 8852 | |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8853 | if (!listener->luid) { |
| 8854 | /* listener ID not set, use automatic numbering with first |
| 8855 | * spare entry starting with next_luid. |
| 8856 | */ |
| 8857 | next_id = get_next_id(&curproxy->conf.used_listener_id, next_id); |
| 8858 | listener->conf.id.key = listener->luid = next_id; |
| 8859 | eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id); |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8860 | } |
Krzysztof Piotr Oledzki | df5cb9f | 2010-02-05 20:58:27 +0100 | [diff] [blame] | 8861 | next_id++; |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 8862 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8863 | /* enable separate counters */ |
| 8864 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
Willy Tarreau | ae9bea0 | 2016-11-25 14:44:52 +0100 | [diff] [blame] | 8865 | listener->counters = calloc(1, sizeof(*listener->counters)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 8866 | if (!listener->name) |
| 8867 | memprintf(&listener->name, "sock-%d", listener->luid); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 8868 | } |
Willy Tarreau | 81796be | 2012-09-22 19:11:47 +0200 | [diff] [blame] | 8869 | |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8870 | if (curproxy->options & PR_O_TCP_NOLING) |
| 8871 | listener->options |= LI_O_NOLINGER; |
Willy Tarreau | 32368ce | 2012-09-06 11:10:55 +0200 | [diff] [blame] | 8872 | if (!listener->maxconn) |
| 8873 | listener->maxconn = curproxy->maxconn; |
| 8874 | if (!listener->backlog) |
| 8875 | listener->backlog = curproxy->backlog; |
Willy Tarreau | 16a2147 | 2012-11-19 12:39:59 +0100 | [diff] [blame] | 8876 | if (!listener->maxaccept) |
| 8877 | listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64; |
| 8878 | |
| 8879 | /* we want to have an optimal behaviour on single process mode to |
| 8880 | * maximize the work at once, but in multi-process we want to keep |
| 8881 | * some fairness between processes, so we target half of the max |
| 8882 | * number of events to be balanced over all the processes the proxy |
| 8883 | * is bound to. Rememeber that maxaccept = -1 must be kept as it is |
| 8884 | * used to disable the limit. |
| 8885 | */ |
| 8886 | if (listener->maxaccept > 0) { |
| 8887 | if (nbproc > 1) |
| 8888 | listener->maxaccept = (listener->maxaccept + 1) / 2; |
| 8889 | listener->maxaccept = (listener->maxaccept + nbproc - 1) / nbproc; |
| 8890 | } |
| 8891 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 8892 | listener->accept = session_accept_fd; |
Willy Tarreau | c1a2167 | 2009-08-16 22:37:44 +0200 | [diff] [blame] | 8893 | listener->analysers |= curproxy->fe_req_ana; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 8894 | listener->default_target = curproxy->default_target; |
Willy Tarreau | 3bc1377 | 2008-12-07 11:50:35 +0100 | [diff] [blame] | 8895 | |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8896 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l4_rules)) |
Willy Tarreau | 7d9736f | 2016-10-21 16:34:21 +0200 | [diff] [blame] | 8897 | listener->options |= LI_O_TCP_L4_RULES; |
Willy Tarreau | a5c0ab2 | 2010-05-31 10:30:33 +0200 | [diff] [blame] | 8898 | |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 8899 | if (!LIST_ISEMPTY(&curproxy->tcp_req.l5_rules)) |
| 8900 | listener->options |= LI_O_TCP_L5_RULES; |
| 8901 | |
Willy Tarreau | de3041d | 2010-05-31 10:56:17 +0200 | [diff] [blame] | 8902 | if (curproxy->mon_mask.s_addr) |
| 8903 | listener->options |= LI_O_CHK_MONNET; |
| 8904 | |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8905 | /* smart accept mode is automatic in HTTP mode */ |
| 8906 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8907 | ((curproxy->mode == PR_MODE_HTTP || listener->bind_conf->is_ssl) && |
Willy Tarreau | 9ea05a7 | 2009-06-14 12:07:01 +0200 | [diff] [blame] | 8908 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
| 8909 | listener->options |= LI_O_NOQUICKACK; |
Willy Tarreau | e6b9894 | 2007-10-29 01:09:36 +0100 | [diff] [blame] | 8910 | } |
| 8911 | |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8912 | /* Release unused SSL configs */ |
| 8913 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
Willy Tarreau | 795cdab | 2016-12-22 17:30:54 +0100 | [diff] [blame] | 8914 | if (!bind_conf->is_ssl && bind_conf->xprt->destroy_bind_conf) |
| 8915 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 8916 | } |
Willy Tarreau | f5ae8f7 | 2012-09-07 16:58:00 +0200 | [diff] [blame] | 8917 | |
Willy Tarreau | 7c0ffd2 | 2016-04-14 11:47:38 +0200 | [diff] [blame] | 8918 | if (my_popcountl(curproxy->bind_proc & nbits(global.nbproc)) > 1) { |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8919 | if (curproxy->uri_auth) { |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8920 | int count, maxproc = 0; |
| 8921 | |
| 8922 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 8923 | count = my_popcountl(bind_conf->bind_proc); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8924 | if (count > maxproc) |
| 8925 | maxproc = count; |
| 8926 | } |
| 8927 | /* backends have 0, frontends have 1 or more */ |
| 8928 | if (maxproc != 1) |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8929 | ha_warning("Proxy '%s': in multi-process mode, stats will be" |
| 8930 | " limited to process assigned to the current request.\n", |
| 8931 | curproxy->id); |
Willy Tarreau | eb791e0 | 2014-09-16 15:11:04 +0200 | [diff] [blame] | 8932 | |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8933 | if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8934 | ha_warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", |
| 8935 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8936 | } |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8937 | } |
Willy Tarreau | 102df61 | 2014-05-07 23:56:38 +0200 | [diff] [blame] | 8938 | if (!LIST_ISEMPTY(&curproxy->sticking_rules)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8939 | ha_warning("Proxy '%s': sticking rules will not work correctly in multi-process mode.\n", |
| 8940 | curproxy->id); |
Cyril Bonté | 02ff8ef | 2010-12-14 22:48:49 +0100 | [diff] [blame] | 8941 | } |
| 8942 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8943 | |
| 8944 | /* create the task associated with the proxy */ |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 8945 | curproxy->task = task_new(MAX_THREADS_MASK); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8946 | if (curproxy->task) { |
| 8947 | curproxy->task->context = curproxy; |
| 8948 | curproxy->task->process = manage_proxy; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8949 | } else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 8950 | ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
| 8951 | curproxy->id); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 8952 | cfgerr++; |
| 8953 | } |
Willy Tarreau | b369a04 | 2014-09-16 13:21:03 +0200 | [diff] [blame] | 8954 | } |
| 8955 | |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8956 | /* automatically compute fullconn if not set. We must not do it in the |
| 8957 | * loop above because cross-references are not yet fully resolved. |
| 8958 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8959 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8960 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 8961 | * the possible incoming frontend's maxconns. |
| 8962 | */ |
| 8963 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8964 | /* we have the sum of the maxconns in <total>. We only |
| 8965 | * keep 10% of that sum to set the default fullconn, with |
| 8966 | * a hard minimum of 1 (to avoid a divide by zero). |
| 8967 | */ |
Emeric Brun | 3f78357 | 2017-01-12 11:21:28 +0100 | [diff] [blame] | 8968 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
Willy Tarreau | fbb7842 | 2011-06-05 15:38:35 +0200 | [diff] [blame] | 8969 | if (!curproxy->fullconn) |
| 8970 | curproxy->fullconn = 1; |
| 8971 | } |
Krzysztof Piotr Oledzki | 9610504 | 2010-01-29 17:50:44 +0100 | [diff] [blame] | 8972 | } |
| 8973 | |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8974 | /* |
| 8975 | * Recount currently required checks. |
| 8976 | */ |
| 8977 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8978 | for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) { |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8979 | int optnum; |
| 8980 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8981 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
| 8982 | if (curproxy->options & cfg_opts[optnum].val) |
| 8983 | global.last_checks |= cfg_opts[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8984 | |
Willy Tarreau | 66aa61f | 2009-01-18 21:44:07 +0100 | [diff] [blame] | 8985 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
| 8986 | if (curproxy->options2 & cfg_opts2[optnum].val) |
| 8987 | global.last_checks |= cfg_opts2[optnum].checks; |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 8988 | } |
| 8989 | |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 8990 | /* compute the required process bindings for the peers */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 8991 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) |
Willy Tarreau | 0fca483 | 2015-05-01 19:12:05 +0200 | [diff] [blame] | 8992 | if (curproxy->table.peers.p) |
| 8993 | curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc; |
| 8994 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 8995 | if (cfg_peers) { |
| 8996 | struct peers *curpeers = cfg_peers, **last; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 8997 | struct peer *p, *pb; |
| 8998 | |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 8999 | /* Remove all peers sections which don't have a valid listener, |
| 9000 | * which are not used by any table, or which are bound to more |
| 9001 | * than one process. |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9002 | */ |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 9003 | last = &cfg_peers; |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9004 | while (*last) { |
| 9005 | curpeers = *last; |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9006 | |
| 9007 | if (curpeers->state == PR_STSTOPPED) { |
| 9008 | /* the "disabled" keyword was present */ |
| 9009 | if (curpeers->peers_fe) |
| 9010 | stop_proxy(curpeers->peers_fe); |
| 9011 | curpeers->peers_fe = NULL; |
| 9012 | } |
| 9013 | else if (!curpeers->peers_fe) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9014 | ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
| 9015 | curpeers->id, localpeer); |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9016 | } |
David Carlier | e6c3941 | 2015-07-02 07:00:17 +0000 | [diff] [blame] | 9017 | else if (my_popcountl(curpeers->peers_fe->bind_proc) != 1) { |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9018 | /* either it's totally stopped or too much used */ |
| 9019 | if (curpeers->peers_fe->bind_proc) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9020 | ha_alert("Peers section '%s': peers referenced by sections " |
| 9021 | "running in different processes (%d different ones). " |
| 9022 | "Check global.nbproc and all tables' bind-process " |
| 9023 | "settings.\n", curpeers->id, my_popcountl(curpeers->peers_fe->bind_proc)); |
Willy Tarreau | 1e27301 | 2015-05-01 19:15:17 +0200 | [diff] [blame] | 9024 | cfgerr++; |
| 9025 | } |
| 9026 | stop_proxy(curpeers->peers_fe); |
| 9027 | curpeers->peers_fe = NULL; |
| 9028 | } |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9029 | else { |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 9030 | peers_init_sync(curpeers); |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9031 | last = &curpeers->next; |
| 9032 | continue; |
| 9033 | } |
| 9034 | |
Willy Tarreau | 77e4bd1 | 2015-05-01 20:02:17 +0200 | [diff] [blame] | 9035 | /* clean what has been detected above */ |
Willy Tarreau | 122541c | 2011-09-07 21:24:49 +0200 | [diff] [blame] | 9036 | p = curpeers->remote; |
| 9037 | while (p) { |
| 9038 | pb = p->next; |
| 9039 | free(p->id); |
| 9040 | free(p); |
| 9041 | p = pb; |
| 9042 | } |
| 9043 | |
| 9044 | /* Destroy and unlink this curpeers section. |
| 9045 | * Note: curpeers is backed up into *last. |
| 9046 | */ |
| 9047 | free(curpeers->id); |
| 9048 | curpeers = curpeers->next; |
| 9049 | free(*last); |
| 9050 | *last = curpeers; |
| 9051 | } |
| 9052 | } |
| 9053 | |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9054 | /* initialize stick-tables on backend capable proxies. This must not |
| 9055 | * be done earlier because the data size may be discovered while parsing |
| 9056 | * other proxies. |
| 9057 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9058 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9059 | if (curproxy->state == PR_STSTOPPED) |
| 9060 | continue; |
| 9061 | |
| 9062 | if (!stktable_init(&curproxy->table)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9063 | ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); |
Willy Tarreau | 6866f3f | 2015-05-01 19:09:08 +0200 | [diff] [blame] | 9064 | cfgerr++; |
| 9065 | } |
| 9066 | } |
| 9067 | |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9068 | if (mailers) { |
| 9069 | struct mailers *curmailers = mailers, **last; |
| 9070 | struct mailer *m, *mb; |
| 9071 | |
| 9072 | /* Remove all mailers sections which don't have a valid listener. |
| 9073 | * This can happen when a mailers section is never referenced. |
| 9074 | */ |
| 9075 | last = &mailers; |
| 9076 | while (*last) { |
| 9077 | curmailers = *last; |
| 9078 | if (curmailers->users) { |
| 9079 | last = &curmailers->next; |
| 9080 | continue; |
| 9081 | } |
| 9082 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9083 | ha_warning("Removing incomplete section 'mailers %s'.\n", |
| 9084 | curmailers->id); |
Simon Horman | 0d16a40 | 2015-01-30 11:22:58 +0900 | [diff] [blame] | 9085 | |
| 9086 | m = curmailers->mailer_list; |
| 9087 | while (m) { |
| 9088 | mb = m->next; |
| 9089 | free(m->id); |
| 9090 | free(m); |
| 9091 | m = mb; |
| 9092 | } |
| 9093 | |
| 9094 | /* Destroy and unlink this curmailers section. |
| 9095 | * Note: curmailers is backed up into *last. |
| 9096 | */ |
| 9097 | free(curmailers->id); |
| 9098 | curmailers = curmailers->next; |
| 9099 | free(*last); |
| 9100 | *last = curmailers; |
| 9101 | } |
| 9102 | } |
| 9103 | |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9104 | /* Update server_state_file_name to backend name if backend is supposed to use |
| 9105 | * a server-state file locally defined and none has been provided */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 9106 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Baptiste Assmann | e11cfcd | 2015-08-19 16:44:03 +0200 | [diff] [blame] | 9107 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
| 9108 | curproxy->server_state_file_name == NULL) |
| 9109 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 9110 | } |
| 9111 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 9112 | pool_head_hdr_idx = create_pool("hdr_idx", |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 9113 | global.tune.max_http_hdr * sizeof(struct hdr_idx_elem), |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 9114 | MEM_F_SHARED); |
| 9115 | |
Ben Draut | 054fbee | 2018-04-13 15:43:04 -0600 | [diff] [blame] | 9116 | list_for_each_entry(curr_resolvers, &dns_resolvers, list) { |
| 9117 | if (LIST_ISEMPTY(&curr_resolvers->nameservers)) { |
| 9118 | ha_warning("config : resolvers '%s' [%s:%d] has no nameservers configured!\n", |
| 9119 | curr_resolvers->id, curr_resolvers->conf.file, |
| 9120 | curr_resolvers->conf.line); |
| 9121 | err_code |= ERR_WARN; |
| 9122 | } |
| 9123 | } |
| 9124 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9125 | list_for_each_entry(postparser, &postparsers, list) { |
| 9126 | if (postparser->func) |
| 9127 | cfgerr += postparser->func(); |
| 9128 | } |
| 9129 | |
Willy Tarreau | bb92501 | 2009-07-23 13:36:36 +0200 | [diff] [blame] | 9130 | if (cfgerr > 0) |
| 9131 | err_code |= ERR_ALERT | ERR_FATAL; |
| 9132 | out: |
| 9133 | return err_code; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9134 | } |
| 9135 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9136 | /* |
| 9137 | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
| 9138 | * parsing sessions. |
| 9139 | */ |
| 9140 | void cfg_register_keywords(struct cfg_kw_list *kwl) |
| 9141 | { |
| 9142 | LIST_ADDQ(&cfg_keywords.list, &kwl->list); |
| 9143 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9144 | |
Willy Tarreau | 5b2c336 | 2008-07-09 19:39:06 +0200 | [diff] [blame] | 9145 | /* |
| 9146 | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
| 9147 | */ |
| 9148 | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
| 9149 | { |
| 9150 | LIST_DEL(&kwl->list); |
| 9151 | LIST_INIT(&kwl->list); |
| 9152 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9153 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9154 | /* this function register new section in the haproxy configuration file. |
| 9155 | * <section_name> is the name of this new section and <section_parser> |
| 9156 | * is the called parser. If two section declaration have the same name, |
| 9157 | * only the first declared is used. |
| 9158 | */ |
| 9159 | int cfg_register_section(char *section_name, |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9160 | int (*section_parser)(const char *, int, char **, int), |
| 9161 | int (*post_section_parser)()) |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9162 | { |
| 9163 | struct cfg_section *cs; |
| 9164 | |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9165 | list_for_each_entry(cs, §ions, list) { |
| 9166 | if (strcmp(cs->section_name, section_name) == 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9167 | ha_alert("register section '%s': already registered.\n", section_name); |
Willy Tarreau | 5e4261b | 2016-05-17 16:16:09 +0200 | [diff] [blame] | 9168 | return 0; |
| 9169 | } |
| 9170 | } |
| 9171 | |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9172 | cs = calloc(1, sizeof(*cs)); |
| 9173 | if (!cs) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9174 | ha_alert("register section '%s': out of memory.\n", section_name); |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9175 | return 0; |
| 9176 | } |
| 9177 | |
| 9178 | cs->section_name = section_name; |
| 9179 | cs->section_parser = section_parser; |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9180 | cs->post_section_parser = post_section_parser; |
Thierry FOURNIER | fa45f1d | 2014-03-18 13:54:18 +0100 | [diff] [blame] | 9181 | |
| 9182 | LIST_ADDQ(§ions, &cs->list); |
| 9183 | |
| 9184 | return 1; |
| 9185 | } |
| 9186 | |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9187 | /* this function register a new function which will be called once the haproxy |
| 9188 | * configuration file has been parsed. It's useful to check dependencies |
| 9189 | * between sections or to resolve items once everything is parsed. |
| 9190 | */ |
| 9191 | int cfg_register_postparser(char *name, int (*func)()) |
| 9192 | { |
| 9193 | struct cfg_postparser *cp; |
| 9194 | |
| 9195 | cp = calloc(1, sizeof(*cp)); |
| 9196 | if (!cp) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 9197 | ha_alert("register postparser '%s': out of memory.\n", name); |
William Lallemand | 48b4bb4 | 2017-10-23 14:36:34 +0200 | [diff] [blame] | 9198 | return 0; |
| 9199 | } |
| 9200 | cp->name = name; |
| 9201 | cp->func = func; |
| 9202 | |
| 9203 | LIST_ADDQ(&postparsers, &cp->list); |
| 9204 | |
| 9205 | return 1; |
| 9206 | } |
| 9207 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9208 | /* |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9209 | * free all config section entries |
| 9210 | */ |
| 9211 | void cfg_unregister_sections(void) |
| 9212 | { |
| 9213 | struct cfg_section *cs, *ics; |
| 9214 | |
| 9215 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9216 | LIST_DEL(&cs->list); |
| 9217 | free(cs); |
| 9218 | } |
| 9219 | } |
| 9220 | |
Christopher Faulet | 7110b40 | 2016-10-26 11:09:44 +0200 | [diff] [blame] | 9221 | void cfg_backup_sections(struct list *backup_sections) |
| 9222 | { |
| 9223 | struct cfg_section *cs, *ics; |
| 9224 | |
| 9225 | list_for_each_entry_safe(cs, ics, §ions, list) { |
| 9226 | LIST_DEL(&cs->list); |
| 9227 | LIST_ADDQ(backup_sections, &cs->list); |
| 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | void cfg_restore_sections(struct list *backup_sections) |
| 9232 | { |
| 9233 | struct cfg_section *cs, *ics; |
| 9234 | |
| 9235 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
| 9236 | LIST_DEL(&cs->list); |
| 9237 | LIST_ADDQ(§ions, &cs->list); |
| 9238 | } |
| 9239 | } |
| 9240 | |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9241 | __attribute__((constructor)) |
| 9242 | static void cfgparse_init(void) |
| 9243 | { |
| 9244 | /* Register internal sections */ |
William Lallemand | d2ff56d | 2017-10-16 11:06:50 +0200 | [diff] [blame] | 9245 | cfg_register_section("listen", cfg_parse_listen, NULL); |
| 9246 | cfg_register_section("frontend", cfg_parse_listen, NULL); |
| 9247 | cfg_register_section("backend", cfg_parse_listen, NULL); |
| 9248 | cfg_register_section("defaults", cfg_parse_listen, NULL); |
| 9249 | cfg_register_section("global", cfg_parse_global, NULL); |
| 9250 | cfg_register_section("userlist", cfg_parse_users, NULL); |
| 9251 | cfg_register_section("peers", cfg_parse_peers, NULL); |
| 9252 | cfg_register_section("mailers", cfg_parse_mailers, NULL); |
| 9253 | cfg_register_section("namespace_list", cfg_parse_netns, NULL); |
| 9254 | cfg_register_section("resolvers", cfg_parse_resolvers, NULL); |
Willy Tarreau | 659fbf0 | 2016-05-26 17:55:28 +0200 | [diff] [blame] | 9255 | } |
| 9256 | |
David Carlier | 845efb5 | 2015-09-25 11:49:18 +0100 | [diff] [blame] | 9257 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 9258 | * Local variables: |
| 9259 | * c-indent-level: 8 |
| 9260 | * c-basic-offset: 8 |
| 9261 | * End: |
| 9262 | */ |