Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 03fa5df | 2010-05-24 21:02:37 +0200 | [diff] [blame] | 2 | * Frontend variables and functions. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 4 | * Copyright 2000-2013 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 <errno.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 17 | #include <string.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 18 | |
| 19 | #include <sys/socket.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 23 | #include <netinet/tcp.h> |
| 24 | |
Willy Tarreau | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 25 | #include <haproxy/acl.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 26 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 27 | #include <haproxy/arg.h> |
Willy Tarreau | c13ed53 | 2020-06-02 10:22:45 +0200 | [diff] [blame] | 28 | #include <haproxy/chunk.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 29 | #include <haproxy/fd.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 30 | #include <haproxy/frontend.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +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 | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 33 | #include <haproxy/log.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 34 | #include <haproxy/proto_tcp.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 35 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 36 | #include <haproxy/sample.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 37 | #include <haproxy/stream.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 38 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 39 | #include <haproxy/task.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 40 | #include <haproxy/time.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 41 | #include <haproxy/tools.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 44 | /* Finish a stream accept() for a proxy (TCP or HTTP). It returns a negative |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 45 | * value in case of a critical failure which must cause the listener to be |
Willy Tarreau | e0232f1 | 2015-04-05 18:01:06 +0200 | [diff] [blame] | 46 | * disabled, a positive or null value in case of success. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 48 | int frontend_accept(struct stream *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 49 | { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 50 | struct session *sess = s->sess; |
Willy Tarreau | e0232f1 | 2015-04-05 18:01:06 +0200 | [diff] [blame] | 51 | struct connection *conn = objt_conn(sess->origin); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 52 | struct listener *l = sess->listener; |
| 53 | struct proxy *fe = sess->fe; |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 55 | if ((fe->mode == PR_MODE_TCP || fe->mode == PR_MODE_HTTP) |
| 56 | && (!LIST_ISEMPTY(&fe->logsrvs))) { |
| 57 | if (likely(!LIST_ISEMPTY(&fe->logformat))) { |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 58 | /* we have the client ip */ |
| 59 | if (s->logs.logwait & LW_CLIP) |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 60 | if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT))) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 61 | s->do_log(s); |
Willy Tarreau | a3445fc | 2010-05-20 16:17:07 +0200 | [diff] [blame] | 62 | } |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 63 | else if (conn && !conn_get_src(conn)) { |
| 64 | send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n", |
| 65 | l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
| 66 | } |
Willy Tarreau | e0232f1 | 2015-04-05 18:01:06 +0200 | [diff] [blame] | 67 | else if (conn) { |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 68 | char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN]; |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 69 | int port; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 70 | |
Willy Tarreau | 44a7d8e | 2019-07-17 17:11:40 +0200 | [diff] [blame] | 71 | switch (addr_to_str(conn->src, pn, sizeof(pn))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 72 | case AF_INET: |
| 73 | case AF_INET6: |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 74 | if (conn_get_dst(conn)) { |
Willy Tarreau | 44a7d8e | 2019-07-17 17:11:40 +0200 | [diff] [blame] | 75 | addr_to_str(conn->dst, sn, sizeof(sn)); |
| 76 | port = get_host_port(conn->dst); |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 77 | } else { |
| 78 | strcpy(sn, "undetermined address"); |
| 79 | port = 0; |
| 80 | } |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 81 | send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n", |
Willy Tarreau | 44a7d8e | 2019-07-17 17:11:40 +0200 | [diff] [blame] | 82 | pn, get_host_port(conn->src), |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 83 | sn, port, |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 84 | fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 85 | break; |
| 86 | case AF_UNIX: |
| 87 | /* UNIX socket, only the destination is known */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 88 | send_log(fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n", |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 89 | l->luid, |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 90 | fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 91 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 93 | } |
| 94 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 95 | |
Willy Tarreau | e0232f1 | 2015-04-05 18:01:06 +0200 | [diff] [blame] | 96 | if (unlikely((global.mode & MODE_DEBUG) && conn && |
| 97 | (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 98 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 9c26680 | 2016-12-04 19:05:24 +0100 | [diff] [blame] | 99 | char alpn[16] = "<none>"; |
Willy Tarreau | 20814ff | 2017-09-15 11:43:32 +0200 | [diff] [blame] | 100 | const char *alpn_str = NULL; |
| 101 | int alpn_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 102 | |
Willy Tarreau | 20814ff | 2017-09-15 11:43:32 +0200 | [diff] [blame] | 103 | /* try to report the ALPN value when available (also works for NPN) */ |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 104 | if (conn == cs_conn(objt_cs(s->si[0].end))) { |
Willy Tarreau | 20814ff | 2017-09-15 11:43:32 +0200 | [diff] [blame] | 105 | if (conn_get_alpn(conn, &alpn_str, &alpn_len) && alpn_str) { |
| 106 | int len = MIN(alpn_len, sizeof(alpn) - 1); |
| 107 | memcpy(alpn, alpn_str, len); |
| 108 | alpn[len] = 0; |
| 109 | } |
Willy Tarreau | 9c26680 | 2016-12-04 19:05:24 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 112 | if (!conn_get_src(conn)) { |
| 113 | chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n", |
Willy Tarreau | 38ba647 | 2020-08-27 08:16:52 +0200 | [diff] [blame] | 114 | s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, |
Willy Tarreau | a0a4b09 | 2019-07-17 11:25:46 +0200 | [diff] [blame] | 115 | l->luid, alpn); |
| 116 | } |
Willy Tarreau | 44a7d8e | 2019-07-17 17:11:40 +0200 | [diff] [blame] | 117 | else switch (addr_to_str(conn->src, pn, sizeof(pn))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 118 | case AF_INET: |
| 119 | case AF_INET6: |
Willy Tarreau | 9c26680 | 2016-12-04 19:05:24 +0100 | [diff] [blame] | 120 | chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n", |
Willy Tarreau | 38ba647 | 2020-08-27 08:16:52 +0200 | [diff] [blame] | 121 | s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, |
Willy Tarreau | 44a7d8e | 2019-07-17 17:11:40 +0200 | [diff] [blame] | 122 | pn, get_host_port(conn->src), alpn); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 123 | break; |
| 124 | case AF_UNIX: |
| 125 | /* UNIX socket, only the destination is known */ |
Willy Tarreau | 9c26680 | 2016-12-04 19:05:24 +0100 | [diff] [blame] | 126 | chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d] ALPN=%s\n", |
Willy Tarreau | 38ba647 | 2020-08-27 08:16:52 +0200 | [diff] [blame] | 127 | s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, |
Willy Tarreau | 9c26680 | 2016-12-04 19:05:24 +0100 | [diff] [blame] | 128 | l->luid, alpn); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 129 | break; |
Emeric Brun | ab844ea | 2010-10-22 16:33:18 +0200 | [diff] [blame] | 130 | } |
Willy Tarreau | 9a2d154 | 2008-08-30 12:31:07 +0200 | [diff] [blame] | 131 | |
Willy Tarreau | 2e8ab6b | 2020-03-14 11:03:20 +0100 | [diff] [blame] | 132 | DISGUISE(write(1, trash.area, trash.data)); |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 133 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 134 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 135 | if (fe->mode == PR_MODE_HTTP) |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 136 | s->req.flags |= CF_READ_DONTWAIT; /* one read is usually enough */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 137 | |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 138 | if (unlikely(fe->nb_req_cap > 0)) { |
Willy Tarreau | ec4cfc3 | 2021-03-22 21:06:21 +0100 | [diff] [blame] | 139 | if ((s->req_cap = pool_zalloc(fe->req_cap_pool)) == NULL) |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 140 | goto out_return; /* no memory */ |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (unlikely(fe->nb_rsp_cap > 0)) { |
Willy Tarreau | ec4cfc3 | 2021-03-22 21:06:21 +0100 | [diff] [blame] | 144 | if ((s->res_cap = pool_zalloc(fe->rsp_cap_pool)) == NULL) |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 145 | goto out_free_reqcap; /* no memory */ |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Christopher Faulet | 75f619a | 2021-03-08 19:12:58 +0100 | [diff] [blame] | 148 | if ((fe->http_needed || IS_HTX_STRM(s)) && !http_create_txn(s)) |
| 149 | goto out_free_rspcap; |
Willy Tarreau | 0a6bed2 | 2016-12-04 18:39:22 +0100 | [diff] [blame] | 150 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 151 | /* everything's OK, let's go on */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 152 | return 1; |
Willy Tarreau | 8ced9a4 | 2007-11-04 17:51:50 +0100 | [diff] [blame] | 153 | |
| 154 | /* Error unrolling */ |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 155 | out_free_rspcap: |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 156 | pool_free(fe->rsp_cap_pool, s->res_cap); |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 157 | out_free_reqcap: |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 158 | pool_free(fe->req_cap_pool, s->req_cap); |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 159 | out_return: |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 160 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 163 | /************************************************************************/ |
| 164 | /* All supported sample and ACL keywords must be declared here. */ |
| 165 | /************************************************************************/ |
| 166 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 167 | /* set temp integer to the id of the frontend */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 168 | static int |
Thierry FOURNIER | 0786d05 | 2015-05-11 15:42:45 +0200 | [diff] [blame] | 169 | smp_fetch_fe_id(const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 170 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 171 | smp->flags = SMP_F_VOL_SESS; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 172 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 173 | smp->data.u.sint = smp->sess->fe->uuid; |
Emeric Brun | 5d16eda | 2010-01-04 15:47:45 +0100 | [diff] [blame] | 174 | return 1; |
| 175 | } |
| 176 | |
Marcin Deranek | d2471c2 | 2016-12-12 14:08:05 +0100 | [diff] [blame] | 177 | /* set string to the name of the frontend */ |
| 178 | static int |
| 179 | smp_fetch_fe_name(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 180 | { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 181 | smp->data.u.str.area = (char *)smp->sess->fe->id; |
| 182 | if (!smp->data.u.str.area) |
Marcin Deranek | d2471c2 | 2016-12-12 14:08:05 +0100 | [diff] [blame] | 183 | return 0; |
| 184 | |
| 185 | smp->data.type = SMP_T_STR; |
| 186 | smp->flags = SMP_F_CONST; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 187 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
Marcin Deranek | d2471c2 | 2016-12-12 14:08:05 +0100 | [diff] [blame] | 188 | return 1; |
| 189 | } |
| 190 | |
Marcin Deranek | 9a66dfb | 2018-04-13 14:37:50 +0200 | [diff] [blame] | 191 | /* set string to the name of the default backend */ |
| 192 | static int |
| 193 | smp_fetch_fe_defbe(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 194 | { |
| 195 | if (!smp->sess->fe->defbe.be) |
| 196 | return 0; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 197 | smp->data.u.str.area = (char *)smp->sess->fe->defbe.be->id; |
| 198 | if (!smp->data.u.str.area) |
Marcin Deranek | 9a66dfb | 2018-04-13 14:37:50 +0200 | [diff] [blame] | 199 | return 0; |
| 200 | |
| 201 | smp->data.type = SMP_T_STR; |
| 202 | smp->flags = SMP_F_CONST; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 203 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
Marcin Deranek | 9a66dfb | 2018-04-13 14:37:50 +0200 | [diff] [blame] | 204 | return 1; |
| 205 | } |
| 206 | |
Nenad Merdanovic | ad9a7e9 | 2016-10-03 04:57:37 +0200 | [diff] [blame] | 207 | /* set temp integer to the number of HTTP requests per second reaching the frontend. |
| 208 | * Accepts exactly 1 argument. Argument is a frontend, other types will cause |
| 209 | * an undefined behaviour. |
| 210 | */ |
| 211 | static int |
| 212 | smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 213 | { |
| 214 | smp->flags = SMP_F_VOL_TEST; |
| 215 | smp->data.type = SMP_T_SINT; |
| 216 | smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_req_per_sec); |
| 217 | return 1; |
| 218 | } |
| 219 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 220 | /* set temp integer to the number of connections per second reaching the frontend. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 221 | * Accepts exactly 1 argument. Argument is a frontend, other types will cause |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 222 | * an undefined behaviour. |
| 223 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 224 | static int |
Thierry FOURNIER | 0786d05 | 2015-05-11 15:42:45 +0200 | [diff] [blame] | 225 | smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 662b2d8 | 2007-05-08 19:56:15 +0200 | [diff] [blame] | 226 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 227 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 228 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 229 | smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_sess_per_sec); |
Emeric Brun | 5d16eda | 2010-01-04 15:47:45 +0100 | [diff] [blame] | 230 | return 1; |
| 231 | } |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 232 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 233 | /* set temp integer to the number of concurrent connections on the frontend |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 234 | * Accepts exactly 1 argument. Argument is a frontend, other types will cause |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 235 | * an undefined behaviour. |
| 236 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 237 | static int |
Thierry FOURNIER | 0786d05 | 2015-05-11 15:42:45 +0200 | [diff] [blame] | 238 | smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 239 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 240 | smp->flags = SMP_F_VOL_TEST; |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 241 | smp->data.type = SMP_T_SINT; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 242 | smp->data.u.sint = args->data.prx->feconn; |
Krzysztof Piotr Oledzki | 346f76d | 2010-01-12 21:59:30 +0100 | [diff] [blame] | 243 | return 1; |
| 244 | } |
| 245 | |
Amaury Denoyelle | da184d5 | 2020-12-10 13:43:55 +0100 | [diff] [blame] | 246 | static int |
| 247 | smp_fetch_fe_client_timeout(const struct arg *args, struct sample *smp, const char *km, void *private) |
| 248 | { |
| 249 | smp->flags = SMP_F_VOL_TXN; |
| 250 | smp->data.type = SMP_T_SINT; |
| 251 | smp->data.u.sint = TICKS_TO_MS(smp->sess->fe->timeout.client); |
| 252 | return 1; |
| 253 | } |
| 254 | |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 255 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 256 | /* Note: must not be declared <const> as its list will be overwritten. |
| 257 | * Please take care of keeping this list alphabetically sorted. |
| 258 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 259 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
Amaury Denoyelle | da184d5 | 2020-12-10 13:43:55 +0100 | [diff] [blame] | 260 | { "fe_client_timeout", smp_fetch_fe_client_timeout, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, }, |
| 261 | { "fe_conn", smp_fetch_fe_conn, ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 262 | { "fe_defbe", smp_fetch_fe_defbe, 0, NULL, SMP_T_STR, SMP_USE_FTEND, }, |
| 263 | { "fe_id", smp_fetch_fe_id, 0, NULL, SMP_T_SINT, SMP_USE_FTEND, }, |
| 264 | { "fe_name", smp_fetch_fe_name, 0, NULL, SMP_T_STR, SMP_USE_FTEND, }, |
| 265 | { "fe_req_rate", smp_fetch_fe_req_rate, ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
| 266 | { "fe_sess_rate", smp_fetch_fe_sess_rate, ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, }, |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 267 | { /* END */ }, |
| 268 | }}; |
| 269 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 270 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws); |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 271 | |
| 272 | /* Note: must not be declared <const> as its list will be overwritten. |
| 273 | * Please take care of keeping this list alphabetically sorted. |
| 274 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 275 | static struct acl_kw_list acl_kws = {ILH, { |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 276 | { /* END */ }, |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 277 | }}; |
| 278 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 279 | INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws); |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 281 | /* |
| 282 | * Local variables: |
| 283 | * c-indent-level: 8 |
| 284 | * c-basic-offset: 8 |
| 285 | * End: |
| 286 | */ |