Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Proxy variables and functions. |
| 3 | * |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 4 | * Copyright 2000-2009 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 | |
| 13 | #include <fcntl.h> |
| 14 | #include <unistd.h> |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 15 | #include <string.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 16 | #include <sys/types.h> |
| 17 | #include <sys/socket.h> |
| 18 | #include <sys/stat.h> |
| 19 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 20 | #include <import/eb32tree.h> |
| 21 | #include <import/ebistree.h> |
| 22 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 23 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 24 | #include <haproxy/applet-t.h> |
| 25 | #include <haproxy/capture-t.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 26 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 27 | #include <haproxy/cli.h> |
Willy Tarreau | 8d36697 | 2020-05-27 16:10:29 +0200 | [diff] [blame] | 28 | #include <haproxy/errors.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 29 | #include <haproxy/fd.h> |
Willy Tarreau | c7babd8 | 2020-06-04 21:29:29 +0200 | [diff] [blame] | 30 | #include <haproxy/filters.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 31 | #include <haproxy/global.h> |
Willy Tarreau | c2b1ff0 | 2020-06-04 21:21:03 +0200 | [diff] [blame] | 32 | #include <haproxy/http_ana.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 33 | #include <haproxy/listener.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 34 | #include <haproxy/log.h> |
Willy Tarreau | 8efbdfb | 2020-06-04 11:29:21 +0200 | [diff] [blame] | 35 | #include <haproxy/obj_type-t.h> |
Willy Tarreau | 3c2a7c2 | 2020-06-04 18:38:21 +0200 | [diff] [blame] | 36 | #include <haproxy/peers.h> |
Willy Tarreau | d0ef439 | 2020-06-02 09:38:52 +0200 | [diff] [blame] | 37 | #include <haproxy/pool.h> |
Willy Tarreau | 626f3a7 | 2020-10-07 16:52:43 +0200 | [diff] [blame] | 38 | #include <haproxy/protocol.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/proto_tcp.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 40 | #include <haproxy/proxy.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 41 | #include <haproxy/server-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 42 | #include <haproxy/signal.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 43 | #include <haproxy/stats-t.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 44 | #include <haproxy/stream.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 45 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 46 | #include <haproxy/task.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 47 | #include <haproxy/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 48 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 50 | int listeners; /* # of proxy listeners, set by cfgparse */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 51 | struct proxy *proxies_list = NULL; /* list of all existing proxies */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 52 | struct eb_root used_proxy_id = EB_ROOT; /* list of proxy IDs in use */ |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 53 | struct eb_root proxy_by_name = EB_ROOT; /* tree of proxies sorted by name */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 54 | unsigned int error_snapshot_id = 0; /* global ID assigned to each error then incremented */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 56 | /* proxy->options */ |
| 57 | const struct cfg_opt cfg_opts[] = |
| 58 | { |
| 59 | { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0, 0 }, |
| 60 | { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0, 0 }, |
| 61 | { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 62 | { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0, 0 }, |
| 63 | { "contstats", PR_O_CONTSTATS, PR_CAP_FE, 0, 0 }, |
| 64 | { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0, 0 }, |
| 65 | { "http_proxy", PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 66 | { "http-buffer-request", PR_O_WREQ_BODY, PR_CAP_FE | PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 67 | { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 68 | { "prefer-last-server", PR_O_PREF_LAST, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 69 | { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0, 0 }, |
| 70 | { "nolinger", PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 }, |
| 71 | { "persist", PR_O_PERSIST, PR_CAP_BE, 0, 0 }, |
| 72 | { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 73 | #ifdef USE_TPROXY |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 74 | { "transparent", PR_O_TRANSP, PR_CAP_BE, 0, 0 }, |
| 75 | #else |
| 76 | { "transparent", 0, 0, 0, 0 }, |
| 77 | #endif |
| 78 | |
| 79 | { NULL, 0, 0, 0, 0 } |
| 80 | }; |
| 81 | |
| 82 | /* proxy->options2 */ |
| 83 | const struct cfg_opt cfg_opts2[] = |
| 84 | { |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 85 | #ifdef USE_LINUX_SPLICE |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 86 | { "splice-request", PR_O2_SPLIC_REQ, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 87 | { "splice-response", PR_O2_SPLIC_RTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 88 | { "splice-auto", PR_O2_SPLIC_AUT, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 89 | #else |
| 90 | { "splice-request", 0, 0, 0, 0 }, |
| 91 | { "splice-response", 0, 0, 0, 0 }, |
| 92 | { "splice-auto", 0, 0, 0, 0 }, |
| 93 | #endif |
| 94 | { "accept-invalid-http-request", PR_O2_REQBUG_OK, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 95 | { "accept-invalid-http-response", PR_O2_RSPBUG_OK, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 96 | { "dontlog-normal", PR_O2_NOLOGNORM, PR_CAP_FE, 0, 0 }, |
| 97 | { "log-separate-errors", PR_O2_LOGERRORS, PR_CAP_FE, 0, 0 }, |
| 98 | { "log-health-checks", PR_O2_LOGHCHKS, PR_CAP_BE, 0, 0 }, |
| 99 | { "socket-stats", PR_O2_SOCKSTAT, PR_CAP_FE, 0, 0 }, |
| 100 | { "tcp-smart-accept", PR_O2_SMARTACC, PR_CAP_FE, 0, 0 }, |
| 101 | { "tcp-smart-connect", PR_O2_SMARTCON, PR_CAP_BE, 0, 0 }, |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 102 | { "independent-streams", PR_O2_INDEPSTR, PR_CAP_FE|PR_CAP_BE, 0, 0 }, |
| 103 | { "http-use-proxy-header", PR_O2_USE_PXHDR, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 104 | { "http-pretend-keepalive", PR_O2_FAKE_KA, PR_CAP_BE, 0, PR_MODE_HTTP }, |
| 105 | { "http-no-delay", PR_O2_NODELAY, PR_CAP_FE|PR_CAP_BE, 0, PR_MODE_HTTP }, |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 106 | { "http-use-htx", 0, PR_CAP_FE|PR_CAP_BE, 0, 0 }, // deprecated |
Christopher Faulet | 98fbe95 | 2019-07-22 16:18:24 +0200 | [diff] [blame] | 107 | |
| 108 | {"h1-case-adjust-bogus-client", PR_O2_H1_ADJ_BUGCLI, PR_CAP_FE, 0, PR_MODE_HTTP }, |
| 109 | {"h1-case-adjust-bogus-server", PR_O2_H1_ADJ_BUGSRV, PR_CAP_BE, 0, PR_MODE_HTTP }, |
Christopher Faulet | 89aed32 | 2020-06-02 17:33:56 +0200 | [diff] [blame] | 110 | {"disable-h2-upgrade", PR_O2_NO_H2_UPGRADE, PR_CAP_FE, 0, PR_MODE_HTTP }, |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 111 | { NULL, 0, 0, 0 } |
| 112 | }; |
| 113 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 114 | /* |
Willy Tarreau | 816eb54 | 2007-11-04 07:04:43 +0100 | [diff] [blame] | 115 | * This function returns a string containing a name describing capabilities to |
| 116 | * report comprehensible error messages. Specifically, it will return the words |
Christopher Faulet | 898566e | 2016-10-26 11:06:28 +0200 | [diff] [blame] | 117 | * "frontend", "backend" when appropriate, or "proxy" for all other |
Willy Tarreau | 816eb54 | 2007-11-04 07:04:43 +0100 | [diff] [blame] | 118 | * cases including the proxies declared in "listen" mode. |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 119 | */ |
Willy Tarreau | 816eb54 | 2007-11-04 07:04:43 +0100 | [diff] [blame] | 120 | const char *proxy_cap_str(int cap) |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 121 | { |
Willy Tarreau | 816eb54 | 2007-11-04 07:04:43 +0100 | [diff] [blame] | 122 | if ((cap & PR_CAP_LISTEN) != PR_CAP_LISTEN) { |
| 123 | if (cap & PR_CAP_FE) |
| 124 | return "frontend"; |
| 125 | else if (cap & PR_CAP_BE) |
| 126 | return "backend"; |
Willy Tarreau | 816eb54 | 2007-11-04 07:04:43 +0100 | [diff] [blame] | 127 | } |
| 128 | return "proxy"; |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 131 | /* |
| 132 | * This function returns a string containing the mode of the proxy in a format |
| 133 | * suitable for error messages. |
| 134 | */ |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 135 | const char *proxy_mode_str(int mode) { |
| 136 | |
| 137 | if (mode == PR_MODE_TCP) |
| 138 | return "tcp"; |
| 139 | else if (mode == PR_MODE_HTTP) |
| 140 | return "http"; |
William Lallemand | cf62f7e | 2018-10-26 14:47:40 +0200 | [diff] [blame] | 141 | else if (mode == PR_MODE_CLI) |
| 142 | return "cli"; |
Krzysztof Piotr Oledzki | 6eb730d | 2007-11-03 23:41:58 +0100 | [diff] [blame] | 143 | else |
| 144 | return "unknown"; |
| 145 | } |
| 146 | |
Willy Tarreau | f395017 | 2009-10-10 18:35:51 +0200 | [diff] [blame] | 147 | /* |
| 148 | * This function scans the list of backends and servers to retrieve the first |
| 149 | * backend and the first server with the given names, and sets them in both |
| 150 | * parameters. It returns zero if either is not found, or non-zero and sets |
| 151 | * the ones it did not found to NULL. If a NULL pointer is passed for the |
| 152 | * backend, only the pointer to the server will be updated. |
| 153 | */ |
| 154 | int get_backend_server(const char *bk_name, const char *sv_name, |
| 155 | struct proxy **bk, struct server **sv) |
| 156 | { |
| 157 | struct proxy *p; |
| 158 | struct server *s; |
Willy Tarreau | 7ecc420 | 2014-03-15 07:57:11 +0100 | [diff] [blame] | 159 | int sid; |
Willy Tarreau | f395017 | 2009-10-10 18:35:51 +0200 | [diff] [blame] | 160 | |
| 161 | *sv = NULL; |
| 162 | |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 163 | sid = -1; |
Willy Tarreau | cfeaa47 | 2009-10-10 22:33:08 +0200 | [diff] [blame] | 164 | if (*sv_name == '#') |
| 165 | sid = atoi(sv_name + 1); |
| 166 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 167 | p = proxy_be_by_name(bk_name); |
Willy Tarreau | f395017 | 2009-10-10 18:35:51 +0200 | [diff] [blame] | 168 | if (bk) |
| 169 | *bk = p; |
| 170 | if (!p) |
| 171 | return 0; |
| 172 | |
| 173 | for (s = p->srv; s; s = s->next) |
Willy Tarreau | 4055a10 | 2012-11-15 00:15:18 +0100 | [diff] [blame] | 174 | if ((sid >= 0 && s->puid == sid) || |
| 175 | (sid < 0 && strcmp(s->id, sv_name) == 0)) |
Willy Tarreau | f395017 | 2009-10-10 18:35:51 +0200 | [diff] [blame] | 176 | break; |
| 177 | *sv = s; |
| 178 | if (!s) |
| 179 | return 0; |
| 180 | return 1; |
| 181 | } |
| 182 | |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 183 | /* This function parses a "timeout" statement in a proxy section. It returns |
| 184 | * -1 if there is any error, 1 for a warning, otherwise zero. If it does not |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 185 | * return zero, it will write an error or warning message into a preallocated |
| 186 | * buffer returned at <err>. The trailing is not be written. The function must |
| 187 | * be called with <args> pointing to the first command line word, with <proxy> |
| 188 | * pointing to the proxy being parsed, and <defpx> to the default proxy or NULL. |
| 189 | * As a special case for compatibility with older configs, it also accepts |
| 190 | * "{cli|srv|con}timeout" in args[0]. |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 191 | */ |
Willy Tarreau | 9de1bbd | 2008-07-09 20:34:27 +0200 | [diff] [blame] | 192 | static int proxy_parse_timeout(char **args, int section, struct proxy *proxy, |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 193 | struct proxy *defpx, const char *file, int line, |
| 194 | char **err) |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 195 | { |
| 196 | unsigned timeout; |
| 197 | int retval, cap; |
| 198 | const char *res, *name; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 199 | int *tv = NULL; |
| 200 | int *td = NULL; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 201 | |
| 202 | retval = 0; |
Willy Tarreau | 9de1bbd | 2008-07-09 20:34:27 +0200 | [diff] [blame] | 203 | |
| 204 | /* simply skip "timeout" but remain compatible with old form */ |
| 205 | if (strcmp(args[0], "timeout") == 0) |
| 206 | args++; |
| 207 | |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 208 | name = args[0]; |
Tim Duesterhus | 86e6b6e | 2019-05-14 20:57:59 +0200 | [diff] [blame] | 209 | if (!strcmp(args[0], "client")) { |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 210 | name = "client"; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 211 | tv = &proxy->timeout.client; |
| 212 | td = &defpx->timeout.client; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 213 | cap = PR_CAP_FE; |
| 214 | } else if (!strcmp(args[0], "tarpit")) { |
| 215 | tv = &proxy->timeout.tarpit; |
| 216 | td = &defpx->timeout.tarpit; |
Willy Tarreau | 51c9bde | 2008-01-06 13:40:03 +0100 | [diff] [blame] | 217 | cap = PR_CAP_FE | PR_CAP_BE; |
Willy Tarreau | b16a574 | 2010-01-10 14:46:16 +0100 | [diff] [blame] | 218 | } else if (!strcmp(args[0], "http-keep-alive")) { |
| 219 | tv = &proxy->timeout.httpka; |
| 220 | td = &defpx->timeout.httpka; |
| 221 | cap = PR_CAP_FE | PR_CAP_BE; |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame] | 222 | } else if (!strcmp(args[0], "http-request")) { |
| 223 | tv = &proxy->timeout.httpreq; |
| 224 | td = &defpx->timeout.httpreq; |
Willy Tarreau | cd7afc0 | 2009-07-12 10:03:17 +0200 | [diff] [blame] | 225 | cap = PR_CAP_FE | PR_CAP_BE; |
Tim Duesterhus | 86e6b6e | 2019-05-14 20:57:59 +0200 | [diff] [blame] | 226 | } else if (!strcmp(args[0], "server")) { |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 227 | name = "server"; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 228 | tv = &proxy->timeout.server; |
| 229 | td = &defpx->timeout.server; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 230 | cap = PR_CAP_BE; |
Tim Duesterhus | 86e6b6e | 2019-05-14 20:57:59 +0200 | [diff] [blame] | 231 | } else if (!strcmp(args[0], "connect")) { |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 232 | name = "connect"; |
Willy Tarreau | d7c30f9 | 2007-12-03 01:38:36 +0100 | [diff] [blame] | 233 | tv = &proxy->timeout.connect; |
| 234 | td = &defpx->timeout.connect; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 235 | cap = PR_CAP_BE; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 236 | } else if (!strcmp(args[0], "check")) { |
| 237 | tv = &proxy->timeout.check; |
| 238 | td = &defpx->timeout.check; |
| 239 | cap = PR_CAP_BE; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 240 | } else if (!strcmp(args[0], "queue")) { |
| 241 | tv = &proxy->timeout.queue; |
| 242 | td = &defpx->timeout.queue; |
| 243 | cap = PR_CAP_BE; |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 244 | } else if (!strcmp(args[0], "tunnel")) { |
| 245 | tv = &proxy->timeout.tunnel; |
| 246 | td = &defpx->timeout.tunnel; |
| 247 | cap = PR_CAP_BE; |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 248 | } else if (!strcmp(args[0], "client-fin")) { |
| 249 | tv = &proxy->timeout.clientfin; |
| 250 | td = &defpx->timeout.clientfin; |
| 251 | cap = PR_CAP_FE; |
| 252 | } else if (!strcmp(args[0], "server-fin")) { |
| 253 | tv = &proxy->timeout.serverfin; |
| 254 | td = &defpx->timeout.serverfin; |
| 255 | cap = PR_CAP_BE; |
Tim Duesterhus | 86e6b6e | 2019-05-14 20:57:59 +0200 | [diff] [blame] | 256 | } else if (!strcmp(args[0], "clitimeout")) { |
| 257 | memprintf(err, "the '%s' directive is not supported anymore since HAProxy 2.1. Use 'timeout client'.", args[0]); |
| 258 | return -1; |
| 259 | } else if (!strcmp(args[0], "srvtimeout")) { |
| 260 | memprintf(err, "the '%s' directive is not supported anymore since HAProxy 2.1. Use 'timeout server'.", args[0]); |
| 261 | return -1; |
| 262 | } else if (!strcmp(args[0], "contimeout")) { |
| 263 | memprintf(err, "the '%s' directive is not supported anymore since HAProxy 2.1. Use 'timeout connect'.", args[0]); |
| 264 | return -1; |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 265 | } else { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 266 | memprintf(err, |
| 267 | "'timeout' supports 'client', 'server', 'connect', 'check', " |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 268 | "'queue', 'http-keep-alive', 'http-request', 'tunnel', 'tarpit', " |
| 269 | "'client-fin' and 'server-fin' (got '%s')", |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 270 | args[0]); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | if (*args[1] == 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 275 | memprintf(err, "'timeout %s' expects an integer value (in milliseconds)", name); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 280 | if (res == PARSE_TIME_OVER) { |
| 281 | memprintf(err, "timer overflow in argument '%s' to 'timeout %s' (maximum value is 2147483647 ms or ~24.8 days)", |
| 282 | args[1], name); |
| 283 | return -1; |
| 284 | } |
| 285 | else if (res == PARSE_TIME_UNDER) { |
| 286 | memprintf(err, "timer underflow in argument '%s' to 'timeout %s' (minimum non-null value is 1 ms)", |
| 287 | args[1], name); |
| 288 | return -1; |
| 289 | } |
| 290 | else if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 291 | memprintf(err, "unexpected character '%c' in 'timeout %s'", *res, name); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | if (!(proxy->cap & cap)) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 296 | memprintf(err, "'timeout %s' will be ignored because %s '%s' has no %s capability", |
| 297 | name, proxy_type_str(proxy), proxy->id, |
| 298 | (cap & PR_CAP_BE) ? "backend" : "frontend"); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 299 | retval = 1; |
| 300 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 301 | else if (defpx && *tv != *td) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 302 | memprintf(err, "overwriting 'timeout %s' which was already specified", name); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 303 | retval = 1; |
| 304 | } |
| 305 | |
Willy Tarreau | fac5b59 | 2014-05-22 08:24:46 +0200 | [diff] [blame] | 306 | if (*args[2] != 0) { |
| 307 | memprintf(err, "'timeout %s' : unexpected extra argument '%s' after value '%s'.", name, args[2], args[1]); |
| 308 | retval = -1; |
| 309 | } |
| 310 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 311 | *tv = MS_TO_TICKS(timeout); |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 312 | return retval; |
| 313 | } |
| 314 | |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 315 | /* This function parses a "rate-limit" statement in a proxy section. It returns |
| 316 | * -1 if there is any error, 1 for a warning, otherwise zero. If it does not |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 317 | * return zero, it will write an error or warning message into a preallocated |
| 318 | * buffer returned at <err>. The function must be called with <args> pointing |
| 319 | * to the first command line word, with <proxy> pointing to the proxy being |
| 320 | * parsed, and <defpx> to the default proxy or NULL. |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 321 | */ |
| 322 | static int proxy_parse_rate_limit(char **args, int section, struct proxy *proxy, |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 323 | struct proxy *defpx, const char *file, int line, |
| 324 | char **err) |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 325 | { |
William Dauchy | bb9da0b | 2020-01-16 01:34:27 +0100 | [diff] [blame] | 326 | int retval; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 327 | char *res; |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 328 | unsigned int *tv = NULL; |
| 329 | unsigned int *td = NULL; |
| 330 | unsigned int val; |
| 331 | |
| 332 | retval = 0; |
| 333 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 334 | if (strcmp(args[1], "sessions") == 0) { |
Willy Tarreau | 13a34bd | 2009-05-10 18:52:49 +0200 | [diff] [blame] | 335 | tv = &proxy->fe_sps_lim; |
| 336 | td = &defpx->fe_sps_lim; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 337 | } |
| 338 | else { |
| 339 | memprintf(err, "'%s' only supports 'sessions' (got '%s')", args[0], args[1]); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 340 | return -1; |
| 341 | } |
| 342 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 343 | if (*args[2] == 0) { |
| 344 | memprintf(err, "'%s %s' expects expects an integer value (in sessions/second)", args[0], args[1]); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 345 | return -1; |
| 346 | } |
| 347 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 348 | val = strtoul(args[2], &res, 0); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 349 | if (*res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 350 | memprintf(err, "'%s %s' : unexpected character '%c' in integer value '%s'", args[0], args[1], *res, args[2]); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 351 | return -1; |
| 352 | } |
| 353 | |
William Dauchy | bb9da0b | 2020-01-16 01:34:27 +0100 | [diff] [blame] | 354 | if (!(proxy->cap & PR_CAP_FE)) { |
| 355 | memprintf(err, "%s %s will be ignored because %s '%s' has no frontend capability", |
| 356 | args[0], args[1], proxy_type_str(proxy), proxy->id); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 357 | retval = 1; |
| 358 | } |
| 359 | else if (defpx && *tv != *td) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 360 | memprintf(err, "overwriting %s %s which was already specified", args[0], args[1]); |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 361 | retval = 1; |
| 362 | } |
| 363 | |
| 364 | *tv = val; |
| 365 | return retval; |
| 366 | } |
| 367 | |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 368 | /* This function parses a "max-keep-alive-queue" statement in a proxy section. |
| 369 | * It returns -1 if there is any error, 1 for a warning, otherwise zero. If it |
| 370 | * does not return zero, it will write an error or warning message into a |
| 371 | * preallocated buffer returned at <err>. The function must be called with |
| 372 | * <args> pointing to the first command line word, with <proxy> pointing to |
| 373 | * the proxy being parsed, and <defpx> to the default proxy or NULL. |
| 374 | */ |
| 375 | static int proxy_parse_max_ka_queue(char **args, int section, struct proxy *proxy, |
| 376 | struct proxy *defpx, const char *file, int line, |
| 377 | char **err) |
| 378 | { |
| 379 | int retval; |
| 380 | char *res; |
| 381 | unsigned int val; |
| 382 | |
| 383 | retval = 0; |
| 384 | |
| 385 | if (*args[1] == 0) { |
| 386 | memprintf(err, "'%s' expects expects an integer value (or -1 to disable)", args[0]); |
| 387 | return -1; |
| 388 | } |
| 389 | |
| 390 | val = strtol(args[1], &res, 0); |
| 391 | if (*res) { |
| 392 | memprintf(err, "'%s' : unexpected character '%c' in integer value '%s'", args[0], *res, args[1]); |
| 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | if (!(proxy->cap & PR_CAP_BE)) { |
| 397 | memprintf(err, "%s will be ignored because %s '%s' has no backend capability", |
| 398 | args[0], proxy_type_str(proxy), proxy->id); |
| 399 | retval = 1; |
| 400 | } |
| 401 | |
| 402 | /* we store <val+1> so that a user-facing value of -1 is stored as zero (default) */ |
| 403 | proxy->max_ka_queue = val + 1; |
| 404 | return retval; |
| 405 | } |
| 406 | |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 407 | /* This function parses a "declare" statement in a proxy section. It returns -1 |
| 408 | * if there is any error, 1 for warning, otherwise 0. If it does not return zero, |
| 409 | * it will write an error or warning message into a preallocated buffer returned |
| 410 | * at <err>. The function must be called with <args> pointing to the first command |
| 411 | * line word, with <proxy> pointing to the proxy being parsed, and <defpx> to the |
| 412 | * default proxy or NULL. |
| 413 | */ |
| 414 | static int proxy_parse_declare(char **args, int section, struct proxy *curpx, |
| 415 | struct proxy *defpx, const char *file, int line, |
| 416 | char **err) |
| 417 | { |
| 418 | /* Capture keyword wannot be declared in a default proxy. */ |
| 419 | if (curpx == defpx) { |
Joseph Herlant | 9edebb8 | 2018-11-15 11:50:44 -0800 | [diff] [blame] | 420 | memprintf(err, "'%s' not available in default section", args[0]); |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 421 | return -1; |
| 422 | } |
| 423 | |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 424 | /* Capture keywork is only available in frontend. */ |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 425 | if (!(curpx->cap & PR_CAP_FE)) { |
Joseph Herlant | 9edebb8 | 2018-11-15 11:50:44 -0800 | [diff] [blame] | 426 | memprintf(err, "'%s' only available in frontend or listen section", args[0]); |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 427 | return -1; |
| 428 | } |
| 429 | |
| 430 | /* Check mandatory second keyword. */ |
| 431 | if (!args[1] || !*args[1]) { |
| 432 | memprintf(err, "'%s' needs a second keyword that specify the type of declaration ('capture')", args[0]); |
| 433 | return -1; |
| 434 | } |
| 435 | |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 436 | /* Actually, declare is only available for declaring capture |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 437 | * slot, but in the future it can declare maps or variables. |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 438 | * So, this section permits to check and switch according with |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 439 | * the second keyword. |
| 440 | */ |
| 441 | if (strcmp(args[1], "capture") == 0) { |
| 442 | char *error = NULL; |
| 443 | long len; |
| 444 | struct cap_hdr *hdr; |
| 445 | |
| 446 | /* Check the next keyword. */ |
| 447 | if (!args[2] || !*args[2] || |
| 448 | (strcmp(args[2], "response") != 0 && |
| 449 | strcmp(args[2], "request") != 0)) { |
| 450 | memprintf(err, "'%s %s' requires a direction ('request' or 'response')", args[0], args[1]); |
| 451 | return -1; |
| 452 | } |
| 453 | |
| 454 | /* Check the 'len' keyword. */ |
| 455 | if (!args[3] || !*args[3] || strcmp(args[3], "len") != 0) { |
| 456 | memprintf(err, "'%s %s' requires a capture length ('len')", args[0], args[1]); |
| 457 | return -1; |
| 458 | } |
| 459 | |
| 460 | /* Check the length value. */ |
| 461 | if (!args[4] || !*args[4]) { |
| 462 | memprintf(err, "'%s %s': 'len' requires a numeric value that represents the " |
| 463 | "capture length", |
| 464 | args[0], args[1]); |
| 465 | return -1; |
| 466 | } |
| 467 | |
| 468 | /* convert the length value. */ |
| 469 | len = strtol(args[4], &error, 10); |
| 470 | if (*error != '\0') { |
| 471 | memprintf(err, "'%s %s': cannot parse the length '%s'.", |
| 472 | args[0], args[1], args[3]); |
| 473 | return -1; |
| 474 | } |
| 475 | |
| 476 | /* check length. */ |
| 477 | if (len <= 0) { |
| 478 | memprintf(err, "length must be > 0"); |
| 479 | return -1; |
| 480 | } |
| 481 | |
| 482 | /* register the capture. */ |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 483 | hdr = calloc(1, sizeof(*hdr)); |
Remi Tricot-Le Breton | 978b2d4 | 2021-05-12 18:04:46 +0200 | [diff] [blame] | 484 | if (!hdr) { |
| 485 | memprintf(err, "proxy '%s': out of memory while registering a capture", curpx->id); |
| 486 | return -1; |
| 487 | } |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 488 | hdr->name = NULL; /* not a header capture */ |
| 489 | hdr->namelen = 0; |
| 490 | hdr->len = len; |
| 491 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 492 | |
| 493 | if (strcmp(args[2], "request") == 0) { |
| 494 | hdr->next = curpx->req_cap; |
| 495 | hdr->index = curpx->nb_req_cap++; |
| 496 | curpx->req_cap = hdr; |
| 497 | } |
| 498 | if (strcmp(args[2], "response") == 0) { |
| 499 | hdr->next = curpx->rsp_cap; |
| 500 | hdr->index = curpx->nb_rsp_cap++; |
| 501 | curpx->rsp_cap = hdr; |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | else { |
| 506 | memprintf(err, "unknown declaration type '%s' (supports 'capture')", args[1]); |
| 507 | return -1; |
| 508 | } |
| 509 | } |
| 510 | |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 511 | /* This function parses a "retry-on" statement */ |
| 512 | static int |
| 513 | proxy_parse_retry_on(char **args, int section, struct proxy *curpx, |
| 514 | struct proxy *defpx, const char *file, int line, |
| 515 | char **err) |
| 516 | { |
| 517 | int i; |
| 518 | |
| 519 | if (!(*args[1])) { |
| 520 | memprintf(err, "'%s' needs at least one keyword to specify when to retry", args[0]); |
| 521 | return -1; |
| 522 | } |
| 523 | if (!(curpx->cap & PR_CAP_BE)) { |
| 524 | memprintf(err, "'%s' only available in backend or listen section", args[0]); |
| 525 | return -1; |
| 526 | } |
| 527 | curpx->retry_type = 0; |
| 528 | for (i = 1; *(args[i]); i++) { |
| 529 | if (!strcmp(args[i], "conn-failure")) |
| 530 | curpx->retry_type |= PR_RE_CONN_FAILED; |
| 531 | else if (!strcmp(args[i], "empty-response")) |
| 532 | curpx->retry_type |= PR_RE_DISCONNECTED; |
| 533 | else if (!strcmp(args[i], "response-timeout")) |
| 534 | curpx->retry_type |= PR_RE_TIMEOUT; |
| 535 | else if (!strcmp(args[i], "404")) |
| 536 | curpx->retry_type |= PR_RE_404; |
| 537 | else if (!strcmp(args[i], "408")) |
| 538 | curpx->retry_type |= PR_RE_408; |
| 539 | else if (!strcmp(args[i], "425")) |
| 540 | curpx->retry_type |= PR_RE_425; |
| 541 | else if (!strcmp(args[i], "500")) |
| 542 | curpx->retry_type |= PR_RE_500; |
| 543 | else if (!strcmp(args[i], "501")) |
| 544 | curpx->retry_type |= PR_RE_501; |
| 545 | else if (!strcmp(args[i], "502")) |
| 546 | curpx->retry_type |= PR_RE_502; |
| 547 | else if (!strcmp(args[i], "503")) |
| 548 | curpx->retry_type |= PR_RE_503; |
| 549 | else if (!strcmp(args[i], "504")) |
| 550 | curpx->retry_type |= PR_RE_504; |
Olivier Houchard | 865d839 | 2019-05-03 22:46:27 +0200 | [diff] [blame] | 551 | else if (!strcmp(args[i], "0rtt-rejected")) |
| 552 | curpx->retry_type |= PR_RE_EARLY_ERROR; |
Olivier Houchard | e3249a9 | 2019-05-03 23:01:47 +0200 | [diff] [blame] | 553 | else if (!strcmp(args[i], "junk-response")) |
| 554 | curpx->retry_type |= PR_RE_JUNK_REQUEST; |
Olivier Houchard | ddf0e03 | 2019-05-10 18:05:40 +0200 | [diff] [blame] | 555 | else if (!(strcmp(args[i], "all-retryable-errors"))) |
| 556 | curpx->retry_type |= PR_RE_CONN_FAILED | PR_RE_DISCONNECTED | |
| 557 | PR_RE_TIMEOUT | PR_RE_500 | PR_RE_502 | |
| 558 | PR_RE_503 | PR_RE_504 | PR_RE_EARLY_ERROR | |
| 559 | PR_RE_JUNK_REQUEST; |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 560 | else if (!strcmp(args[i], "none")) { |
| 561 | if (i != 1 || *args[i + 1]) { |
| 562 | memprintf(err, "'%s' 'none' keyworld only usable alone", args[0]); |
| 563 | return -1; |
| 564 | } |
| 565 | } else { |
| 566 | memprintf(err, "'%s': unknown keyword '%s'", args[0], args[i]); |
| 567 | return -1; |
| 568 | } |
| 569 | |
| 570 | } |
| 571 | |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 576 | #ifdef TCP_KEEPCNT |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 577 | /* This function parses "{cli|srv}tcpka-cnt" statements */ |
| 578 | static int proxy_parse_tcpka_cnt(char **args, int section, struct proxy *proxy, |
| 579 | struct proxy *defpx, const char *file, int line, |
| 580 | char **err) |
| 581 | { |
| 582 | int retval; |
| 583 | char *res; |
| 584 | unsigned int tcpka_cnt; |
| 585 | |
| 586 | retval = 0; |
| 587 | |
| 588 | if (*args[1] == 0) { |
| 589 | memprintf(err, "'%s' expects an integer value", args[0]); |
| 590 | return -1; |
| 591 | } |
| 592 | |
| 593 | tcpka_cnt = strtol(args[1], &res, 0); |
| 594 | if (*res) { |
| 595 | memprintf(err, "'%s' : unexpected character '%c' in integer value '%s'", args[0], *res, args[1]); |
| 596 | return -1; |
| 597 | } |
| 598 | |
| 599 | if (!strcmp(args[0], "clitcpka-cnt")) { |
| 600 | if (!(proxy->cap & PR_CAP_FE)) { |
| 601 | memprintf(err, "%s will be ignored because %s '%s' has no frontend capability", |
| 602 | args[0], proxy_type_str(proxy), proxy->id); |
| 603 | retval = 1; |
| 604 | } |
| 605 | proxy->clitcpka_cnt = tcpka_cnt; |
| 606 | } else if (!strcmp(args[0], "srvtcpka-cnt")) { |
| 607 | if (!(proxy->cap & PR_CAP_BE)) { |
| 608 | memprintf(err, "%s will be ignored because %s '%s' has no backend capability", |
| 609 | args[0], proxy_type_str(proxy), proxy->id); |
| 610 | retval = 1; |
| 611 | } |
| 612 | proxy->srvtcpka_cnt = tcpka_cnt; |
| 613 | } else { |
| 614 | /* unreachable */ |
| 615 | memprintf(err, "'%s': unknown keyword", args[0]); |
| 616 | return -1; |
| 617 | } |
| 618 | |
| 619 | return retval; |
| 620 | } |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 621 | #endif |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 622 | |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 623 | #ifdef TCP_KEEPIDLE |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 624 | /* This function parses "{cli|srv}tcpka-idle" statements */ |
| 625 | static int proxy_parse_tcpka_idle(char **args, int section, struct proxy *proxy, |
| 626 | struct proxy *defpx, const char *file, int line, |
| 627 | char **err) |
| 628 | { |
| 629 | int retval; |
| 630 | const char *res; |
| 631 | unsigned int tcpka_idle; |
| 632 | |
| 633 | retval = 0; |
| 634 | |
| 635 | if (*args[1] == 0) { |
| 636 | memprintf(err, "'%s' expects an integer value", args[0]); |
| 637 | return -1; |
| 638 | } |
| 639 | res = parse_time_err(args[1], &tcpka_idle, TIME_UNIT_S); |
| 640 | if (res == PARSE_TIME_OVER) { |
| 641 | memprintf(err, "timer overflow in argument '%s' to '%s' (maximum value is 2147483647 ms or ~24.8 days)", |
| 642 | args[1], args[0]); |
| 643 | return -1; |
| 644 | } |
| 645 | else if (res == PARSE_TIME_UNDER) { |
| 646 | memprintf(err, "timer underflow in argument '%s' to '%s' (minimum non-null value is 1 ms)", |
| 647 | args[1], args[0]); |
| 648 | return -1; |
| 649 | } |
| 650 | else if (res) { |
| 651 | memprintf(err, "unexpected character '%c' in argument to <%s>.\n", *res, args[0]); |
| 652 | return -1; |
| 653 | } |
| 654 | |
| 655 | if (!strcmp(args[0], "clitcpka-idle")) { |
| 656 | if (!(proxy->cap & PR_CAP_FE)) { |
| 657 | memprintf(err, "%s will be ignored because %s '%s' has no frontend capability", |
| 658 | args[0], proxy_type_str(proxy), proxy->id); |
| 659 | retval = 1; |
| 660 | } |
| 661 | proxy->clitcpka_idle = tcpka_idle; |
| 662 | } else if (!strcmp(args[0], "srvtcpka-idle")) { |
| 663 | if (!(proxy->cap & PR_CAP_BE)) { |
| 664 | memprintf(err, "%s will be ignored because %s '%s' has no backend capability", |
| 665 | args[0], proxy_type_str(proxy), proxy->id); |
| 666 | retval = 1; |
| 667 | } |
| 668 | proxy->srvtcpka_idle = tcpka_idle; |
| 669 | } else { |
| 670 | /* unreachable */ |
| 671 | memprintf(err, "'%s': unknown keyword", args[0]); |
| 672 | return -1; |
| 673 | } |
| 674 | |
| 675 | return retval; |
| 676 | } |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 677 | #endif |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 678 | |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 679 | #ifdef TCP_KEEPINTVL |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 680 | /* This function parses "{cli|srv}tcpka-intvl" statements */ |
| 681 | static int proxy_parse_tcpka_intvl(char **args, int section, struct proxy *proxy, |
| 682 | struct proxy *defpx, const char *file, int line, |
| 683 | char **err) |
| 684 | { |
| 685 | int retval; |
| 686 | const char *res; |
| 687 | unsigned int tcpka_intvl; |
| 688 | |
| 689 | retval = 0; |
| 690 | |
| 691 | if (*args[1] == 0) { |
| 692 | memprintf(err, "'%s' expects an integer value", args[0]); |
| 693 | return -1; |
| 694 | } |
| 695 | res = parse_time_err(args[1], &tcpka_intvl, TIME_UNIT_S); |
| 696 | if (res == PARSE_TIME_OVER) { |
| 697 | memprintf(err, "timer overflow in argument '%s' to '%s' (maximum value is 2147483647 ms or ~24.8 days)", |
| 698 | args[1], args[0]); |
| 699 | return -1; |
| 700 | } |
| 701 | else if (res == PARSE_TIME_UNDER) { |
| 702 | memprintf(err, "timer underflow in argument '%s' to '%s' (minimum non-null value is 1 ms)", |
| 703 | args[1], args[0]); |
| 704 | return -1; |
| 705 | } |
| 706 | else if (res) { |
| 707 | memprintf(err, "unexpected character '%c' in argument to <%s>.\n", *res, args[0]); |
| 708 | return -1; |
| 709 | } |
| 710 | |
| 711 | if (!strcmp(args[0], "clitcpka-intvl")) { |
| 712 | if (!(proxy->cap & PR_CAP_FE)) { |
| 713 | memprintf(err, "%s will be ignored because %s '%s' has no frontend capability", |
| 714 | args[0], proxy_type_str(proxy), proxy->id); |
| 715 | retval = 1; |
| 716 | } |
| 717 | proxy->clitcpka_intvl = tcpka_intvl; |
| 718 | } else if (!strcmp(args[0], "srvtcpka-intvl")) { |
| 719 | if (!(proxy->cap & PR_CAP_BE)) { |
| 720 | memprintf(err, "%s will be ignored because %s '%s' has no backend capability", |
| 721 | args[0], proxy_type_str(proxy), proxy->id); |
| 722 | retval = 1; |
| 723 | } |
| 724 | proxy->srvtcpka_intvl = tcpka_intvl; |
| 725 | } else { |
| 726 | /* unreachable */ |
| 727 | memprintf(err, "'%s': unknown keyword", args[0]); |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | return retval; |
| 732 | } |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 733 | #endif |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 734 | |
Willy Tarreau | f79d950 | 2014-03-15 07:22:35 +0100 | [diff] [blame] | 735 | /* This function inserts proxy <px> into the tree of known proxies. The proxy's |
| 736 | * name is used as the storing key so it must already have been initialized. |
| 737 | */ |
| 738 | void proxy_store_name(struct proxy *px) |
| 739 | { |
| 740 | px->conf.by_name.key = px->id; |
| 741 | ebis_insert(&proxy_by_name, &px->conf.by_name); |
| 742 | } |
| 743 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 744 | /* Returns a pointer to the first proxy matching capabilities <cap> and id |
| 745 | * <id>. NULL is returned if no match is found. If <table> is non-zero, it |
| 746 | * only considers proxies having a table. |
Willy Tarreau | bc216c4 | 2011-08-02 11:25:54 +0200 | [diff] [blame] | 747 | */ |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 748 | struct proxy *proxy_find_by_id(int id, int cap, int table) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 749 | { |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 750 | struct eb32_node *n; |
Willy Tarreau | bc216c4 | 2011-08-02 11:25:54 +0200 | [diff] [blame] | 751 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 752 | for (n = eb32_lookup(&used_proxy_id, id); n; n = eb32_next(n)) { |
| 753 | struct proxy *px = container_of(n, struct proxy, conf.id); |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 754 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 755 | if (px->uuid != id) |
| 756 | break; |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 757 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 758 | if ((px->cap & cap) != cap) |
| 759 | continue; |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 760 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 761 | if (table && (!px->table || !px->table->size)) |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 762 | continue; |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 763 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 764 | return px; |
| 765 | } |
| 766 | return NULL; |
| 767 | } |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 768 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 769 | /* Returns a pointer to the first proxy matching either name <name>, or id |
| 770 | * <name> if <name> begins with a '#'. NULL is returned if no match is found. |
| 771 | * If <table> is non-zero, it only considers proxies having a table. |
| 772 | */ |
| 773 | struct proxy *proxy_find_by_name(const char *name, int cap, int table) |
| 774 | { |
| 775 | struct proxy *curproxy; |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 776 | |
Willy Tarreau | 3c56a7d | 2015-05-26 15:25:32 +0200 | [diff] [blame] | 777 | if (*name == '#') { |
| 778 | curproxy = proxy_find_by_id(atoi(name + 1), cap, table); |
| 779 | if (curproxy) |
Willy Tarreau | c739aa8 | 2015-05-26 11:35:41 +0200 | [diff] [blame] | 780 | return curproxy; |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 781 | } |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 782 | else { |
| 783 | struct ebpt_node *node; |
| 784 | |
| 785 | for (node = ebis_lookup(&proxy_by_name, name); node; node = ebpt_next(node)) { |
| 786 | curproxy = container_of(node, struct proxy, conf.by_name); |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 787 | |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 788 | if (strcmp(curproxy->id, name) != 0) |
| 789 | break; |
| 790 | |
| 791 | if ((curproxy->cap & cap) != cap) |
| 792 | continue; |
| 793 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 794 | if (table && (!curproxy->table || !curproxy->table->size)) |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 795 | continue; |
| 796 | |
Willy Tarreau | c739aa8 | 2015-05-26 11:35:41 +0200 | [diff] [blame] | 797 | return curproxy; |
Willy Tarreau | cfd837f | 2014-03-15 07:43:51 +0100 | [diff] [blame] | 798 | } |
| 799 | } |
Willy Tarreau | c739aa8 | 2015-05-26 11:35:41 +0200 | [diff] [blame] | 800 | return NULL; |
Alex Williams | 96532db | 2009-11-01 21:27:13 -0500 | [diff] [blame] | 801 | } |
| 802 | |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 803 | /* Finds the best match for a proxy with capabilities <cap>, name <name> and id |
| 804 | * <id>. At most one of <id> or <name> may be different provided that <cap> is |
| 805 | * valid. Either <id> or <name> may be left unspecified (0). The purpose is to |
| 806 | * find a proxy based on some information from a previous configuration, across |
| 807 | * reloads or during information exchange between peers. |
| 808 | * |
| 809 | * Names are looked up first if present, then IDs are compared if present. In |
| 810 | * case of an inexact match whatever is forced in the configuration has |
| 811 | * precedence in the following order : |
| 812 | * - 1) forced ID (proves a renaming / change of proxy type) |
| 813 | * - 2) proxy name+type (may indicate a move if ID differs) |
| 814 | * - 3) automatic ID+type (may indicate a renaming) |
| 815 | * |
| 816 | * Depending on what is found, we can end up in the following situations : |
| 817 | * |
| 818 | * name id cap | possible causes |
| 819 | * -------------+----------------- |
| 820 | * -- -- -- | nothing found |
| 821 | * -- -- ok | nothing found |
| 822 | * -- ok -- | proxy deleted, ID points to next one |
| 823 | * -- ok ok | proxy renamed, or deleted with ID pointing to next one |
| 824 | * ok -- -- | proxy deleted, but other half with same name still here (before) |
| 825 | * ok -- ok | proxy's ID changed (proxy moved in the config file) |
| 826 | * ok ok -- | proxy deleted, but other half with same name still here (after) |
| 827 | * ok ok ok | perfect match |
| 828 | * |
| 829 | * Upon return if <diff> is not NULL, it is zeroed then filled with up to 3 bits : |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 830 | * - PR_FBM_MISMATCH_ID : proxy was found but ID differs |
| 831 | * (and ID was not zero) |
| 832 | * - PR_FBM_MISMATCH_NAME : proxy was found by ID but name differs |
| 833 | * (and name was not NULL) |
| 834 | * - PR_FBM_MISMATCH_PROXYTYPE : a proxy of different type was found with |
| 835 | * the same name and/or id |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 836 | * |
| 837 | * Only a valid proxy is returned. If capabilities do not match, NULL is |
| 838 | * returned. The caller can check <diff> to report detailed warnings / errors, |
| 839 | * and decide whether or not to use what was found. |
| 840 | */ |
| 841 | struct proxy *proxy_find_best_match(int cap, const char *name, int id, int *diff) |
| 842 | { |
| 843 | struct proxy *byname; |
| 844 | struct proxy *byid; |
| 845 | |
| 846 | if (!name && !id) |
| 847 | return NULL; |
| 848 | |
| 849 | if (diff) |
| 850 | *diff = 0; |
| 851 | |
| 852 | byname = byid = NULL; |
| 853 | |
| 854 | if (name) { |
| 855 | byname = proxy_find_by_name(name, cap, 0); |
| 856 | if (byname && (!id || byname->uuid == id)) |
| 857 | return byname; |
| 858 | } |
| 859 | |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 860 | /* remaining possibilities : |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 861 | * - name not set |
| 862 | * - name set but not found |
| 863 | * - name found, but ID doesn't match. |
| 864 | */ |
| 865 | if (id) { |
| 866 | byid = proxy_find_by_id(id, cap, 0); |
| 867 | if (byid) { |
| 868 | if (byname) { |
| 869 | /* id+type found, name+type found, but not all 3. |
| 870 | * ID wins only if forced, otherwise name wins. |
| 871 | */ |
| 872 | if (byid->options & PR_O_FORCED_ID) { |
| 873 | if (diff) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 874 | *diff |= PR_FBM_MISMATCH_NAME; |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 875 | return byid; |
| 876 | } |
| 877 | else { |
| 878 | if (diff) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 879 | *diff |= PR_FBM_MISMATCH_ID; |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 880 | return byname; |
| 881 | } |
| 882 | } |
| 883 | |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 884 | /* remaining possibilities : |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 885 | * - name not set |
| 886 | * - name set but not found |
| 887 | */ |
| 888 | if (name && diff) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 889 | *diff |= PR_FBM_MISMATCH_NAME; |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 890 | return byid; |
| 891 | } |
| 892 | |
| 893 | /* ID not found */ |
| 894 | if (byname) { |
| 895 | if (diff) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 896 | *diff |= PR_FBM_MISMATCH_ID; |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 897 | return byname; |
| 898 | } |
| 899 | } |
| 900 | |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 901 | /* All remaining possibilities will lead to NULL. If we can report more |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 902 | * detailed information to the caller about changed types and/or name, |
| 903 | * we'll do it. For example, we could detect that "listen foo" was |
| 904 | * split into "frontend foo_ft" and "backend foo_bk" if IDs are forced. |
| 905 | * - name not set, ID not found |
| 906 | * - name not found, ID not set |
| 907 | * - name not found, ID not found |
| 908 | */ |
| 909 | if (!diff) |
| 910 | return NULL; |
| 911 | |
| 912 | if (name) { |
| 913 | byname = proxy_find_by_name(name, 0, 0); |
| 914 | if (byname && (!id || byname->uuid == id)) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 915 | *diff |= PR_FBM_MISMATCH_PROXYTYPE; |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | if (id) { |
| 919 | byid = proxy_find_by_id(id, 0, 0); |
| 920 | if (byid) { |
| 921 | if (!name) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 922 | *diff |= PR_FBM_MISMATCH_PROXYTYPE; /* only type changed */ |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 923 | else if (byid->options & PR_O_FORCED_ID) |
Baptiste Assmann | 8a027cc | 2015-07-03 11:03:33 +0200 | [diff] [blame] | 924 | *diff |= PR_FBM_MISMATCH_NAME | PR_FBM_MISMATCH_PROXYTYPE; /* name and type changed */ |
Willy Tarreau | eb3e348 | 2015-05-27 16:46:26 +0200 | [diff] [blame] | 925 | /* otherwise it's a different proxy that was returned */ |
| 926 | } |
| 927 | } |
| 928 | return NULL; |
| 929 | } |
| 930 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 931 | /* |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 932 | * This function finds a server with matching name within selected proxy. |
| 933 | * It also checks if there are more matching servers with |
| 934 | * requested name as this often leads into unexpected situations. |
| 935 | */ |
| 936 | |
| 937 | struct server *findserver(const struct proxy *px, const char *name) { |
| 938 | |
| 939 | struct server *cursrv, *target = NULL; |
| 940 | |
| 941 | if (!px) |
| 942 | return NULL; |
| 943 | |
| 944 | for (cursrv = px->srv; cursrv; cursrv = cursrv->next) { |
| 945 | if (strcmp(cursrv->id, name)) |
| 946 | continue; |
| 947 | |
| 948 | if (!target) { |
| 949 | target = cursrv; |
| 950 | continue; |
| 951 | } |
| 952 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 953 | ha_alert("Refusing to use duplicated server '%s' found in proxy: %s!\n", |
| 954 | name, px->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 955 | |
| 956 | return NULL; |
| 957 | } |
| 958 | |
| 959 | return target; |
| 960 | } |
| 961 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 962 | /* This function checks that the designated proxy has no http directives |
| 963 | * enabled. It will output a warning if there are, and will fix some of them. |
| 964 | * It returns the number of fatal errors encountered. This should be called |
| 965 | * at the end of the configuration parsing if the proxy is not in http mode. |
| 966 | * The <file> argument is used to construct the error message. |
| 967 | */ |
Willy Tarreau | 915e1eb | 2009-06-22 15:48:36 +0200 | [diff] [blame] | 968 | int proxy_cfg_ensure_no_http(struct proxy *curproxy) |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 969 | { |
| 970 | if (curproxy->cookie_name != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 971 | ha_warning("config : cookie will be ignored for %s '%s' (needs 'mode http').\n", |
| 972 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 973 | } |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 974 | if (curproxy->monitor_uri != NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 975 | ha_warning("config : monitor-uri will be ignored for %s '%s' (needs 'mode http').\n", |
| 976 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 977 | } |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 978 | if (curproxy->lbprm.algo & BE_LB_NEED_HTTP) { |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 979 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 980 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 981 | ha_warning("config : Layer 7 hash not possible for %s '%s' (needs 'mode http'). Falling back to round robin.\n", |
| 982 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 983 | } |
Willy Tarreau | 1780416 | 2009-11-09 21:27:51 +0100 | [diff] [blame] | 984 | if (curproxy->to_log & (LW_REQ | LW_RESP)) { |
| 985 | curproxy->to_log &= ~(LW_REQ | LW_RESP); |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 986 | ha_warning("parsing [%s:%d] : HTTP log/header format not usable with %s '%s' (needs 'mode http').\n", |
| 987 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, |
| 988 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 1780416 | 2009-11-09 21:27:51 +0100 | [diff] [blame] | 989 | } |
Willy Tarreau | 62a6123 | 2013-04-12 18:13:46 +0200 | [diff] [blame] | 990 | if (curproxy->conf.logformat_string == default_http_log_format || |
| 991 | curproxy->conf.logformat_string == clf_http_log_format) { |
| 992 | /* Note: we don't change the directive's file:line number */ |
| 993 | curproxy->conf.logformat_string = default_tcp_log_format; |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 994 | ha_warning("parsing [%s:%d] : 'option httplog' not usable with %s '%s' (needs 'mode http'). Falling back to 'option tcplog'.\n", |
| 995 | curproxy->conf.lfs_file, curproxy->conf.lfs_line, |
| 996 | proxy_type_str(curproxy), curproxy->id); |
Willy Tarreau | 196729e | 2012-05-31 19:30:26 +0200 | [diff] [blame] | 997 | } |
| 998 | |
Willy Tarreau | ff01a21 | 2009-03-15 13:46:16 +0100 | [diff] [blame] | 999 | return 0; |
| 1000 | } |
| 1001 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1002 | /* Perform the most basic initialization of a proxy : |
| 1003 | * memset(), list_init(*), reset_timeouts(*). |
Willy Tarreau | b249e84 | 2011-09-07 18:41:08 +0200 | [diff] [blame] | 1004 | * Any new proxy or peer should be initialized via this function. |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1005 | */ |
| 1006 | void init_new_proxy(struct proxy *p) |
| 1007 | { |
| 1008 | memset(p, 0, sizeof(struct proxy)); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1009 | p->obj_type = OBJ_TYPE_PROXY; |
Patrick Hemmer | 0355dab | 2018-05-11 12:52:31 -0400 | [diff] [blame] | 1010 | p->pendconns = EB_ROOT; |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1011 | LIST_INIT(&p->acl); |
| 1012 | LIST_INIT(&p->http_req_rules); |
Willy Tarreau | e365c0b | 2013-06-11 16:06:12 +0200 | [diff] [blame] | 1013 | LIST_INIT(&p->http_res_rules); |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 1014 | LIST_INIT(&p->http_after_res_rules); |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1015 | LIST_INIT(&p->redirect_rules); |
| 1016 | LIST_INIT(&p->mon_fail_cond); |
| 1017 | LIST_INIT(&p->switching_rules); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1018 | LIST_INIT(&p->server_rules); |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1019 | LIST_INIT(&p->persist_rules); |
| 1020 | LIST_INIT(&p->sticking_rules); |
| 1021 | LIST_INIT(&p->storersp_rules); |
| 1022 | LIST_INIT(&p->tcp_req.inspect_rules); |
| 1023 | LIST_INIT(&p->tcp_rep.inspect_rules); |
| 1024 | LIST_INIT(&p->tcp_req.l4_rules); |
Willy Tarreau | 620408f | 2016-10-21 16:37:51 +0200 | [diff] [blame] | 1025 | LIST_INIT(&p->tcp_req.l5_rules); |
Olivier Houchard | 859dc80 | 2019-08-08 15:47:21 +0200 | [diff] [blame] | 1026 | MT_LIST_INIT(&p->listener_queue); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 1027 | LIST_INIT(&p->logsrvs); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 1028 | LIST_INIT(&p->logformat); |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 1029 | LIST_INIT(&p->logformat_sd); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1030 | LIST_INIT(&p->format_unique_id); |
Willy Tarreau | 2a65ff0 | 2012-09-13 17:54:29 +0200 | [diff] [blame] | 1031 | LIST_INIT(&p->conf.bind); |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1032 | LIST_INIT(&p->conf.listeners); |
Christopher Faulet | 76edc0f | 2020-01-13 15:52:01 +0100 | [diff] [blame] | 1033 | LIST_INIT(&p->conf.errors); |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1034 | LIST_INIT(&p->conf.args.list); |
Christopher Faulet | 443ea1a | 2016-02-04 13:40:26 +0100 | [diff] [blame] | 1035 | LIST_INIT(&p->filter_configs); |
Christopher Faulet | 7a1e2e1 | 2020-04-02 18:05:11 +0200 | [diff] [blame] | 1036 | LIST_INIT(&p->tcpcheck_rules.preset_vars); |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1037 | |
| 1038 | /* Timeouts are defined as -1 */ |
| 1039 | proxy_reset_timeouts(p); |
| 1040 | p->tcp_rep.inspect_delay = TICK_ETERNITY; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 1041 | |
| 1042 | /* initial uuid is unassigned (-1) */ |
| 1043 | p->uuid = -1; |
Christopher Faulet | ff8abcd | 2017-06-02 15:33:24 +0200 | [diff] [blame] | 1044 | |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 1045 | /* Default to only allow L4 retries */ |
| 1046 | p->retry_type = PR_RE_CONN_FAILED; |
| 1047 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1048 | HA_RWLOCK_INIT(&p->lock); |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Willy Tarreau | acde152 | 2020-10-07 16:31:39 +0200 | [diff] [blame] | 1051 | /* to be called under the proxy lock after stopping some listeners. This will |
| 1052 | * automatically update the p->disabled flag after stopping the last one, and |
| 1053 | * will emit a log indicating the proxy's condition. The function is idempotent |
| 1054 | * so that it will not emit multiple logs; a proxy will be disabled only once. |
| 1055 | */ |
| 1056 | void proxy_cond_disable(struct proxy *p) |
| 1057 | { |
| 1058 | if (p->disabled) |
| 1059 | return; |
| 1060 | |
| 1061 | if (p->li_ready + p->li_paused > 0) |
| 1062 | return; |
| 1063 | |
| 1064 | p->disabled = 1; |
| 1065 | |
| 1066 | if (!(proc_mask(p->bind_proc) & pid_bit)) |
| 1067 | goto silent; |
| 1068 | |
| 1069 | /* Note: syslog proxies use their own loggers so while it's somewhat OK |
| 1070 | * to report them being stopped as a warning, we must not spam their log |
| 1071 | * servers which are in fact production servers. For other types (CLI, |
| 1072 | * peers, etc) we must not report them at all as they're not really on |
| 1073 | * the data plane but on the control plane. |
| 1074 | */ |
| 1075 | if (p->mode == PR_MODE_TCP || p->mode == PR_MODE_HTTP || p->mode == PR_MODE_SYSLOG) |
| 1076 | ha_warning("Proxy %s stopped (cumulated conns: FE: %lld, BE: %lld).\n", |
| 1077 | p->id, p->fe_counters.cum_conn, p->be_counters.cum_conn); |
| 1078 | |
| 1079 | if (p->mode == PR_MODE_TCP || p->mode == PR_MODE_HTTP) |
| 1080 | send_log(p, LOG_WARNING, "Proxy %s stopped (cumulated conns: FE: %lld, BE: %lld).\n", |
| 1081 | p->id, p->fe_counters.cum_conn, p->be_counters.cum_conn); |
| 1082 | |
| 1083 | silent: |
| 1084 | if (p->table && p->table->size && p->table->sync_task) |
| 1085 | task_wakeup(p->table->sync_task, TASK_WOKEN_MSG); |
| 1086 | |
| 1087 | if (p->task) |
| 1088 | task_wakeup(p->task, TASK_WOKEN_MSG); |
| 1089 | } |
| 1090 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1091 | /* |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1092 | * This is the proxy management task. It enables proxies when there are enough |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1093 | * free streams, or stops them when the table is full. It is designed to be |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1094 | * called as a task which is woken up upon stopping or when rate limiting must |
| 1095 | * be enforced. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1096 | */ |
Olivier Houchard | 9f6af33 | 2018-05-25 14:04:04 +0200 | [diff] [blame] | 1097 | struct task *manage_proxy(struct task *t, void *context, unsigned short state) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1098 | { |
Olivier Houchard | 9f6af33 | 2018-05-25 14:04:04 +0200 | [diff] [blame] | 1099 | struct proxy *p = context; |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1100 | int next = TICK_ETERNITY; |
Willy Tarreau | 7958422 | 2009-03-06 09:18:27 +0100 | [diff] [blame] | 1101 | unsigned int wait; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1102 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1103 | /* We should periodically try to enable listeners waiting for a |
| 1104 | * global resource here. |
| 1105 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1106 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1107 | /* first, let's check if we need to stop the proxy */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1108 | if (unlikely(stopping && !p->disabled)) { |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1109 | int t; |
| 1110 | t = tick_remain(now_ms, p->stop_time); |
| 1111 | if (t == 0) { |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1112 | stop_proxy(p); |
| 1113 | /* try to free more memory */ |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 1114 | pool_gc(NULL); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1115 | } |
| 1116 | else { |
| 1117 | next = tick_first(next, p->stop_time); |
| 1118 | } |
| 1119 | } |
Willy Tarreau | f3f8c70 | 2011-07-25 07:37:28 +0200 | [diff] [blame] | 1120 | |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 1121 | /* If the proxy holds a stick table, we need to purge all unused |
| 1122 | * entries. These are all the ones in the table with ref_cnt == 0 |
| 1123 | * and all the ones in the pool used to allocate new entries. Any |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1124 | * entry attached to an existing stream waiting for a store will |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 1125 | * be in neither list. Any entry being dumped will have ref_cnt > 0. |
| 1126 | * However we protect tables that are being synced to peers. |
| 1127 | */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1128 | if (unlikely(stopping && p->disabled && p->table && p->table->current)) { |
Emeric Brun | 167b783 | 2021-04-23 17:02:22 +0200 | [diff] [blame] | 1129 | |
| 1130 | if (!p->table->refcnt) { |
| 1131 | /* !table->refcnt means there |
| 1132 | * is no more pending full resync |
| 1133 | * to push to a new process and |
| 1134 | * we are free to flush the table. |
| 1135 | */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1136 | stktable_trash_oldest(p->table, p->table->current); |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 1137 | pool_gc(NULL); |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 1138 | } |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1139 | if (p->table->current) { |
Willy Tarreau | 3a925c1 | 2013-09-04 17:54:01 +0200 | [diff] [blame] | 1140 | /* some entries still remain, let's recheck in one second */ |
| 1141 | next = tick_first(next, tick_add(now_ms, 1000)); |
| 1142 | } |
| 1143 | } |
| 1144 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1145 | /* the rest below is just for frontends */ |
| 1146 | if (!(p->cap & PR_CAP_FE)) |
| 1147 | goto out; |
Willy Tarreau | f3f8c70 | 2011-07-25 07:37:28 +0200 | [diff] [blame] | 1148 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1149 | /* check the various reasons we may find to block the frontend */ |
Willy Tarreau | 6b3bf73 | 2020-09-24 07:35:46 +0200 | [diff] [blame] | 1150 | if (unlikely(p->feconn >= p->maxconn)) |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1151 | goto out; |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 1152 | |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1153 | if (p->fe_sps_lim && |
| 1154 | (wait = next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0))) { |
| 1155 | /* we're blocking because a limit was reached on the number of |
| 1156 | * requests/s on the frontend. We want to re-check ASAP, which |
| 1157 | * means in 1 ms before estimated expiration date, because the |
| 1158 | * timer will have settled down. |
| 1159 | */ |
| 1160 | next = tick_first(next, tick_add(now_ms, wait)); |
| 1161 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1162 | } |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1163 | |
| 1164 | /* The proxy is not limited so we can re-enable any waiting listener */ |
Willy Tarreau | 241797a | 2019-12-10 14:10:52 +0100 | [diff] [blame] | 1165 | dequeue_proxy_listeners(p); |
Willy Tarreau | 918ff60 | 2011-07-25 16:33:49 +0200 | [diff] [blame] | 1166 | out: |
| 1167 | t->expire = next; |
| 1168 | task_queue(t); |
| 1169 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1173 | static int proxy_parse_hard_stop_after(char **args, int section_type, struct proxy *curpx, |
| 1174 | struct proxy *defpx, const char *file, int line, |
| 1175 | char **err) |
| 1176 | { |
| 1177 | const char *res; |
| 1178 | |
| 1179 | if (!*args[1]) { |
| 1180 | memprintf(err, "'%s' expects <time> as argument.\n", args[0]); |
| 1181 | return -1; |
| 1182 | } |
| 1183 | res = parse_time_err(args[1], &global.hard_stop_after, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1184 | if (res == PARSE_TIME_OVER) { |
| 1185 | memprintf(err, "timer overflow in argument '%s' to '%s' (maximum value is 2147483647 ms or ~24.8 days)", |
| 1186 | args[1], args[0]); |
| 1187 | return -1; |
| 1188 | } |
| 1189 | else if (res == PARSE_TIME_UNDER) { |
| 1190 | memprintf(err, "timer underflow in argument '%s' to '%s' (minimum non-null value is 1 ms)", |
| 1191 | args[1], args[0]); |
| 1192 | return -1; |
| 1193 | } |
| 1194 | else if (res) { |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1195 | memprintf(err, "unexpected character '%c' in argument to <%s>.\n", *res, args[0]); |
| 1196 | return -1; |
| 1197 | } |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Olivier Houchard | 9f6af33 | 2018-05-25 14:04:04 +0200 | [diff] [blame] | 1201 | struct task *hard_stop(struct task *t, void *context, unsigned short state) |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1202 | { |
| 1203 | struct proxy *p; |
| 1204 | struct stream *s; |
Willy Tarreau | 6b08479 | 2021-02-24 11:13:59 +0100 | [diff] [blame] | 1205 | int thr; |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1206 | |
| 1207 | if (killed) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1208 | ha_warning("Some tasks resisted to hard-stop, exiting now.\n"); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1209 | send_log(NULL, LOG_WARNING, "Some tasks resisted to hard-stop, exiting now.\n"); |
Willy Tarreau | 7067b3a | 2019-06-02 11:11:29 +0200 | [diff] [blame] | 1210 | killed = 2; |
Willy Tarreau | 6b08479 | 2021-02-24 11:13:59 +0100 | [diff] [blame] | 1211 | for (thr = 0; thr < global.nbthread; thr++) |
| 1212 | if (((all_threads_mask & ~tid_bit) >> thr) & 1) |
| 1213 | wake_thread(thr); |
Willy Tarreau | 7067b3a | 2019-06-02 11:11:29 +0200 | [diff] [blame] | 1214 | t->expire = TICK_ETERNITY; |
| 1215 | return t; |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1218 | ha_warning("soft-stop running for too long, performing a hard-stop.\n"); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1219 | send_log(NULL, LOG_WARNING, "soft-stop running for too long, performing a hard-stop.\n"); |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1220 | p = proxies_list; |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1221 | while (p) { |
| 1222 | if ((p->cap & PR_CAP_FE) && (p->feconn > 0)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1223 | ha_warning("Proxy %s hard-stopped (%d remaining conns will be closed).\n", |
| 1224 | p->id, p->feconn); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1225 | send_log(p, LOG_WARNING, "Proxy %s hard-stopped (%d remaining conns will be closed).\n", |
| 1226 | p->id, p->feconn); |
| 1227 | } |
| 1228 | p = p->next; |
| 1229 | } |
Willy Tarreau | be9833e | 2021-02-24 11:08:56 +0100 | [diff] [blame] | 1230 | |
| 1231 | thread_isolate(); |
Willy Tarreau | 67de95e | 2021-02-24 10:37:01 +0100 | [diff] [blame] | 1232 | |
| 1233 | for (thr = 0; thr < global.nbthread; thr++) { |
| 1234 | list_for_each_entry(s, &ha_thread_info[thr].streams, list) { |
| 1235 | stream_shutdown(s, SF_ERR_KILLED); |
| 1236 | } |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1237 | } |
Willy Tarreau | 67de95e | 2021-02-24 10:37:01 +0100 | [diff] [blame] | 1238 | |
Willy Tarreau | be9833e | 2021-02-24 11:08:56 +0100 | [diff] [blame] | 1239 | thread_release(); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1240 | |
| 1241 | killed = 1; |
| 1242 | t->expire = tick_add(now_ms, MS_TO_TICKS(1000)); |
| 1243 | return t; |
| 1244 | } |
| 1245 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1246 | /* |
| 1247 | * this function disables health-check servers so that the process will quickly be ignored |
| 1248 | * by load balancers. Note that if a proxy was already in the PAUSED state, then its grace |
| 1249 | * time will not be used since it would already not listen anymore to the socket. |
| 1250 | */ |
| 1251 | void soft_stop(void) |
| 1252 | { |
| 1253 | struct proxy *p; |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1254 | struct task *task; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1255 | |
| 1256 | stopping = 1; |
William Dauchy | 3894d97 | 2019-12-28 15:36:02 +0100 | [diff] [blame] | 1257 | /* disable busy polling to avoid cpu eating for the new process */ |
| 1258 | global.tune.options &= ~GTUNE_BUSY_POLLING; |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1259 | if (tick_isset(global.hard_stop_after)) { |
Emeric Brun | c60def8 | 2017-09-27 14:59:38 +0200 | [diff] [blame] | 1260 | task = task_new(MAX_THREADS_MASK); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1261 | if (task) { |
| 1262 | task->process = hard_stop; |
| 1263 | task_schedule(task, tick_add(now_ms, global.hard_stop_after)); |
| 1264 | } |
| 1265 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1266 | ha_alert("out of memory trying to allocate the hard-stop task.\n"); |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1267 | } |
| 1268 | } |
Willy Tarreau | 626f3a7 | 2020-10-07 16:52:43 +0200 | [diff] [blame] | 1269 | |
| 1270 | /* stop all stoppable listeners, resulting in disabling all proxies |
| 1271 | * that don't use a grace period. |
| 1272 | */ |
| 1273 | protocol_stop_now(); |
| 1274 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1275 | p = proxies_list; |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 1276 | tv_update_date(0,1); /* else, the old time before select will be used */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1277 | while (p) { |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1278 | if (!p->disabled) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1279 | ha_warning("Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace); |
Willy Tarreau | f8fbcef | 2008-10-10 17:51:34 +0200 | [diff] [blame] | 1280 | send_log(p, LOG_WARNING, "Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace); |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1281 | p->stop_time = tick_add(now_ms, p->grace); |
Emeric Brun | 5a8c0a9 | 2010-09-23 18:44:36 +0200 | [diff] [blame] | 1282 | |
Willy Tarreau | 20b7afb | 2015-09-28 16:35:04 +0200 | [diff] [blame] | 1283 | /* Note: do not wake up stopped proxies' task nor their tables' |
| 1284 | * tasks as these ones might point to already released entries. |
| 1285 | */ |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1286 | if (p->table && p->table->size && p->table->sync_task) |
| 1287 | task_wakeup(p->table->sync_task, TASK_WOKEN_MSG); |
Willy Tarreau | 20b7afb | 2015-09-28 16:35:04 +0200 | [diff] [blame] | 1288 | |
| 1289 | if (p->task) |
| 1290 | task_wakeup(p->task, TASK_WOKEN_MSG); |
| 1291 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1292 | p = p->next; |
| 1293 | } |
Willy Tarreau | bbe11b1 | 2011-07-25 11:16:24 +0200 | [diff] [blame] | 1294 | |
Willy Tarreau | d0807c3 | 2010-08-27 18:26:11 +0200 | [diff] [blame] | 1295 | /* signal zero is used to broadcast the "stopping" event */ |
| 1296 | signal_handler(0); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 1300 | /* Temporarily disables listening on all of the proxy's listeners. Upon |
Willy Tarreau | a17c91b | 2020-09-24 07:44:34 +0200 | [diff] [blame] | 1301 | * success, the proxy enters the PR_PAUSED state. The function returns 0 |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1302 | * if it fails, or non-zero on success. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1303 | */ |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1304 | int pause_proxy(struct proxy *p) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1305 | { |
| 1306 | struct listener *l; |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1307 | |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1308 | if (!(p->cap & PR_CAP_FE) || p->disabled || !p->li_ready) |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1309 | return 1; |
| 1310 | |
Willy Tarreau | a17c91b | 2020-09-24 07:44:34 +0200 | [diff] [blame] | 1311 | list_for_each_entry(l, &p->conf.listeners, by_fe) |
| 1312 | pause_listener(l); |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1313 | |
Willy Tarreau | a17c91b | 2020-09-24 07:44:34 +0200 | [diff] [blame] | 1314 | if (p->li_ready) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1315 | ha_warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id); |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1316 | send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id); |
| 1317 | return 0; |
| 1318 | } |
Willy Tarreau | ce8fe25 | 2011-09-07 19:14:57 +0200 | [diff] [blame] | 1319 | return 1; |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 1320 | } |
| 1321 | |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 1322 | /* |
| 1323 | * This function completely stops a proxy and releases its listeners. It has |
| 1324 | * to be called when going down in order to release the ports so that another |
| 1325 | * process may bind to them. It must also be called on disabled proxies at the |
William Lallemand | c59f988 | 2018-11-16 16:57:21 +0100 | [diff] [blame] | 1326 | * end of start-up. If all listeners are closed, the proxy is set to the |
Willy Tarreau | 3de3cd4 | 2019-07-24 17:42:44 +0200 | [diff] [blame] | 1327 | * PR_STSTOPPED state. The function takes the proxy's lock so it's safe to |
| 1328 | * call from multiple places. |
Willy Tarreau | da250db | 2008-10-12 12:07:48 +0200 | [diff] [blame] | 1329 | */ |
| 1330 | void stop_proxy(struct proxy *p) |
| 1331 | { |
| 1332 | struct listener *l; |
| 1333 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1334 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock); |
Willy Tarreau | 3de3cd4 | 2019-07-24 17:42:44 +0200 | [diff] [blame] | 1335 | |
Willy Tarreau | 322b9b9 | 2020-10-07 16:20:34 +0200 | [diff] [blame] | 1336 | list_for_each_entry(l, &p->conf.listeners, by_fe) |
| 1337 | stop_listener(l, 1, 0, 0); |
Willy Tarreau | 3de3cd4 | 2019-07-24 17:42:44 +0200 | [diff] [blame] | 1338 | |
Willy Tarreau | ba29687 | 2020-10-16 15:10:11 +0200 | [diff] [blame] | 1339 | if (!p->disabled && !p->li_ready) { |
| 1340 | /* might be just a backend */ |
| 1341 | p->disabled = 1; |
| 1342 | } |
| 1343 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1344 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1345 | } |
| 1346 | |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1347 | /* This function resumes listening on the specified proxy. It scans all of its |
| 1348 | * listeners and tries to enable them all. If any of them fails, the proxy is |
| 1349 | * put back to the paused state. It returns 1 upon success, or zero if an error |
| 1350 | * is encountered. |
| 1351 | */ |
| 1352 | int resume_proxy(struct proxy *p) |
| 1353 | { |
| 1354 | struct listener *l; |
| 1355 | int fail; |
| 1356 | |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1357 | if (p->disabled || !p->li_paused) |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1358 | return 1; |
| 1359 | |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1360 | fail = 0; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 1361 | list_for_each_entry(l, &p->conf.listeners, by_fe) { |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1362 | if (!resume_listener(l)) { |
| 1363 | int port; |
| 1364 | |
Willy Tarreau | 3715906 | 2020-08-27 07:48:42 +0200 | [diff] [blame] | 1365 | port = get_host_port(&l->rx.addr); |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1366 | if (port) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1367 | ha_warning("Port %d busy while trying to enable %s %s.\n", |
| 1368 | port, proxy_cap_str(p->cap), p->id); |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1369 | send_log(p, LOG_WARNING, "Port %d busy while trying to enable %s %s.\n", |
| 1370 | port, proxy_cap_str(p->cap), p->id); |
| 1371 | } |
| 1372 | else { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1373 | ha_warning("Bind on socket %d busy while trying to enable %s %s.\n", |
| 1374 | l->luid, proxy_cap_str(p->cap), p->id); |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1375 | send_log(p, LOG_WARNING, "Bind on socket %d busy while trying to enable %s %s.\n", |
| 1376 | l->luid, proxy_cap_str(p->cap), p->id); |
| 1377 | } |
| 1378 | |
| 1379 | /* Another port might have been enabled. Let's stop everything. */ |
| 1380 | fail = 1; |
| 1381 | break; |
| 1382 | } |
| 1383 | } |
| 1384 | |
Willy Tarreau | c03ebbf | 2011-09-07 21:33:14 +0200 | [diff] [blame] | 1385 | if (fail) { |
| 1386 | pause_proxy(p); |
| 1387 | return 0; |
| 1388 | } |
| 1389 | return 1; |
| 1390 | } |
| 1391 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1392 | /* Set current stream's backend to <be>. Nothing is done if the |
| 1393 | * stream already had a backend assigned, which is indicated by |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1394 | * s->flags & SF_BE_ASSIGNED. |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1395 | * All flags, stats and counters which need be updated are updated. |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1396 | * Returns 1 if done, 0 in case of internal error, eg: lack of resource. |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1397 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1398 | int stream_set_backend(struct stream *s, struct proxy *be) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1399 | { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1400 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1401 | return 1; |
Christopher Faulet | 4117904 | 2016-06-21 11:54:52 +0200 | [diff] [blame] | 1402 | |
| 1403 | if (flt_set_stream_backend(s, be) < 0) |
| 1404 | return 0; |
| 1405 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1406 | s->be = be; |
Christopher Faulet | ff8abcd | 2017-06-02 15:33:24 +0200 | [diff] [blame] | 1407 | HA_ATOMIC_UPDATE_MAX(&be->be_counters.conn_max, |
| 1408 | HA_ATOMIC_ADD(&be->beconn, 1)); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1409 | proxy_inc_be_ctr(be); |
| 1410 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1411 | /* assign new parameters to the stream from the new backend */ |
Willy Tarreau | f27b5ea | 2009-10-03 22:01:18 +0200 | [diff] [blame] | 1412 | s->si[1].flags &= ~SI_FL_INDEP_STR; |
| 1413 | if (be->options2 & PR_O2_INDEPSTR) |
| 1414 | s->si[1].flags |= SI_FL_INDEP_STR; |
| 1415 | |
Hongbo Long | e39683c | 2017-03-10 18:41:51 +0100 | [diff] [blame] | 1416 | if (tick_isset(be->timeout.serverfin)) |
| 1417 | s->si[1].hcto = be->timeout.serverfin; |
| 1418 | |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 1419 | /* We want to enable the backend-specific analysers except those which |
| 1420 | * were already run as part of the frontend/listener. Note that it would |
| 1421 | * be more reliable to store the list of analysers that have been run, |
| 1422 | * but what we do here is OK for now. |
| 1423 | */ |
Christopher Faulet | 70e2f27 | 2017-01-09 16:33:19 +0100 | [diff] [blame] | 1424 | s->req.analysers |= be->be_req_ana & ~(strm_li(s) ? strm_li(s)->analysers : 0); |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 1425 | |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 1426 | /* If the target backend requires HTTP processing, we have to allocate |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 1427 | * the HTTP transaction if we did not have one. |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 1428 | */ |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1429 | if (unlikely(!s->txn && be->http_needed)) { |
| 1430 | if (unlikely(!http_alloc_txn(s))) |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 1431 | return 0; /* not enough memory */ |
Willy Tarreau | 39e4f62 | 2010-05-31 17:01:36 +0200 | [diff] [blame] | 1432 | |
| 1433 | /* and now initialize the HTTP transaction state */ |
| 1434 | http_init_txn(s); |
Willy Tarreau | 51aecc7 | 2009-07-12 09:47:04 +0200 | [diff] [blame] | 1435 | } |
| 1436 | |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 1437 | /* Be sure to filter request headers if the backend is an HTTP proxy and |
| 1438 | * if there are filters attached to the stream. */ |
| 1439 | if (s->be->mode == PR_MODE_HTTP && HAS_FILTERS(s)) |
Christopher Faulet | 0184ea7 | 2017-01-05 14:06:34 +0100 | [diff] [blame] | 1440 | s->req.analysers |= AN_REQ_FLT_HTTP_HDRS; |
Christopher Faulet | 309c641 | 2015-12-02 09:57:32 +0100 | [diff] [blame] | 1441 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1442 | if (s->txn) { |
Christopher Faulet | bbe6854 | 2019-04-08 10:53:51 +0200 | [diff] [blame] | 1443 | /* If we chain a TCP frontend to an HTX backend, we must upgrade |
| 1444 | * the client mux */ |
Christopher Faulet | 60d29b3 | 2019-07-15 15:00:25 +0200 | [diff] [blame] | 1445 | if (!IS_HTX_STRM(s) && be->mode == PR_MODE_HTTP) { |
Christopher Faulet | bbe6854 | 2019-04-08 10:53:51 +0200 | [diff] [blame] | 1446 | struct connection *conn = objt_conn(strm_sess(s)->origin); |
| 1447 | struct conn_stream *cs = objt_cs(s->si[0].end); |
| 1448 | |
| 1449 | if (conn && cs) { |
| 1450 | si_rx_endp_more(&s->si[0]); |
Olivier Houchard | 2ab3dad | 2019-07-03 13:08:18 +0200 | [diff] [blame] | 1451 | /* Make sure we're unsubscribed, the the new |
| 1452 | * mux will probably want to subscribe to |
| 1453 | * the underlying XPRT |
| 1454 | */ |
| 1455 | if (s->si[0].wait_event.events) |
| 1456 | conn->mux->unsubscribe(cs, s->si[0].wait_event.events, |
| 1457 | &s->si[0].wait_event); |
Christopher Faulet | c985f6c | 2019-07-15 11:42:52 +0200 | [diff] [blame] | 1458 | if (conn_upgrade_mux_fe(conn, cs, &s->req.buf, ist(""), PROTO_MODE_HTTP) == -1) |
Christopher Faulet | bbe6854 | 2019-04-08 10:53:51 +0200 | [diff] [blame] | 1459 | return 0; |
Olivier Houchard | 4c18f94 | 2019-07-31 18:05:26 +0200 | [diff] [blame] | 1460 | if (!strcmp(conn->mux->name, "H2")) { |
| 1461 | /* For HTTP/2, destroy the conn_stream, |
| 1462 | * disable logging, and pretend that we |
| 1463 | * failed, to that the stream is |
| 1464 | * silently destroyed. The new mux |
| 1465 | * will create new streams. |
| 1466 | */ |
Olivier Houchard | 59dd06d | 2019-08-09 18:01:15 +0200 | [diff] [blame] | 1467 | cs_free(cs); |
Olivier Houchard | 4c18f94 | 2019-07-31 18:05:26 +0200 | [diff] [blame] | 1468 | si_detach_endpoint(&s->si[0]); |
| 1469 | s->logs.logwait = 0; |
| 1470 | s->logs.level = 0; |
| 1471 | s->flags |= SF_IGNORE; |
| 1472 | return 0; |
| 1473 | } |
Olivier Houchard | 71b20c2 | 2019-08-09 17:50:05 +0200 | [diff] [blame] | 1474 | s->flags |= SF_HTX; |
Christopher Faulet | bbe6854 | 2019-04-08 10:53:51 +0200 | [diff] [blame] | 1475 | } |
| 1476 | } |
Christopher Faulet | eec7f8a | 2019-12-20 15:59:20 +0100 | [diff] [blame] | 1477 | else if (IS_HTX_STRM(s) && be->mode != PR_MODE_HTTP) { |
| 1478 | /* If a TCP backend is assgiend to an HTX stream, return |
| 1479 | * an error. It may happens for a new stream on a |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 1480 | * previously upgraded connections. */ |
Christopher Faulet | eec7f8a | 2019-12-20 15:59:20 +0100 | [diff] [blame] | 1481 | if (!(s->flags & SF_ERR_MASK)) |
| 1482 | s->flags |= SF_ERR_INTERNAL; |
| 1483 | return 0; |
| 1484 | } |
Christopher Faulet | bbe6854 | 2019-04-08 10:53:51 +0200 | [diff] [blame] | 1485 | |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 1486 | /* we may request to parse a request body */ |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 1487 | if (be->options & PR_O_WREQ_BODY) |
Willy Tarreau | 9fbe18e | 2015-05-01 22:42:08 +0200 | [diff] [blame] | 1488 | s->req.analysers |= AN_REQ_HTTP_BODY; |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | s->flags |= SF_BE_ASSIGNED; |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 1492 | if (be->options2 & PR_O2_NODELAY) { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1493 | s->req.flags |= CF_NEVER_WAIT; |
| 1494 | s->res.flags |= CF_NEVER_WAIT; |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 1495 | } |
| 1496 | |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1497 | return 1; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1500 | /* Capture a bad request or response and archive it in the proxy's structure. |
| 1501 | * It is relatively protocol-agnostic so it requires that a number of elements |
| 1502 | * are passed : |
| 1503 | * - <proxy> is the proxy where the error was detected and where the snapshot |
| 1504 | * needs to be stored |
Joseph Herlant | 59dd295 | 2018-11-15 11:46:55 -0800 | [diff] [blame] | 1505 | * - <is_back> indicates that the error happened when receiving the response |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1506 | * - <other_end> is a pointer to the proxy on the other side when known |
| 1507 | * - <target> is the target of the connection, usually a server or a proxy |
| 1508 | * - <sess> is the session which experienced the error |
| 1509 | * - <ctx> may be NULL or should contain any info relevant to the protocol |
| 1510 | * - <buf> is the buffer containing the offending data |
| 1511 | * - <buf_ofs> is the position of this buffer's input data in the input |
| 1512 | * stream, starting at zero. It may be passed as zero if unknown. |
| 1513 | * - <buf_out> is the portion of <buf->data> which was already forwarded and |
| 1514 | * which precedes the buffer's input. The buffer's input starts at |
| 1515 | * buf->head + buf_out. |
| 1516 | * - <err_pos> is the pointer to the faulty byte in the buffer's input. |
| 1517 | * - <show> is the callback to use to display <ctx>. It may be NULL. |
| 1518 | */ |
| 1519 | void proxy_capture_error(struct proxy *proxy, int is_back, |
| 1520 | struct proxy *other_end, enum obj_type *target, |
| 1521 | const struct session *sess, |
| 1522 | const struct buffer *buf, long buf_ofs, |
| 1523 | unsigned int buf_out, unsigned int err_pos, |
| 1524 | const union error_snapshot_ctx *ctx, |
| 1525 | void (*show)(struct buffer *, const struct error_snapshot *)) |
| 1526 | { |
| 1527 | struct error_snapshot *es; |
| 1528 | unsigned int buf_len; |
| 1529 | int len1, len2; |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 1530 | unsigned int ev_id; |
| 1531 | |
| 1532 | ev_id = HA_ATOMIC_XADD(&error_snapshot_id, 1); |
| 1533 | |
Willy Tarreau | 4bc7d90 | 2018-09-07 20:07:17 +0200 | [diff] [blame] | 1534 | buf_len = b_data(buf) - buf_out; |
| 1535 | |
| 1536 | es = malloc(sizeof(*es) + buf_len); |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 1537 | if (!es) |
| 1538 | return; |
| 1539 | |
Willy Tarreau | 4bc7d90 | 2018-09-07 20:07:17 +0200 | [diff] [blame] | 1540 | es->buf_len = buf_len; |
| 1541 | es->ev_id = ev_id; |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1542 | |
Christopher Faulet | 47a7210 | 2020-01-06 11:37:00 +0100 | [diff] [blame] | 1543 | len1 = b_size(buf) - b_peek_ofs(buf, buf_out); |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1544 | if (len1 > buf_len) |
| 1545 | len1 = buf_len; |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1546 | |
Willy Tarreau | 4bc7d90 | 2018-09-07 20:07:17 +0200 | [diff] [blame] | 1547 | if (len1) { |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1548 | memcpy(es->buf, b_peek(buf, buf_out), len1); |
Willy Tarreau | 4bc7d90 | 2018-09-07 20:07:17 +0200 | [diff] [blame] | 1549 | len2 = buf_len - len1; |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1550 | if (len2) |
| 1551 | memcpy(es->buf + len1, b_orig(buf), len2); |
| 1552 | } |
| 1553 | |
| 1554 | es->buf_err = err_pos; |
| 1555 | es->when = date; // user-visible date |
| 1556 | es->srv = objt_server(target); |
| 1557 | es->oe = other_end; |
Olivier Houchard | bdb00c5 | 2020-03-12 15:30:17 +0100 | [diff] [blame] | 1558 | if (sess && objt_conn(sess->origin) && conn_get_src(__objt_conn(sess->origin))) |
Willy Tarreau | 026efc7 | 2019-07-17 15:20:02 +0200 | [diff] [blame] | 1559 | es->src = *__objt_conn(sess->origin)->src; |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1560 | else |
| 1561 | memset(&es->src, 0, sizeof(es->src)); |
| 1562 | |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1563 | es->buf_wrap = b_wrap(buf) - b_peek(buf, buf_out); |
| 1564 | es->buf_out = buf_out; |
| 1565 | es->buf_ofs = buf_ofs; |
| 1566 | |
| 1567 | /* be sure to indicate the offset of the first IN byte */ |
| 1568 | if (es->buf_ofs >= es->buf_len) |
| 1569 | es->buf_ofs -= es->buf_len; |
| 1570 | else |
| 1571 | es->buf_ofs = 0; |
| 1572 | |
| 1573 | /* protocol-specific part now */ |
| 1574 | if (ctx) |
| 1575 | es->ctx = *ctx; |
| 1576 | else |
| 1577 | memset(&es->ctx, 0, sizeof(es->ctx)); |
| 1578 | es->show = show; |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 1579 | |
| 1580 | /* note: we still lock since we have to be certain that nobody is |
| 1581 | * dumping the output while we free. |
| 1582 | */ |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1583 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &proxy->lock); |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 1584 | if (is_back) { |
| 1585 | es = HA_ATOMIC_XCHG(&proxy->invalid_rep, es); |
| 1586 | } else { |
| 1587 | es = HA_ATOMIC_XCHG(&proxy->invalid_req, es); |
| 1588 | } |
| 1589 | free(es); |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1590 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &proxy->lock); |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1591 | } |
| 1592 | |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1593 | /* Configure all proxies which lack a maxconn setting to use the global one by |
| 1594 | * default. This avoids the common mistake consisting in setting maxconn only |
| 1595 | * in the global section and discovering the hard way that it doesn't propagate |
| 1596 | * through the frontends. These values are also propagated through the various |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 1597 | * targeted backends, whose fullconn is finally calculated if not yet set. |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1598 | */ |
| 1599 | void proxy_adjust_all_maxconn() |
| 1600 | { |
| 1601 | struct proxy *curproxy; |
| 1602 | struct switching_rule *swrule1, *swrule2; |
| 1603 | |
| 1604 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1605 | if (curproxy->disabled) |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1606 | continue; |
| 1607 | |
| 1608 | if (!(curproxy->cap & PR_CAP_FE)) |
| 1609 | continue; |
| 1610 | |
| 1611 | if (!curproxy->maxconn) |
| 1612 | curproxy->maxconn = global.maxconn; |
| 1613 | |
| 1614 | /* update the target backend's fullconn count : default_backend */ |
| 1615 | if (curproxy->defbe.be) |
| 1616 | curproxy->defbe.be->tot_fe_maxconn += curproxy->maxconn; |
| 1617 | else if ((curproxy->cap & PR_CAP_LISTEN) == PR_CAP_LISTEN) |
| 1618 | curproxy->tot_fe_maxconn += curproxy->maxconn; |
| 1619 | |
| 1620 | list_for_each_entry(swrule1, &curproxy->switching_rules, list) { |
| 1621 | /* For each target of switching rules, we update their |
| 1622 | * tot_fe_maxconn, except if a previous rule points to |
| 1623 | * the same backend or to the default backend. |
| 1624 | */ |
| 1625 | if (swrule1->be.backend != curproxy->defbe.be) { |
Frédéric Lécaille | 2365fb0 | 2019-03-07 15:02:52 +0100 | [diff] [blame] | 1626 | /* note: swrule1->be.backend isn't a backend if the rule |
| 1627 | * is dynamic, it's an expression instead, so it must not |
| 1628 | * be dereferenced as a backend before being certain it is. |
| 1629 | */ |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1630 | list_for_each_entry(swrule2, &curproxy->switching_rules, list) { |
| 1631 | if (swrule2 == swrule1) { |
Frédéric Lécaille | 2365fb0 | 2019-03-07 15:02:52 +0100 | [diff] [blame] | 1632 | if (!swrule1->dynamic) |
| 1633 | swrule1->be.backend->tot_fe_maxconn += curproxy->maxconn; |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1634 | break; |
| 1635 | } |
| 1636 | else if (!swrule2->dynamic && swrule2->be.backend == swrule1->be.backend) { |
| 1637 | /* there are multiple refs of this backend */ |
| 1638 | break; |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | /* automatically compute fullconn if not set. We must not do it in the |
| 1646 | * loop above because cross-references are not yet fully resolved. |
| 1647 | */ |
| 1648 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1649 | if (curproxy->disabled) |
Willy Tarreau | c8d5b95 | 2019-02-27 17:25:52 +0100 | [diff] [blame] | 1650 | continue; |
| 1651 | |
| 1652 | /* If <fullconn> is not set, let's set it to 10% of the sum of |
| 1653 | * the possible incoming frontend's maxconns. |
| 1654 | */ |
| 1655 | if (!curproxy->fullconn && (curproxy->cap & PR_CAP_BE)) { |
| 1656 | /* we have the sum of the maxconns in <total>. We only |
| 1657 | * keep 10% of that sum to set the default fullconn, with |
| 1658 | * a hard minimum of 1 (to avoid a divide by zero). |
| 1659 | */ |
| 1660 | curproxy->fullconn = (curproxy->tot_fe_maxconn + 9) / 10; |
| 1661 | if (!curproxy->fullconn) |
| 1662 | curproxy->fullconn = 1; |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | |
Willy Tarreau | 75fb65a | 2018-09-07 17:43:26 +0200 | [diff] [blame] | 1667 | /* Config keywords below */ |
| 1668 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 1669 | static struct cfg_kw_list cfg_kws = {ILH, { |
Cyril Bonté | 203ec5a | 2017-03-23 22:44:13 +0100 | [diff] [blame] | 1670 | { CFG_GLOBAL, "hard-stop-after", proxy_parse_hard_stop_after }, |
Willy Tarreau | 9de1bbd | 2008-07-09 20:34:27 +0200 | [diff] [blame] | 1671 | { CFG_LISTEN, "timeout", proxy_parse_timeout }, |
Tim Duesterhus | 86e6b6e | 2019-05-14 20:57:59 +0200 | [diff] [blame] | 1672 | { CFG_LISTEN, "clitimeout", proxy_parse_timeout }, /* This keyword actually fails to parse, this line remains for better error messages. */ |
| 1673 | { CFG_LISTEN, "contimeout", proxy_parse_timeout }, /* This keyword actually fails to parse, this line remains for better error messages. */ |
| 1674 | { CFG_LISTEN, "srvtimeout", proxy_parse_timeout }, /* This keyword actually fails to parse, this line remains for better error messages. */ |
Willy Tarreau | 3a7d207 | 2009-03-05 23:48:25 +0100 | [diff] [blame] | 1675 | { CFG_LISTEN, "rate-limit", proxy_parse_rate_limit }, |
Willy Tarreau | c35362a | 2014-04-25 13:58:37 +0200 | [diff] [blame] | 1676 | { CFG_LISTEN, "max-keep-alive-queue", proxy_parse_max_ka_queue }, |
Thierry FOURNIER | a0a1b75 | 2015-05-26 17:44:32 +0200 | [diff] [blame] | 1677 | { CFG_LISTEN, "declare", proxy_parse_declare }, |
Olivier Houchard | a254a37 | 2019-04-05 15:30:12 +0200 | [diff] [blame] | 1678 | { CFG_LISTEN, "retry-on", proxy_parse_retry_on }, |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 1679 | #ifdef TCP_KEEPCNT |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 1680 | { CFG_LISTEN, "clitcpka-cnt", proxy_parse_tcpka_cnt }, |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 1681 | { CFG_LISTEN, "srvtcpka-cnt", proxy_parse_tcpka_cnt }, |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 1682 | #endif |
| 1683 | #ifdef TCP_KEEPIDLE |
| 1684 | { CFG_LISTEN, "clitcpka-idle", proxy_parse_tcpka_idle }, |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 1685 | { CFG_LISTEN, "srvtcpka-idle", proxy_parse_tcpka_idle }, |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 1686 | #endif |
| 1687 | #ifdef TCP_KEEPINTVL |
| 1688 | { CFG_LISTEN, "clitcpka-intvl", proxy_parse_tcpka_intvl }, |
MIZUTA Takeshi | b24bc0d | 2020-07-09 11:13:20 +0900 | [diff] [blame] | 1689 | { CFG_LISTEN, "srvtcpka-intvl", proxy_parse_tcpka_intvl }, |
Willy Tarreau | 5254321 | 2020-07-09 05:58:51 +0200 | [diff] [blame] | 1690 | #endif |
Willy Tarreau | 9de1bbd | 2008-07-09 20:34:27 +0200 | [diff] [blame] | 1691 | { 0, NULL, NULL }, |
| 1692 | }}; |
| 1693 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1694 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |
| 1695 | |
Willy Tarreau | 960f2cb | 2016-11-24 12:02:29 +0100 | [diff] [blame] | 1696 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 1697 | * adequate error messages and returns NULL. This function is designed to be used by |
| 1698 | * functions requiring a frontend on the CLI. |
| 1699 | */ |
| 1700 | struct proxy *cli_find_frontend(struct appctx *appctx, const char *arg) |
| 1701 | { |
| 1702 | struct proxy *px; |
| 1703 | |
| 1704 | if (!*arg) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1705 | cli_err(appctx, "A frontend name is expected.\n"); |
Willy Tarreau | 960f2cb | 2016-11-24 12:02:29 +0100 | [diff] [blame] | 1706 | return NULL; |
| 1707 | } |
| 1708 | |
| 1709 | px = proxy_fe_by_name(arg); |
| 1710 | if (!px) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1711 | cli_err(appctx, "No such frontend.\n"); |
Willy Tarreau | 960f2cb | 2016-11-24 12:02:29 +0100 | [diff] [blame] | 1712 | return NULL; |
| 1713 | } |
| 1714 | return px; |
| 1715 | } |
| 1716 | |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1717 | /* Expects to find a backend named <arg> and returns it, otherwise displays various |
| 1718 | * adequate error messages and returns NULL. This function is designed to be used by |
| 1719 | * functions requiring a frontend on the CLI. |
| 1720 | */ |
| 1721 | struct proxy *cli_find_backend(struct appctx *appctx, const char *arg) |
| 1722 | { |
| 1723 | struct proxy *px; |
| 1724 | |
| 1725 | if (!*arg) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1726 | cli_err(appctx, "A backend name is expected.\n"); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1727 | return NULL; |
| 1728 | } |
| 1729 | |
| 1730 | px = proxy_be_by_name(arg); |
| 1731 | if (!px) { |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1732 | cli_err(appctx, "No such backend.\n"); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1733 | return NULL; |
| 1734 | } |
| 1735 | return px; |
| 1736 | } |
| 1737 | |
| 1738 | |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 1739 | /* parse a "show servers [state|conn]" CLI line, returns 0 if it wants to start |
| 1740 | * the dump or 1 if it stops immediately. If an argument is specified, it will |
| 1741 | * set the proxy pointer into cli.p0 and its ID into cli.i0. It sets cli.o0 to |
| 1742 | * 0 for "state", or 1 for "conn". |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1743 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1744 | static int cli_parse_show_servers(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1745 | { |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1746 | struct proxy *px; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1747 | |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 1748 | appctx->ctx.cli.o0 = *args[2] == 'c'; // "conn" vs "state" |
| 1749 | |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1750 | /* check if a backend name has been provided */ |
| 1751 | if (*args[3]) { |
| 1752 | /* read server state from local file */ |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1753 | px = proxy_be_by_name(args[3]); |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1754 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 1755 | if (!px) |
| 1756 | return cli_err(appctx, "Can't find backend.\n"); |
| 1757 | |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1758 | appctx->ctx.cli.p0 = px; |
| 1759 | appctx->ctx.cli.i0 = px->uuid; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1760 | } |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
Willy Tarreau | 6ff8143 | 2020-07-01 07:02:42 +0200 | [diff] [blame] | 1764 | /* dumps server state information for all the servers found in backend cli.p0. |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1765 | * These information are all the parameters which may change during HAProxy runtime. |
| 1766 | * By default, we only export to the last known server state file format. |
| 1767 | * These information can be used at next startup to recover same level of server state. |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1768 | * It uses the proxy pointer from cli.p0, the proxy's id from cli.i0 and the server's |
| 1769 | * pointer from cli.p1. |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1770 | */ |
Willy Tarreau | 6ff8143 | 2020-07-01 07:02:42 +0200 | [diff] [blame] | 1771 | static int dump_servers_state(struct stream_interface *si) |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1772 | { |
| 1773 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1774 | struct proxy *px = appctx->ctx.cli.p0; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1775 | struct server *srv; |
| 1776 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 1777 | time_t srv_time_since_last_change; |
| 1778 | int bk_f_forced_id, srv_f_forced_id; |
Baptiste Assmann | 6d0f38f | 2018-07-02 17:00:54 +0200 | [diff] [blame] | 1779 | char *srvrecord; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1780 | |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1781 | /* we don't want to report any state if the backend is not enabled on this process */ |
Willy Tarreau | 6daac19 | 2019-02-02 17:39:53 +0100 | [diff] [blame] | 1782 | if (!(proc_mask(px->bind_proc) & pid_bit)) |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1783 | return 1; |
| 1784 | |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1785 | if (!appctx->ctx.cli.p1) |
| 1786 | appctx->ctx.cli.p1 = px->srv; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1787 | |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1788 | for (; appctx->ctx.cli.p1 != NULL; appctx->ctx.cli.p1 = srv->next) { |
| 1789 | srv = appctx->ctx.cli.p1; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1790 | srv_addr[0] = '\0'; |
| 1791 | |
| 1792 | switch (srv->addr.ss_family) { |
| 1793 | case AF_INET: |
| 1794 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 1795 | srv_addr, INET_ADDRSTRLEN + 1); |
| 1796 | break; |
| 1797 | case AF_INET6: |
| 1798 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 1799 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 1800 | break; |
Daniel Corbett | 9215ffa | 2018-05-19 19:43:24 -0400 | [diff] [blame] | 1801 | default: |
| 1802 | memcpy(srv_addr, "-\0", 2); |
| 1803 | break; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1804 | } |
| 1805 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1806 | bk_f_forced_id = px->options & PR_O_FORCED_ID ? 1 : 0; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1807 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 1808 | |
Baptiste Assmann | 6d0f38f | 2018-07-02 17:00:54 +0200 | [diff] [blame] | 1809 | srvrecord = NULL; |
| 1810 | if (srv->srvrq && srv->srvrq->name) |
| 1811 | srvrecord = srv->srvrq->name; |
| 1812 | |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 1813 | if (appctx->ctx.cli.o0 == 0) { |
| 1814 | /* show servers state */ |
| 1815 | chunk_printf(&trash, |
| 1816 | "%d %s " |
| 1817 | "%d %s %s " |
| 1818 | "%d %d %d %d %ld " |
| 1819 | "%d %d %d %d %d " |
| 1820 | "%d %d %s %u %s" |
| 1821 | "\n", |
| 1822 | px->uuid, px->id, |
| 1823 | srv->puid, srv->id, srv_addr, |
| 1824 | srv->cur_state, srv->cur_admin, srv->uweight, srv->iweight, (long int)srv_time_since_last_change, |
| 1825 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 1826 | bk_f_forced_id, srv_f_forced_id, srv->hostname ? srv->hostname : "-", srv->svc_port, |
| 1827 | srvrecord ? srvrecord : "-"); |
| 1828 | } else { |
| 1829 | /* show servers conn */ |
| 1830 | int thr; |
| 1831 | |
| 1832 | chunk_printf(&trash, |
| 1833 | "%s/%s %d/%d %s %u - %u %u %u %u %u %u %d %u", |
| 1834 | px->id, srv->id, px->uuid, srv->puid, srv_addr,srv->svc_port, |
| 1835 | srv->pool_purge_delay, |
| 1836 | srv->curr_used_conns, srv->max_used_conns, srv->est_need_conns, |
| 1837 | srv->curr_idle_nb, srv->curr_safe_nb, (int)srv->max_idle_conns, srv->curr_idle_conns); |
| 1838 | |
Willy Tarreau | 42abe68 | 2020-07-02 15:19:57 +0200 | [diff] [blame] | 1839 | for (thr = 0; thr < global.nbthread && srv->curr_idle_thr; thr++) |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 1840 | chunk_appendf(&trash, " %u", srv->curr_idle_thr[thr]); |
| 1841 | |
| 1842 | chunk_appendf(&trash, "\n"); |
| 1843 | } |
| 1844 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1845 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 1846 | si_rx_room_blk(si); |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1847 | return 0; |
| 1848 | } |
| 1849 | } |
| 1850 | return 1; |
| 1851 | } |
| 1852 | |
| 1853 | /* Parses backend list or simply use backend name provided by the user to return |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1854 | * states of servers to stdout. It dumps proxy <cli.p0> and stops if <cli.i0> is |
| 1855 | * non-null. |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1856 | */ |
| 1857 | static int cli_io_handler_servers_state(struct appctx *appctx) |
| 1858 | { |
| 1859 | struct stream_interface *si = appctx->owner; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1860 | struct proxy *curproxy; |
| 1861 | |
| 1862 | chunk_reset(&trash); |
| 1863 | |
| 1864 | if (appctx->st2 == STAT_ST_INIT) { |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1865 | if (!appctx->ctx.cli.p0) |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1866 | appctx->ctx.cli.p0 = proxies_list; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1867 | appctx->st2 = STAT_ST_HEAD; |
| 1868 | } |
| 1869 | |
| 1870 | if (appctx->st2 == STAT_ST_HEAD) { |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 1871 | if (appctx->ctx.cli.o0 == 0) |
| 1872 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 1873 | else |
| 1874 | chunk_printf(&trash, |
| 1875 | "# bkname/svname bkid/svid addr port - purge_delay used_cur used_max need_est unsafe_nb safe_nb idle_lim idle_cur idle_per_thr[%d]\n", |
| 1876 | global.nbthread); |
| 1877 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1878 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 1879 | si_rx_room_blk(si); |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1880 | return 0; |
| 1881 | } |
| 1882 | appctx->st2 = STAT_ST_INFO; |
| 1883 | } |
| 1884 | |
| 1885 | /* STAT_ST_INFO */ |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1886 | for (; appctx->ctx.cli.p0 != NULL; appctx->ctx.cli.p0 = curproxy->next) { |
| 1887 | curproxy = appctx->ctx.cli.p0; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1888 | /* servers are only in backends */ |
| 1889 | if (curproxy->cap & PR_CAP_BE) { |
Willy Tarreau | 6ff8143 | 2020-07-01 07:02:42 +0200 | [diff] [blame] | 1890 | if (!dump_servers_state(si)) |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1891 | return 0; |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1892 | } |
| 1893 | /* only the selected proxy is dumped */ |
Willy Tarreau | 3c92f2a | 2016-12-16 18:23:39 +0100 | [diff] [blame] | 1894 | if (appctx->ctx.cli.i0) |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1895 | break; |
| 1896 | } |
| 1897 | |
| 1898 | return 1; |
| 1899 | } |
| 1900 | |
Willy Tarreau | 608ea59 | 2016-12-16 18:01:15 +0100 | [diff] [blame] | 1901 | /* Parses backend list and simply report backend names. It keeps the proxy |
| 1902 | * pointer in cli.p0. |
| 1903 | */ |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1904 | static int cli_io_handler_show_backend(struct appctx *appctx) |
| 1905 | { |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1906 | struct stream_interface *si = appctx->owner; |
| 1907 | struct proxy *curproxy; |
| 1908 | |
| 1909 | chunk_reset(&trash); |
| 1910 | |
Willy Tarreau | 608ea59 | 2016-12-16 18:01:15 +0100 | [diff] [blame] | 1911 | if (!appctx->ctx.cli.p0) { |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1912 | chunk_printf(&trash, "# name\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1913 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 1914 | si_rx_room_blk(si); |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1915 | return 0; |
| 1916 | } |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1917 | appctx->ctx.cli.p0 = proxies_list; |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1918 | } |
| 1919 | |
Willy Tarreau | 608ea59 | 2016-12-16 18:01:15 +0100 | [diff] [blame] | 1920 | for (; appctx->ctx.cli.p0 != NULL; appctx->ctx.cli.p0 = curproxy->next) { |
| 1921 | curproxy = appctx->ctx.cli.p0; |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1922 | |
| 1923 | /* looking for backends only */ |
| 1924 | if (!(curproxy->cap & PR_CAP_BE)) |
| 1925 | continue; |
| 1926 | |
| 1927 | /* we don't want to list a backend which is bound to this process */ |
Willy Tarreau | 6daac19 | 2019-02-02 17:39:53 +0100 | [diff] [blame] | 1928 | if (!(proc_mask(curproxy->bind_proc) & pid_bit)) |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1929 | continue; |
| 1930 | |
| 1931 | chunk_appendf(&trash, "%s\n", curproxy->id); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1932 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 1933 | si_rx_room_blk(si); |
William Lallemand | 933efcd | 2016-11-22 12:34:16 +0100 | [diff] [blame] | 1934 | return 0; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | return 1; |
| 1939 | } |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 1940 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 1941 | /* Parses the "enable dynamic-cookies backend" directive, it always returns 1. |
| 1942 | * |
| 1943 | * Grabs the proxy lock and each server's lock. |
| 1944 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1945 | static int cli_parse_enable_dyncookie_backend(char **args, char *payload, struct appctx *appctx, void *private) |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1946 | { |
| 1947 | struct proxy *px; |
| 1948 | struct server *s; |
| 1949 | |
| 1950 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1951 | return 1; |
| 1952 | |
| 1953 | px = cli_find_backend(appctx, args[3]); |
| 1954 | if (!px) |
| 1955 | return 1; |
| 1956 | |
Willy Tarreau | 5e83d99 | 2019-07-30 11:59:34 +0200 | [diff] [blame] | 1957 | /* Note: this lock is to make sure this doesn't change while another |
| 1958 | * thread is in srv_set_dyncookie(). |
| 1959 | */ |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1960 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1961 | px->ck_opts |= PR_CK_DYNAMIC; |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1962 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1963 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 1964 | for (s = px->srv; s != NULL; s = s->next) { |
| 1965 | HA_SPIN_LOCK(SERVER_LOCK, &s->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1966 | srv_set_dyncookie(s); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 1967 | HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); |
| 1968 | } |
| 1969 | |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1970 | return 1; |
| 1971 | } |
| 1972 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 1973 | /* Parses the "disable dynamic-cookies backend" directive, it always returns 1. |
| 1974 | * |
| 1975 | * Grabs the proxy lock and each server's lock. |
| 1976 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1977 | static int cli_parse_disable_dyncookie_backend(char **args, char *payload, struct appctx *appctx, void *private) |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1978 | { |
| 1979 | struct proxy *px; |
| 1980 | struct server *s; |
| 1981 | |
| 1982 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1983 | return 1; |
| 1984 | |
| 1985 | px = cli_find_backend(appctx, args[3]); |
| 1986 | if (!px) |
| 1987 | return 1; |
| 1988 | |
Willy Tarreau | 5e83d99 | 2019-07-30 11:59:34 +0200 | [diff] [blame] | 1989 | /* Note: this lock is to make sure this doesn't change while another |
| 1990 | * thread is in srv_set_dyncookie(). |
| 1991 | */ |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1992 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1993 | px->ck_opts &= ~PR_CK_DYNAMIC; |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 1994 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1995 | |
| 1996 | for (s = px->srv; s != NULL; s = s->next) { |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 1997 | HA_SPIN_LOCK(SERVER_LOCK, &s->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 1998 | if (!(s->flags & SRV_F_COOKIESET)) { |
| 1999 | free(s->cookie); |
| 2000 | s->cookie = NULL; |
| 2001 | } |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2002 | HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | return 1; |
| 2006 | } |
| 2007 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2008 | /* Parses the "set dynamic-cookie-key backend" directive, it always returns 1. |
| 2009 | * |
| 2010 | * Grabs the proxy lock and each server's lock. |
| 2011 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 2012 | static int cli_parse_set_dyncookie_key_backend(char **args, char *payload, struct appctx *appctx, void *private) |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2013 | { |
| 2014 | struct proxy *px; |
| 2015 | struct server *s; |
| 2016 | char *newkey; |
| 2017 | |
| 2018 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 2019 | return 1; |
| 2020 | |
| 2021 | px = cli_find_backend(appctx, args[3]); |
| 2022 | if (!px) |
| 2023 | return 1; |
| 2024 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2025 | if (!*args[4]) |
| 2026 | return cli_err(appctx, "String value expected.\n"); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2027 | |
| 2028 | newkey = strdup(args[4]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2029 | if (!newkey) |
| 2030 | return cli_err(appctx, "Failed to allocate memory.\n"); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2031 | |
Willy Tarreau | 5e83d99 | 2019-07-30 11:59:34 +0200 | [diff] [blame] | 2032 | /* Note: this lock is to make sure this doesn't change while another |
| 2033 | * thread is in srv_set_dyncookie(). |
| 2034 | */ |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2035 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2036 | free(px->dyncookie_key); |
| 2037 | px->dyncookie_key = newkey; |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2038 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2039 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2040 | for (s = px->srv; s != NULL; s = s->next) { |
| 2041 | HA_SPIN_LOCK(SERVER_LOCK, &s->lock); |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2042 | srv_set_dyncookie(s); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2043 | HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); |
| 2044 | } |
| 2045 | |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2046 | return 1; |
| 2047 | } |
| 2048 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2049 | /* Parses the "set maxconn frontend" directive, it always returns 1. |
| 2050 | * |
| 2051 | * Grabs the proxy lock. |
| 2052 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 2053 | static int cli_parse_set_maxconn_frontend(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2054 | { |
| 2055 | struct proxy *px; |
| 2056 | struct listener *l; |
| 2057 | int v; |
| 2058 | |
| 2059 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 2060 | return 1; |
| 2061 | |
| 2062 | px = cli_find_frontend(appctx, args[3]); |
| 2063 | if (!px) |
| 2064 | return 1; |
| 2065 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2066 | if (!*args[4]) |
| 2067 | return cli_err(appctx, "Integer value expected.\n"); |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2068 | |
| 2069 | v = atoi(args[4]); |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2070 | if (v < 0) |
| 2071 | return cli_err(appctx, "Value out of range.\n"); |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2072 | |
| 2073 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 2074 | * its listeners. The blocked ones will be dequeued. |
| 2075 | */ |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2076 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2077 | |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2078 | px->maxconn = v; |
| 2079 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2080 | if (l->state == LI_FULL) |
| 2081 | resume_listener(l); |
| 2082 | } |
| 2083 | |
Willy Tarreau | 241797a | 2019-12-10 14:10:52 +0100 | [diff] [blame] | 2084 | if (px->maxconn > px->feconn) |
| 2085 | dequeue_proxy_listeners(px); |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2086 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2087 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2088 | |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2089 | return 1; |
| 2090 | } |
| 2091 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2092 | /* Parses the "shutdown frontend" directive, it always returns 1. |
| 2093 | * |
| 2094 | * Grabs the proxy lock. |
| 2095 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 2096 | static int cli_parse_shutdown_frontend(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 5212d7f | 2016-11-24 11:13:06 +0100 | [diff] [blame] | 2097 | { |
| 2098 | struct proxy *px; |
| 2099 | |
| 2100 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 2101 | return 1; |
| 2102 | |
| 2103 | px = cli_find_frontend(appctx, args[2]); |
| 2104 | if (!px) |
| 2105 | return 1; |
| 2106 | |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 2107 | if (px->disabled) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2108 | return cli_msg(appctx, LOG_NOTICE, "Frontend was already shut down.\n"); |
Willy Tarreau | 5212d7f | 2016-11-24 11:13:06 +0100 | [diff] [blame] | 2109 | |
Willy Tarreau | 5212d7f | 2016-11-24 11:13:06 +0100 | [diff] [blame] | 2110 | stop_proxy(px); |
| 2111 | return 1; |
| 2112 | } |
| 2113 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2114 | /* Parses the "disable frontend" directive, it always returns 1. |
| 2115 | * |
| 2116 | * Grabs the proxy lock. |
| 2117 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 2118 | static int cli_parse_disable_frontend(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2119 | { |
| 2120 | struct proxy *px; |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2121 | int ret; |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2122 | |
| 2123 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 2124 | return 1; |
| 2125 | |
| 2126 | px = cli_find_frontend(appctx, args[2]); |
| 2127 | if (!px) |
| 2128 | return 1; |
| 2129 | |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 2130 | if (px->disabled) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2131 | return cli_msg(appctx, LOG_NOTICE, "Frontend was previously shut down, cannot disable.\n"); |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2132 | |
Willy Tarreau | f18d968 | 2020-09-24 08:04:27 +0200 | [diff] [blame] | 2133 | if (!px->li_ready) |
| 2134 | return cli_msg(appctx, LOG_NOTICE, "All sockets are already disabled.\n"); |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2135 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2136 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2137 | ret = pause_proxy(px); |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2138 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2139 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2140 | if (!ret) |
| 2141 | return cli_err(appctx, "Failed to pause frontend, check logs for precise cause.\n"); |
| 2142 | |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2143 | return 1; |
| 2144 | } |
| 2145 | |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2146 | /* Parses the "enable frontend" directive, it always returns 1. |
| 2147 | * |
| 2148 | * Grabs the proxy lock. |
| 2149 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 2150 | static int cli_parse_enable_frontend(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2151 | { |
| 2152 | struct proxy *px; |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2153 | int ret; |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2154 | |
| 2155 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 2156 | return 1; |
| 2157 | |
| 2158 | px = cli_find_frontend(appctx, args[2]); |
| 2159 | if (!px) |
| 2160 | return 1; |
| 2161 | |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 2162 | if (px->disabled) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2163 | return cli_err(appctx, "Frontend was previously shut down, cannot enable.\n"); |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2164 | |
Willy Tarreau | f18d968 | 2020-09-24 08:04:27 +0200 | [diff] [blame] | 2165 | if (px->li_ready == px->li_all) |
| 2166 | return cli_msg(appctx, LOG_NOTICE, "All sockets are already enabled.\n"); |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2167 | |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2168 | HA_RWLOCK_WRLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2169 | ret = resume_proxy(px); |
Willy Tarreau | ac66d6b | 2020-10-20 17:24:27 +0200 | [diff] [blame] | 2170 | HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock); |
Willy Tarreau | a275a37 | 2018-08-21 14:50:44 +0200 | [diff] [blame] | 2171 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2172 | if (!ret) |
| 2173 | return cli_err(appctx, "Failed to resume frontend, check logs for precise cause (port conflict?).\n"); |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2174 | return 1; |
| 2175 | } |
| 2176 | |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2177 | /* "show errors" handler for the CLI. Returns 0 if wants to continue, 1 to stop |
| 2178 | * now. |
| 2179 | */ |
| 2180 | static int cli_parse_show_errors(char **args, char *payload, struct appctx *appctx, void *private) |
| 2181 | { |
| 2182 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 2183 | return 1; |
| 2184 | |
| 2185 | if (*args[2]) { |
| 2186 | struct proxy *px; |
| 2187 | |
| 2188 | px = proxy_find_by_name(args[2], 0, 0); |
| 2189 | if (px) |
| 2190 | appctx->ctx.errors.iid = px->uuid; |
| 2191 | else |
| 2192 | appctx->ctx.errors.iid = atoi(args[2]); |
| 2193 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 2194 | if (!appctx->ctx.errors.iid) |
| 2195 | return cli_err(appctx, "No such proxy.\n"); |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2196 | } |
| 2197 | else |
| 2198 | appctx->ctx.errors.iid = -1; // dump all proxies |
| 2199 | |
| 2200 | appctx->ctx.errors.flag = 0; |
| 2201 | if (strcmp(args[3], "request") == 0) |
| 2202 | appctx->ctx.errors.flag |= 4; // ignore response |
| 2203 | else if (strcmp(args[3], "response") == 0) |
| 2204 | appctx->ctx.errors.flag |= 2; // ignore request |
| 2205 | appctx->ctx.errors.px = NULL; |
| 2206 | return 0; |
| 2207 | } |
| 2208 | |
| 2209 | /* This function dumps all captured errors onto the stream interface's |
| 2210 | * read buffer. It returns 0 if the output buffer is full and it needs |
| 2211 | * to be called again, otherwise non-zero. |
| 2212 | */ |
| 2213 | static int cli_io_handler_show_errors(struct appctx *appctx) |
| 2214 | { |
| 2215 | struct stream_interface *si = appctx->owner; |
| 2216 | extern const char *monthname[12]; |
| 2217 | |
| 2218 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 2219 | return 1; |
| 2220 | |
| 2221 | chunk_reset(&trash); |
| 2222 | |
| 2223 | if (!appctx->ctx.errors.px) { |
| 2224 | /* the function had not been called yet, let's prepare the |
| 2225 | * buffer for a response. |
| 2226 | */ |
| 2227 | struct tm tm; |
| 2228 | |
| 2229 | get_localtime(date.tv_sec, &tm); |
| 2230 | chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n", |
| 2231 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 2232 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 2233 | error_snapshot_id); |
| 2234 | |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2235 | if (ci_putchk(si_ic(si), &trash) == -1) |
| 2236 | goto cant_send; |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2237 | |
| 2238 | appctx->ctx.errors.px = proxies_list; |
| 2239 | appctx->ctx.errors.bol = 0; |
| 2240 | appctx->ctx.errors.ptr = -1; |
| 2241 | } |
| 2242 | |
| 2243 | /* we have two inner loops here, one for the proxy, the other one for |
| 2244 | * the buffer. |
| 2245 | */ |
| 2246 | while (appctx->ctx.errors.px) { |
| 2247 | struct error_snapshot *es; |
| 2248 | |
Willy Tarreau | 5503908 | 2020-10-20 17:38:10 +0200 | [diff] [blame] | 2249 | HA_RWLOCK_RDLOCK(PROXY_LOCK, &appctx->ctx.errors.px->lock); |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2250 | |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2251 | if ((appctx->ctx.errors.flag & 1) == 0) { |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 2252 | es = appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2253 | if (appctx->ctx.errors.flag & 2) // skip req |
| 2254 | goto next; |
| 2255 | } |
| 2256 | else { |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 2257 | es = appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2258 | if (appctx->ctx.errors.flag & 4) // skip resp |
| 2259 | goto next; |
| 2260 | } |
| 2261 | |
Willy Tarreau | c55015e | 2018-09-07 19:02:32 +0200 | [diff] [blame] | 2262 | if (!es) |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2263 | goto next; |
| 2264 | |
| 2265 | if (appctx->ctx.errors.iid >= 0 && |
| 2266 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
Olivier Houchard | bdb00c5 | 2020-03-12 15:30:17 +0100 | [diff] [blame] | 2267 | (!es->oe || es->oe->uuid != appctx->ctx.errors.iid)) |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2268 | goto next; |
| 2269 | |
| 2270 | if (appctx->ctx.errors.ptr < 0) { |
| 2271 | /* just print headers now */ |
| 2272 | |
| 2273 | char pn[INET6_ADDRSTRLEN]; |
| 2274 | struct tm tm; |
| 2275 | int port; |
| 2276 | |
| 2277 | get_localtime(es->when.tv_sec, &tm); |
| 2278 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
| 2279 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 2280 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000)); |
| 2281 | |
| 2282 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 2283 | case AF_INET: |
| 2284 | case AF_INET6: |
| 2285 | port = get_host_port(&es->src); |
| 2286 | break; |
| 2287 | default: |
| 2288 | port = 0; |
| 2289 | } |
| 2290 | |
| 2291 | switch (appctx->ctx.errors.flag & 1) { |
| 2292 | case 0: |
| 2293 | chunk_appendf(&trash, |
| 2294 | " frontend %s (#%d): invalid request\n" |
| 2295 | " backend %s (#%d)", |
| 2296 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Olivier Houchard | bdb00c5 | 2020-03-12 15:30:17 +0100 | [diff] [blame] | 2297 | (es->oe && es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 2298 | (es->oe && es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2299 | break; |
| 2300 | case 1: |
| 2301 | chunk_appendf(&trash, |
| 2302 | " backend %s (#%d): invalid response\n" |
| 2303 | " frontend %s (#%d)", |
| 2304 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Olivier Houchard | bdb00c5 | 2020-03-12 15:30:17 +0100 | [diff] [blame] | 2305 | es->oe ? es->oe->id : "<NONE>" , es->oe ? es->oe->uuid : -1); |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2306 | break; |
| 2307 | } |
| 2308 | |
| 2309 | chunk_appendf(&trash, |
| 2310 | ", server %s (#%d), event #%u, src %s:%d\n" |
| 2311 | " buffer starts at %llu (including %u out), %u free,\n" |
| 2312 | " len %u, wraps at %u, error at position %u\n", |
| 2313 | es->srv ? es->srv->id : "<NONE>", |
| 2314 | es->srv ? es->srv->puid : -1, |
| 2315 | es->ev_id, pn, port, |
| 2316 | es->buf_ofs, es->buf_out, |
| 2317 | global.tune.bufsize - es->buf_out - es->buf_len, |
| 2318 | es->buf_len, es->buf_wrap, es->buf_err); |
| 2319 | |
| 2320 | if (es->show) |
| 2321 | es->show(&trash, es); |
| 2322 | |
| 2323 | chunk_appendf(&trash, " \n"); |
| 2324 | |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2325 | if (ci_putchk(si_ic(si), &trash) == -1) |
| 2326 | goto cant_send_unlock; |
| 2327 | |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2328 | appctx->ctx.errors.ptr = 0; |
| 2329 | appctx->ctx.errors.ev_id = es->ev_id; |
| 2330 | } |
| 2331 | |
| 2332 | if (appctx->ctx.errors.ev_id != es->ev_id) { |
| 2333 | /* the snapshot changed while we were dumping it */ |
| 2334 | chunk_appendf(&trash, |
| 2335 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2336 | if (ci_putchk(si_ic(si), &trash) == -1) |
| 2337 | goto cant_send_unlock; |
| 2338 | |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2339 | goto next; |
| 2340 | } |
| 2341 | |
| 2342 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 4bc7d90 | 2018-09-07 20:07:17 +0200 | [diff] [blame] | 2343 | while (appctx->ctx.errors.ptr < es->buf_len && appctx->ctx.errors.ptr < global.tune.bufsize) { |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2344 | int newptr; |
| 2345 | int newline; |
| 2346 | |
| 2347 | newline = appctx->ctx.errors.bol; |
| 2348 | newptr = dump_text_line(&trash, es->buf, global.tune.bufsize, es->buf_len, &newline, appctx->ctx.errors.ptr); |
| 2349 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2350 | goto cant_send_unlock; |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2351 | |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2352 | if (ci_putchk(si_ic(si), &trash) == -1) |
| 2353 | goto cant_send_unlock; |
| 2354 | |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2355 | appctx->ctx.errors.ptr = newptr; |
| 2356 | appctx->ctx.errors.bol = newline; |
| 2357 | }; |
| 2358 | next: |
Willy Tarreau | 5503908 | 2020-10-20 17:38:10 +0200 | [diff] [blame] | 2359 | HA_RWLOCK_RDUNLOCK(PROXY_LOCK, &appctx->ctx.errors.px->lock); |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2360 | appctx->ctx.errors.bol = 0; |
| 2361 | appctx->ctx.errors.ptr = -1; |
| 2362 | appctx->ctx.errors.flag ^= 1; |
| 2363 | if (!(appctx->ctx.errors.flag & 1)) |
| 2364 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
| 2365 | } |
| 2366 | |
| 2367 | /* dump complete */ |
| 2368 | return 1; |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2369 | |
| 2370 | cant_send_unlock: |
Willy Tarreau | 5503908 | 2020-10-20 17:38:10 +0200 | [diff] [blame] | 2371 | HA_RWLOCK_RDUNLOCK(PROXY_LOCK, &appctx->ctx.errors.px->lock); |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2372 | cant_send: |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 2373 | si_rx_room_blk(si); |
Willy Tarreau | 36b2736 | 2018-09-07 19:55:44 +0200 | [diff] [blame] | 2374 | return 0; |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2375 | } |
| 2376 | |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 2377 | /* register cli keywords */ |
| 2378 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | 15b9e68 | 2016-11-24 11:55:28 +0100 | [diff] [blame] | 2379 | { { "disable", "frontend", NULL }, "disable frontend : temporarily disable specific frontend", cli_parse_disable_frontend, NULL, NULL }, |
| 2380 | { { "enable", "frontend", NULL }, "enable frontend : re-enable specific frontend", cli_parse_enable_frontend, NULL, NULL }, |
Willy Tarreau | c429a1f | 2016-11-23 16:22:04 +0100 | [diff] [blame] | 2381 | { { "set", "maxconn", "frontend", NULL }, "set maxconn frontend : change a frontend's maxconn setting", cli_parse_set_maxconn_frontend, NULL }, |
Willy Tarreau | 69f591e | 2020-07-01 07:00:59 +0200 | [diff] [blame] | 2382 | { { "show","servers", "conn", NULL }, "show servers conn [id]: dump server connections status (for backend <id>)", cli_parse_show_servers, cli_io_handler_servers_state }, |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 2383 | { { "show","servers", "state", NULL }, "show servers state [id]: dump volatile server information (for backend <id>)", cli_parse_show_servers, cli_io_handler_servers_state }, |
Willy Tarreau | 608ea59 | 2016-12-16 18:01:15 +0100 | [diff] [blame] | 2384 | { { "show", "backend", NULL }, "show backend : list backends in the current running config", NULL, cli_io_handler_show_backend }, |
Willy Tarreau | 5212d7f | 2016-11-24 11:13:06 +0100 | [diff] [blame] | 2385 | { { "shutdown", "frontend", NULL }, "shutdown frontend : stop a specific frontend", cli_parse_shutdown_frontend, NULL, NULL }, |
Olivier Houchard | 614f8d7 | 2017-03-14 20:08:46 +0100 | [diff] [blame] | 2386 | { { "set", "dynamic-cookie-key", "backend", NULL }, "set dynamic-cookie-key backend : change a backend secret key for dynamic cookies", cli_parse_set_dyncookie_key_backend, NULL }, |
| 2387 | { { "enable", "dynamic-cookie", "backend", NULL }, "enable dynamic-cookie backend : enable dynamic cookies on a specific backend", cli_parse_enable_dyncookie_backend, NULL }, |
| 2388 | { { "disable", "dynamic-cookie", "backend", NULL }, "disable dynamic-cookie backend : disable dynamic cookies on a specific backend", cli_parse_disable_dyncookie_backend, NULL }, |
Willy Tarreau | ddb68ac | 2018-09-07 18:34:24 +0200 | [diff] [blame] | 2389 | { { "show", "errors", NULL }, "show errors : report last request and response errors for each proxy", cli_parse_show_errors, cli_io_handler_show_errors, NULL }, |
William Lallemand | a6c5f33 | 2016-11-19 02:25:36 +0100 | [diff] [blame] | 2390 | {{},} |
| 2391 | }}; |
| 2392 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 2393 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2394 | |
| 2395 | /* |
| 2396 | * Local variables: |
| 2397 | * c-indent-level: 8 |
| 2398 | * c-basic-offset: 8 |
| 2399 | * End: |
| 2400 | */ |