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 | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 25 | #include <common/chunk.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/compat.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 27 | #include <common/config.h> |
Willy Tarreau | 8b0cbf9 | 2010-10-15 23:23:19 +0200 | [diff] [blame] | 28 | #include <common/debug.h> |
| 29 | #include <common/standard.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 30 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 34 | #include <proto/acl.h> |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 35 | #include <proto/arg.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 36 | #include <proto/channel.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 37 | #include <proto/fd.h> |
Willy Tarreau | 03fa5df | 2010-05-24 21:02:37 +0200 | [diff] [blame] | 38 | #include <proto/frontend.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | #include <proto/log.h> |
Willy Tarreau | e5f20dc | 2006-12-03 15:21:35 +0100 | [diff] [blame] | 40 | #include <proto/hdr_idx.h> |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 41 | #include <proto/proto_tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/proto_http.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 43 | #include <proto/proxy.h> |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 44 | #include <proto/sample.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 45 | #include <proto/stream.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 46 | #include <proto/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | #include <proto/task.h> |
| 48 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 49 | /* 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] | 50 | * value in case of a critical failure which must cause the listener to be |
| 51 | * disabled, a positive value in case of success, or zero if it is a success |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 52 | * but the stream must be closed ASAP (eg: monitoring). It only supports |
| 53 | * streams with a connection in si[0]. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 54 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 55 | int frontend_accept(struct stream *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 56 | { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 57 | struct session *sess = s->sess; |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 58 | struct connection *conn = __objt_conn(sess->origin); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 59 | struct listener *l = sess->listener; |
| 60 | struct proxy *fe = sess->fe; |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 61 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 62 | int cfd = conn->t.sock.fd; |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 63 | |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 64 | tv_zero(&s->logs.tv_request); |
| 65 | s->logs.t_queue = -1; |
| 66 | s->logs.t_connect = -1; |
| 67 | s->logs.t_data = -1; |
| 68 | s->logs.t_close = 0; |
| 69 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 70 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 71 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 72 | |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 73 | /* FIXME: the logs are horribly complicated now, because they are |
| 74 | * defined in <p>, <p>, and later <be> and <be>. |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 75 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 76 | s->do_log = strm_log; |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 77 | |
| 78 | /* default error reporting function, may be changed by analysers */ |
| 79 | s->srv_error = default_srv_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 80 | |
Willy Tarreau | f67c978 | 2010-05-23 22:59:00 +0200 | [diff] [blame] | 81 | /* Adjust some socket options */ |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 82 | if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6) { |
Willy Tarreau | 9c3bc22 | 2010-12-24 14:49:37 +0100 | [diff] [blame] | 83 | if (setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, |
| 84 | (char *) &one, sizeof(one)) == -1) |
| 85 | goto out_return; |
Willy Tarreau | f67c978 | 2010-05-23 22:59:00 +0200 | [diff] [blame] | 86 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 87 | if (fe->options & PR_O_TCP_CLI_KA) |
Willy Tarreau | 9c3bc22 | 2010-12-24 14:49:37 +0100 | [diff] [blame] | 88 | setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, |
| 89 | (char *) &one, sizeof(one)); |
Willy Tarreau | f67c978 | 2010-05-23 22:59:00 +0200 | [diff] [blame] | 90 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 91 | if (fe->options & PR_O_TCP_NOLING) |
Willy Tarreau | ad38ace | 2013-12-15 14:19:38 +0100 | [diff] [blame] | 92 | fdtab[cfd].linger_risk = 1; |
| 93 | |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 94 | #if defined(TCP_MAXSEG) |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 95 | if (l->maxseg < 0) { |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 96 | /* we just want to reduce the current MSS by that value */ |
| 97 | int mss; |
Willy Tarreau | 7d286a0 | 2011-01-05 15:42:54 +0100 | [diff] [blame] | 98 | socklen_t mss_len = sizeof(mss); |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 99 | if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 100 | mss += l->maxseg; /* remember, it's < 0 */ |
Willy Tarreau | 48a7e72 | 2010-12-24 15:26:39 +0100 | [diff] [blame] | 101 | setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)); |
| 102 | } |
| 103 | } |
| 104 | #endif |
Willy Tarreau | 9c3bc22 | 2010-12-24 14:49:37 +0100 | [diff] [blame] | 105 | } |
Willy Tarreau | f67c978 | 2010-05-23 22:59:00 +0200 | [diff] [blame] | 106 | |
| 107 | if (global.tune.client_sndbuf) |
| 108 | setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf)); |
| 109 | |
| 110 | if (global.tune.client_rcvbuf) |
| 111 | setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf)); |
| 112 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 113 | if (unlikely(fe->nb_req_cap > 0)) { |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 114 | if ((s->req_cap = pool_alloc2(fe->req_cap_pool)) == NULL) |
Willy Tarreau | 9654e57 | 2014-11-18 18:49:19 +0100 | [diff] [blame] | 115 | goto out_return; /* no memory */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 116 | memset(s->req_cap, 0, fe->nb_req_cap * sizeof(void *)); |
Willy Tarreau | 9654e57 | 2014-11-18 18:49:19 +0100 | [diff] [blame] | 117 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 118 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 119 | if (unlikely(fe->nb_rsp_cap > 0)) { |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 120 | if ((s->res_cap = pool_alloc2(fe->rsp_cap_pool)) == NULL) |
Willy Tarreau | 9654e57 | 2014-11-18 18:49:19 +0100 | [diff] [blame] | 121 | goto out_free_reqcap; /* no memory */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 122 | memset(s->res_cap, 0, fe->nb_rsp_cap * sizeof(void *)); |
Willy Tarreau | 9654e57 | 2014-11-18 18:49:19 +0100 | [diff] [blame] | 123 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 124 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 125 | if (fe->http_needed) { |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 126 | /* we have to allocate header indexes only if we know |
| 127 | * that we may make use of them. This of course includes |
| 128 | * (mode == PR_MODE_HTTP). |
Willy Tarreau | 042cc79 | 2007-03-19 16:20:06 +0100 | [diff] [blame] | 129 | */ |
Willy Tarreau | ac1932d | 2011-10-24 19:14:41 +0200 | [diff] [blame] | 130 | s->txn.hdr_idx.size = global.tune.max_http_hdr; |
Willy Tarreau | 45e73e3 | 2006-12-17 00:05:15 +0100 | [diff] [blame] | 131 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 132 | if (unlikely((s->txn.hdr_idx.v = pool_alloc2(pool2_hdr_idx)) == NULL)) |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 133 | goto out_free_rspcap; /* no memory */ |
Willy Tarreau | 45e73e3 | 2006-12-17 00:05:15 +0100 | [diff] [blame] | 134 | |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 135 | /* and now initialize the HTTP transaction state */ |
| 136 | http_init_txn(s); |
| 137 | } |
Willy Tarreau | e5f20dc | 2006-12-03 15:21:35 +0100 | [diff] [blame] | 138 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 139 | if ((fe->mode == PR_MODE_TCP || fe->mode == PR_MODE_HTTP) |
| 140 | && (!LIST_ISEMPTY(&fe->logsrvs))) { |
| 141 | if (likely(!LIST_ISEMPTY(&fe->logformat))) { |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 142 | /* we have the client ip */ |
| 143 | if (s->logs.logwait & LW_CLIP) |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 144 | if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT))) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 145 | s->do_log(s); |
Willy Tarreau | a3445fc | 2010-05-20 16:17:07 +0200 | [diff] [blame] | 146 | } |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 147 | else { |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 148 | char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 14c8aac | 2007-05-08 19:46:30 +0200 | [diff] [blame] | 149 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 150 | conn_get_from_addr(conn); |
| 151 | conn_get_to_addr(conn); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 152 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 153 | switch (addr_to_str(&conn->addr.from, pn, sizeof(pn))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 154 | case AF_INET: |
| 155 | case AF_INET6: |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 156 | addr_to_str(&conn->addr.to, sn, sizeof(sn)); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 157 | send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 158 | pn, get_host_port(&conn->addr.from), |
| 159 | sn, get_host_port(&conn->addr.to), |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 160 | fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 161 | break; |
| 162 | case AF_UNIX: |
| 163 | /* UNIX socket, only the destination is known */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 164 | send_log(fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n", |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 165 | l->luid, |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 166 | fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP"); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 167 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 168 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 169 | } |
| 170 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | |
Willy Tarreau | 2281b7f | 2010-05-28 19:29:49 +0200 | [diff] [blame] | 172 | if (unlikely((global.mode & MODE_DEBUG) && (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 173 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 174 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 175 | conn_get_from_addr(conn); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 176 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 177 | switch (addr_to_str(&conn->addr.from, pn, sizeof(pn))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 178 | case AF_INET: |
| 179 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 180 | chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n", |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 181 | s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)cfd, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 182 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 183 | break; |
| 184 | case AF_UNIX: |
| 185 | /* UNIX socket, only the destination is known */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 186 | chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d]\n", |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 187 | s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)cfd, |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 188 | l->luid); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 189 | break; |
Emeric Brun | ab844ea | 2010-10-22 16:33:18 +0200 | [diff] [blame] | 190 | } |
Willy Tarreau | 9a2d154 | 2008-08-30 12:31:07 +0200 | [diff] [blame] | 191 | |
Willy Tarreau | 89efaed | 2013-12-13 15:14:55 +0100 | [diff] [blame] | 192 | shut_your_big_mouth_gcc(write(1, trash.str, trash.len)); |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 193 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 194 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 195 | if (fe->mode == PR_MODE_HTTP) |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 196 | s->req.flags |= CF_READ_DONTWAIT; /* one read is usually enough */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 198 | /* note: this should not happen anymore since there's always at least the switching rules */ |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 199 | if (!s->req.analysers) { |
| 200 | channel_auto_connect(&s->req); /* don't wait to establish connection */ |
| 201 | channel_auto_close(&s->req); /* let the producer forward close requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 202 | } |
Willy Tarreau | d797128 | 2006-07-29 18:36:34 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 204 | s->req.rto = fe->timeout.client; |
| 205 | s->res.wto = fe->timeout.client; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 206 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 207 | /* everything's OK, let's go on */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 208 | return 1; |
Willy Tarreau | 8ced9a4 | 2007-11-04 17:51:50 +0100 | [diff] [blame] | 209 | |
| 210 | /* Error unrolling */ |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 211 | out_free_rspcap: |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 212 | pool_free2(fe->rsp_cap_pool, s->res_cap); |
Willy Tarreau | 35a0994 | 2010-06-01 17:12:40 +0200 | [diff] [blame] | 213 | out_free_reqcap: |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame^] | 214 | pool_free2(fe->req_cap_pool, s->req_cap); |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 215 | out_return: |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 216 | return -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 219 | /************************************************************************/ |
| 220 | /* All supported sample and ACL keywords must be declared here. */ |
| 221 | /************************************************************************/ |
| 222 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 223 | /* set temp integer to the id of the frontend */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 224 | static int |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 225 | smp_fetch_fe_id(struct proxy *px, struct stream *l4, void *l7, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 226 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 227 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 228 | smp->flags = SMP_F_VOL_SESS; |
| 229 | smp->type = SMP_T_UINT; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 230 | smp->data.uint = strm_sess(l4)->fe->uuid; |
Emeric Brun | 5d16eda | 2010-01-04 15:47:45 +0100 | [diff] [blame] | 231 | return 1; |
| 232 | } |
| 233 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 234 | /* 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] | 235 | * Accepts exactly 1 argument. Argument is a frontend, other types will cause |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 236 | * an undefined behaviour. |
| 237 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 238 | static int |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 239 | smp_fetch_fe_sess_rate(struct proxy *px, struct stream *l4, void *l7, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 240 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 662b2d8 | 2007-05-08 19:56:15 +0200 | [diff] [blame] | 241 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 242 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 243 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 244 | smp->data.uint = read_freq_ctr(&args->data.prx->fe_sess_per_sec); |
Emeric Brun | 5d16eda | 2010-01-04 15:47:45 +0100 | [diff] [blame] | 245 | return 1; |
| 246 | } |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 247 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 248 | /* set temp integer to the number of concurrent connections on the frontend |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 249 | * Accepts exactly 1 argument. Argument is a frontend, other types will cause |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 250 | * an undefined behaviour. |
| 251 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 252 | static int |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 253 | smp_fetch_fe_conn(struct proxy *px, struct stream *l4, void *l7, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 254 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 255 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 256 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 257 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 258 | smp->data.uint = args->data.prx->feconn; |
Krzysztof Piotr Oledzki | 346f76d | 2010-01-12 21:59:30 +0100 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 262 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 263 | /* Note: must not be declared <const> as its list will be overwritten. |
| 264 | * Please take care of keeping this list alphabetically sorted. |
| 265 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 266 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 267 | { "fe_conn", smp_fetch_fe_conn, ARG1(1,FE), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 268 | { "fe_id", smp_fetch_fe_id, 0, NULL, SMP_T_UINT, SMP_USE_FTEND, }, |
| 269 | { "fe_sess_rate", smp_fetch_fe_sess_rate, ARG1(1,FE), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 270 | { /* END */ }, |
| 271 | }}; |
| 272 | |
| 273 | |
| 274 | /* Note: must not be declared <const> as its list will be overwritten. |
| 275 | * Please take care of keeping this list alphabetically sorted. |
| 276 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 277 | static struct acl_kw_list acl_kws = {ILH, { |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 278 | { /* END */ }, |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 279 | }}; |
| 280 | |
| 281 | |
| 282 | __attribute__((constructor)) |
Willy Tarreau | 03fa5df | 2010-05-24 21:02:37 +0200 | [diff] [blame] | 283 | static void __frontend_init(void) |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 284 | { |
Willy Tarreau | d6896bc | 2013-01-07 22:48:29 +0100 | [diff] [blame] | 285 | sample_register_fetches(&smp_kws); |
Willy Tarreau | 8797c06 | 2007-05-07 00:55:35 +0200 | [diff] [blame] | 286 | acl_register_keywords(&acl_kws); |
| 287 | } |
| 288 | |
| 289 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 290 | /* |
| 291 | * Local variables: |
| 292 | * c-indent-level: 8 |
| 293 | * c-basic-offset: 8 |
| 294 | * End: |
| 295 | */ |