Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/connection.h |
| 3 | * This file contains connection function prototypes |
| 4 | * |
| 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROTO_CONNECTION_H |
| 23 | #define _PROTO_CONNECTION_H |
| 24 | |
| 25 | #include <common/config.h> |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 26 | #include <common/ist.h> |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 27 | #include <common/memory.h> |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 28 | #include <types/connection.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 29 | #include <types/listener.h> |
Willy Tarreau | 2b199c9 | 2012-11-23 17:32:21 +0100 | [diff] [blame] | 30 | #include <proto/fd.h> |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 31 | #include <proto/obj_type.h> |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 32 | #include <proto/task.h> |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 34 | extern struct pool_head *pool_head_connection; |
| 35 | extern struct pool_head *pool_head_connstream; |
Willy Tarreau | 13e1410 | 2016-12-22 20:25:26 +0100 | [diff] [blame] | 36 | extern struct xprt_ops *registered_xprt[XPRT_ENTRIES]; |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 37 | extern struct mux_proto_list mux_proto_list; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 38 | |
| 39 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 40 | int init_connection(); |
| 41 | |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 42 | /* I/O callback for fd-based connections. It calls the read/write handlers |
Willy Tarreau | 7a798e5 | 2016-04-14 11:13:20 +0200 | [diff] [blame] | 43 | * provided by the connection's sock_ops. |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 44 | */ |
Willy Tarreau | 7a798e5 | 2016-04-14 11:13:20 +0200 | [diff] [blame] | 45 | void conn_fd_handler(int fd); |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 46 | |
Willy Tarreau | 11c9aa4 | 2018-03-02 13:55:01 +0100 | [diff] [blame] | 47 | /* conn_stream functions */ |
| 48 | size_t __cs_recv(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); |
Christopher Faulet | 063f786 | 2018-05-23 15:03:43 +0200 | [diff] [blame] | 49 | size_t __cs_send(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); |
Willy Tarreau | 11c9aa4 | 2018-03-02 13:55:01 +0100 | [diff] [blame] | 50 | |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 51 | /* receive a PROXY protocol header over a connection */ |
| 52 | int conn_recv_proxy(struct connection *conn, int flag); |
David S | afb7683 | 2014-05-08 23:42:08 -0400 | [diff] [blame] | 53 | int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connection *remote); |
| 54 | int make_proxy_line_v1(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst); |
| 55 | int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connection *remote); |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 56 | |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 57 | int conn_subscribe(struct connection *conn, int event_type, void *param); |
Bertrand Jacquin | 93b227d | 2016-06-04 15:11:10 +0100 | [diff] [blame] | 58 | /* receive a NetScaler Client IP insertion header over a connection */ |
| 59 | int conn_recv_netscaler_cip(struct connection *conn, int flag); |
| 60 | |
Willy Tarreau | ff3e648 | 2015-03-12 23:56:52 +0100 | [diff] [blame] | 61 | /* raw send() directly on the socket */ |
| 62 | int conn_sock_send(struct connection *conn, const void *buf, int len, int flags); |
| 63 | |
Willy Tarreau | d85c485 | 2015-03-13 00:40:28 +0100 | [diff] [blame] | 64 | /* drains any pending bytes from the socket */ |
| 65 | int conn_sock_drain(struct connection *conn); |
| 66 | |
Willy Tarreau | d02cdd2 | 2013-12-15 10:23:20 +0100 | [diff] [blame] | 67 | /* returns true is the transport layer is ready */ |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 68 | static inline int conn_xprt_ready(const struct connection *conn) |
Willy Tarreau | d02cdd2 | 2013-12-15 10:23:20 +0100 | [diff] [blame] | 69 | { |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 70 | return (conn->flags & CO_FL_XPRT_READY); |
Willy Tarreau | d02cdd2 | 2013-12-15 10:23:20 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* returns true is the control layer is ready */ |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 74 | static inline int conn_ctrl_ready(const struct connection *conn) |
Willy Tarreau | d02cdd2 | 2013-12-15 10:23:20 +0100 | [diff] [blame] | 75 | { |
| 76 | return (conn->flags & CO_FL_CTRL_READY); |
| 77 | } |
| 78 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 79 | /* Calls the init() function of the transport layer if any and if not done yet, |
| 80 | * and sets the CO_FL_XPRT_READY flag to indicate it was properly initialized. |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 81 | * Returns <0 in case of error. |
Willy Tarreau | 15678ef | 2012-08-31 13:54:11 +0200 | [diff] [blame] | 82 | */ |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 83 | static inline int conn_xprt_init(struct connection *conn) |
Willy Tarreau | 15678ef | 2012-08-31 13:54:11 +0200 | [diff] [blame] | 84 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 85 | int ret = 0; |
| 86 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 87 | if (!conn_xprt_ready(conn) && conn->xprt && conn->xprt->init) |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 88 | ret = conn->xprt->init(conn); |
| 89 | |
| 90 | if (ret >= 0) |
| 91 | conn->flags |= CO_FL_XPRT_READY; |
| 92 | |
| 93 | return ret; |
Willy Tarreau | 15678ef | 2012-08-31 13:54:11 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 96 | /* Calls the close() function of the transport layer if any and if not done |
| 97 | * yet, and clears the CO_FL_XPRT_READY flag. However this is not done if the |
| 98 | * CO_FL_XPRT_TRACKED flag is set, which allows logs to take data from the |
| 99 | * transport layer very late if needed. |
Willy Tarreau | 6c03a64 | 2012-10-12 17:00:05 +0200 | [diff] [blame] | 100 | */ |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 101 | static inline void conn_xprt_close(struct connection *conn) |
Willy Tarreau | 8b11708 | 2012-08-06 15:06:49 +0200 | [diff] [blame] | 102 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 103 | if ((conn->flags & (CO_FL_XPRT_READY|CO_FL_XPRT_TRACKED)) == CO_FL_XPRT_READY) { |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 104 | if (conn->xprt->close) |
Willy Tarreau | 6c03a64 | 2012-10-12 17:00:05 +0200 | [diff] [blame] | 105 | conn->xprt->close(conn); |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 106 | conn->flags &= ~CO_FL_XPRT_READY; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /* Initializes the connection's control layer which essentially consists in |
| 111 | * registering the file descriptor for polling and setting the CO_FL_CTRL_READY |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 112 | * flag. The caller is responsible for ensuring that the control layer is |
| 113 | * already assigned to the connection prior to the call. |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 114 | */ |
| 115 | static inline void conn_ctrl_init(struct connection *conn) |
| 116 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 117 | if (!conn_ctrl_ready(conn)) { |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 118 | int fd = conn->handle.fd; |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 119 | |
Willy Tarreau | a9786b6 | 2018-01-25 07:22:13 +0100 | [diff] [blame] | 120 | fd_insert(fd, conn, conn_fd_handler, tid_bit); |
Willy Tarreau | f817e9f | 2014-01-10 16:58:45 +0100 | [diff] [blame] | 121 | /* mark the fd as ready so as not to needlessly poll at the beginning */ |
| 122 | fd_may_recv(fd); |
| 123 | fd_may_send(fd); |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 124 | conn->flags |= CO_FL_CTRL_READY; |
Willy Tarreau | 6c03a64 | 2012-10-12 17:00:05 +0200 | [diff] [blame] | 125 | } |
Willy Tarreau | 8b11708 | 2012-08-06 15:06:49 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 128 | /* Deletes the FD if the transport layer is already gone. Once done, |
| 129 | * it then removes the CO_FL_CTRL_READY flag. |
| 130 | */ |
| 131 | static inline void conn_ctrl_close(struct connection *conn) |
| 132 | { |
| 133 | if ((conn->flags & (CO_FL_XPRT_READY|CO_FL_CTRL_READY)) == CO_FL_CTRL_READY) { |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 134 | fd_delete(conn->handle.fd); |
Willy Tarreau | 6a0a80a | 2017-10-05 17:43:39 +0200 | [diff] [blame] | 135 | conn->handle.fd = DEAD_FD_MAGIC; |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 136 | conn->flags &= ~CO_FL_CTRL_READY; |
| 137 | } |
| 138 | } |
| 139 | |
Willy Tarreau | 2b199c9 | 2012-11-23 17:32:21 +0100 | [diff] [blame] | 140 | /* If the connection still has a transport layer, then call its close() function |
| 141 | * if any, and delete the file descriptor if a control layer is set. This is |
| 142 | * used to close everything at once and atomically. However this is not done if |
| 143 | * the CO_FL_XPRT_TRACKED flag is set, which allows logs to take data from the |
| 144 | * transport layer very late if needed. |
| 145 | */ |
| 146 | static inline void conn_full_close(struct connection *conn) |
| 147 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 148 | conn_xprt_close(conn); |
| 149 | conn_ctrl_close(conn); |
| 150 | } |
| 151 | |
Willy Tarreau | dc42acd | 2017-10-05 18:09:20 +0200 | [diff] [blame] | 152 | /* stop tracking a connection, allowing conn_full_close() to always |
| 153 | * succeed. |
| 154 | */ |
| 155 | static inline void conn_stop_tracking(struct connection *conn) |
| 156 | { |
| 157 | conn->flags &= ~CO_FL_XPRT_TRACKED; |
| 158 | } |
| 159 | |
Willy Tarreau | e9dfa79 | 2012-09-01 17:26:16 +0200 | [diff] [blame] | 160 | /* Update polling on connection <c>'s file descriptor depending on its current |
| 161 | * state as reported in the connection's CO_FL_CURR_* flags, reports of EAGAIN |
| 162 | * in CO_FL_WAIT_*, and the sock layer expectations indicated by CO_FL_SOCK_*. |
| 163 | * The connection flags are updated with the new flags at the end of the |
Willy Tarreau | 0ffde2c | 2012-10-04 22:21:15 +0200 | [diff] [blame] | 164 | * operation. Polling is totally disabled if an error was reported. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 165 | */ |
Willy Tarreau | e9dfa79 | 2012-09-01 17:26:16 +0200 | [diff] [blame] | 166 | void conn_update_sock_polling(struct connection *c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 167 | |
Willy Tarreau | e9dfa79 | 2012-09-01 17:26:16 +0200 | [diff] [blame] | 168 | /* Update polling on connection <c>'s file descriptor depending on its current |
| 169 | * state as reported in the connection's CO_FL_CURR_* flags, reports of EAGAIN |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 170 | * in CO_FL_WAIT_*, and the upper layer expectations indicated by CO_FL_XPRT_*. |
Willy Tarreau | e9dfa79 | 2012-09-01 17:26:16 +0200 | [diff] [blame] | 171 | * The connection flags are updated with the new flags at the end of the |
Willy Tarreau | 0ffde2c | 2012-10-04 22:21:15 +0200 | [diff] [blame] | 172 | * operation. Polling is totally disabled if an error was reported. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 173 | */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 174 | void conn_update_xprt_polling(struct connection *c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 175 | |
Willy Tarreau | 7d28149 | 2012-12-16 19:19:13 +0100 | [diff] [blame] | 176 | /* Refresh the connection's polling flags from its file descriptor status. |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 177 | * This should be called at the beginning of a connection handler. It does |
| 178 | * nothing if CO_FL_WILL_UPDATE is present, indicating that an upper caller |
| 179 | * has already done it. |
Willy Tarreau | 7d28149 | 2012-12-16 19:19:13 +0100 | [diff] [blame] | 180 | */ |
| 181 | static inline void conn_refresh_polling_flags(struct connection *conn) |
| 182 | { |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 183 | if (conn_ctrl_ready(conn) && !(conn->flags & CO_FL_WILL_UPDATE)) { |
Willy Tarreau | bc97cc4 | 2017-10-25 10:28:45 +0200 | [diff] [blame] | 184 | unsigned int flags = conn->flags; |
Willy Tarreau | 7d28149 | 2012-12-16 19:19:13 +0100 | [diff] [blame] | 185 | |
Willy Tarreau | bc97cc4 | 2017-10-25 10:28:45 +0200 | [diff] [blame] | 186 | flags &= ~(CO_FL_CURR_RD_ENA | CO_FL_CURR_WR_ENA | CO_FL_WAIT_ROOM); |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 187 | if (fd_recv_active(conn->handle.fd)) |
Willy Tarreau | 7d28149 | 2012-12-16 19:19:13 +0100 | [diff] [blame] | 188 | flags |= CO_FL_CURR_RD_ENA; |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 189 | if (fd_send_active(conn->handle.fd)) |
Willy Tarreau | 7d28149 | 2012-12-16 19:19:13 +0100 | [diff] [blame] | 190 | flags |= CO_FL_CURR_WR_ENA; |
| 191 | conn->flags = flags; |
| 192 | } |
| 193 | } |
| 194 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 195 | /* inspects c->flags and returns non-zero if XPRT ENA changes from the CURR ENA |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 196 | * or if the WAIT flags are set with their respective ENA flags. Additionally, |
Willy Tarreau | 0ffde2c | 2012-10-04 22:21:15 +0200 | [diff] [blame] | 197 | * non-zero is also returned if an error was reported on the connection. This |
| 198 | * function is used quite often and is inlined. In order to proceed optimally |
| 199 | * with very little code and CPU cycles, the bits are arranged so that a change |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 200 | * can be detected by a few left shifts, a xor, and a mask. These operations |
| 201 | * detect when W&D are both enabled for either direction, when C&D differ for |
| 202 | * either direction and when Error is set. The trick consists in first keeping |
| 203 | * only the bits we're interested in, since they don't collide when shifted, |
| 204 | * and to perform the AND at the end. In practice, the compiler is able to |
| 205 | * replace the last AND with a TEST in boolean conditions. This results in |
| 206 | * checks that are done in 4-6 cycles and less than 30 bytes. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 207 | */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 208 | static inline unsigned int conn_xprt_polling_changes(const struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 209 | { |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 210 | unsigned int f = c->flags; |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 211 | f &= CO_FL_XPRT_WR_ENA | CO_FL_XPRT_RD_ENA | CO_FL_CURR_WR_ENA | |
Willy Tarreau | 310987a | 2014-01-22 19:46:33 +0100 | [diff] [blame] | 212 | CO_FL_CURR_RD_ENA | CO_FL_ERROR; |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 213 | |
Willy Tarreau | 310987a | 2014-01-22 19:46:33 +0100 | [diff] [blame] | 214 | f = (f ^ (f << 1)) & (CO_FL_CURR_WR_ENA|CO_FL_CURR_RD_ENA); /* test C ^ D */ |
| 215 | return f & (CO_FL_CURR_WR_ENA | CO_FL_CURR_RD_ENA | CO_FL_ERROR); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Willy Tarreau | e9dfa79 | 2012-09-01 17:26:16 +0200 | [diff] [blame] | 218 | /* inspects c->flags and returns non-zero if SOCK ENA changes from the CURR ENA |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 219 | * or if the WAIT flags are set with their respective ENA flags. Additionally, |
Willy Tarreau | 0ffde2c | 2012-10-04 22:21:15 +0200 | [diff] [blame] | 220 | * non-zero is also returned if an error was reported on the connection. This |
| 221 | * function is used quite often and is inlined. In order to proceed optimally |
| 222 | * with very little code and CPU cycles, the bits are arranged so that a change |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 223 | * can be detected by a few left shifts, a xor, and a mask. These operations |
| 224 | * detect when W&S are both enabled for either direction, when C&S differ for |
| 225 | * either direction and when Error is set. The trick consists in first keeping |
| 226 | * only the bits we're interested in, since they don't collide when shifted, |
| 227 | * and to perform the AND at the end. In practice, the compiler is able to |
| 228 | * replace the last AND with a TEST in boolean conditions. This results in |
| 229 | * checks that are done in 4-6 cycles and less than 30 bytes. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 230 | */ |
| 231 | static inline unsigned int conn_sock_polling_changes(const struct connection *c) |
| 232 | { |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 233 | unsigned int f = c->flags; |
| 234 | f &= CO_FL_SOCK_WR_ENA | CO_FL_SOCK_RD_ENA | CO_FL_CURR_WR_ENA | |
Willy Tarreau | 310987a | 2014-01-22 19:46:33 +0100 | [diff] [blame] | 235 | CO_FL_CURR_RD_ENA | CO_FL_ERROR; |
Willy Tarreau | c8dd77f | 2012-11-05 17:52:26 +0100 | [diff] [blame] | 236 | |
Willy Tarreau | 310987a | 2014-01-22 19:46:33 +0100 | [diff] [blame] | 237 | f = (f ^ (f << 2)) & (CO_FL_CURR_WR_ENA|CO_FL_CURR_RD_ENA); /* test C ^ S */ |
| 238 | return f & (CO_FL_CURR_WR_ENA | CO_FL_CURR_RD_ENA | CO_FL_ERROR); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 241 | /* Automatically updates polling on connection <c> depending on the XPRT flags |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 242 | * if no handshake is in progress. It does nothing if CO_FL_WILL_UPDATE is |
| 243 | * present, indicating that an upper caller is going to do it again later. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 244 | */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 245 | static inline void conn_cond_update_xprt_polling(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 246 | { |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 247 | if (!(c->flags & CO_FL_WILL_UPDATE)) |
| 248 | if (!(c->flags & CO_FL_POLL_SOCK) && conn_xprt_polling_changes(c)) |
| 249 | conn_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* Automatically updates polling on connection <c> depending on the SOCK flags |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 253 | * if a handshake is in progress. It does nothing if CO_FL_WILL_UPDATE is |
| 254 | * present, indicating that an upper caller is going to do it again later. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 255 | */ |
| 256 | static inline void conn_cond_update_sock_polling(struct connection *c) |
| 257 | { |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 258 | if (!(c->flags & CO_FL_WILL_UPDATE)) |
| 259 | if ((c->flags & CO_FL_POLL_SOCK) && conn_sock_polling_changes(c)) |
| 260 | conn_update_sock_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Willy Tarreau | 36fb02c | 2012-11-24 11:09:07 +0100 | [diff] [blame] | 263 | /* Stop all polling on the fd. This might be used when an error is encountered |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 264 | * for example. It does not propage the change to the fd layer if |
| 265 | * CO_FL_WILL_UPDATE is present, indicating that an upper caller is going to do |
| 266 | * it later. |
Willy Tarreau | 36fb02c | 2012-11-24 11:09:07 +0100 | [diff] [blame] | 267 | */ |
| 268 | static inline void conn_stop_polling(struct connection *c) |
| 269 | { |
| 270 | c->flags &= ~(CO_FL_CURR_RD_ENA | CO_FL_CURR_WR_ENA | |
| 271 | CO_FL_SOCK_RD_ENA | CO_FL_SOCK_WR_ENA | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 272 | CO_FL_XPRT_RD_ENA | CO_FL_XPRT_WR_ENA); |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 273 | if (!(c->flags & CO_FL_WILL_UPDATE) && conn_ctrl_ready(c)) |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 274 | fd_stop_both(c->handle.fd); |
Willy Tarreau | 36fb02c | 2012-11-24 11:09:07 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 277 | /* Automatically update polling on connection <c> depending on the XPRT and |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 278 | * SOCK flags, and on whether a handshake is in progress or not. This may be |
| 279 | * called at any moment when there is a doubt about the effectiveness of the |
| 280 | * polling state, for instance when entering or leaving the handshake state. |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 281 | * It does nothing if CO_FL_WILL_UPDATE is present, indicating that an upper |
| 282 | * caller is going to do it again later. |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 283 | */ |
| 284 | static inline void conn_cond_update_polling(struct connection *c) |
| 285 | { |
Willy Tarreau | 36fb02c | 2012-11-24 11:09:07 +0100 | [diff] [blame] | 286 | if (unlikely(c->flags & CO_FL_ERROR)) |
| 287 | conn_stop_polling(c); |
Willy Tarreau | 916e12d | 2017-10-25 09:22:43 +0200 | [diff] [blame] | 288 | else if (!(c->flags & CO_FL_WILL_UPDATE)) { |
| 289 | if (!(c->flags & CO_FL_POLL_SOCK) && conn_xprt_polling_changes(c)) |
| 290 | conn_update_xprt_polling(c); |
| 291 | else if ((c->flags & CO_FL_POLL_SOCK) && conn_sock_polling_changes(c)) |
| 292 | conn_update_sock_polling(c); |
| 293 | } |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 294 | } |
| 295 | |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 296 | /* recompute the mux polling flags after updating the current conn_stream and |
| 297 | * propagate the result down the transport layer. |
| 298 | */ |
| 299 | static inline void cs_update_mux_polling(struct conn_stream *cs) |
| 300 | { |
| 301 | struct connection *conn = cs->conn; |
| 302 | |
| 303 | if (conn->mux && conn->mux->update_poll) |
| 304 | conn->mux->update_poll(cs); |
| 305 | } |
| 306 | |
Willy Tarreau | 11c9aa4 | 2018-03-02 13:55:01 +0100 | [diff] [blame] | 307 | /* conn_stream receive function. Uses mux->rcv_buf() if defined, otherwise |
| 308 | * falls back to __cs_recv(). |
| 309 | */ |
| 310 | static inline size_t cs_recv(struct conn_stream *cs, struct buffer *buf, size_t count, int flags) |
| 311 | { |
| 312 | if (cs->conn->mux->rcv_buf) |
| 313 | return cs->conn->mux->rcv_buf(cs, buf, count, flags); |
| 314 | else |
| 315 | return __cs_recv(cs, buf, count, flags); |
| 316 | } |
| 317 | |
Christopher Faulet | 063f786 | 2018-05-23 15:03:43 +0200 | [diff] [blame] | 318 | /* conn_stream send function. Uses mux->snd_buf() if defined, otherwise |
| 319 | * falls back to __cs_send(). |
| 320 | */ |
| 321 | static inline size_t cs_send(struct conn_stream *cs, struct buffer *buf, size_t count, int flags) |
| 322 | { |
| 323 | if (cs->conn->mux->snd_buf) |
| 324 | return cs->conn->mux->snd_buf(cs, buf, count, flags); |
| 325 | else |
| 326 | return __cs_send(cs, buf, count, flags); |
| 327 | } |
| 328 | |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 329 | /***** Event manipulation primitives for use by DATA I/O callbacks *****/ |
| 330 | /* The __conn_* versions do not propagate to lower layers and are only meant |
| 331 | * to be used by handlers called by the connection handler. The other ones |
| 332 | * may be used anywhere. |
| 333 | */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 334 | static inline void __conn_xprt_want_recv(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 335 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 336 | c->flags |= CO_FL_XPRT_RD_ENA; |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 339 | static inline void __conn_xprt_stop_recv(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 340 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 341 | c->flags &= ~CO_FL_XPRT_RD_ENA; |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 344 | static inline void __cs_want_recv(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 345 | { |
| 346 | cs->flags |= CS_FL_DATA_RD_ENA; |
| 347 | } |
| 348 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 349 | static inline void __cs_stop_recv(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 350 | { |
| 351 | cs->flags &= ~CS_FL_DATA_RD_ENA; |
| 352 | } |
| 353 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 354 | static inline void cs_want_recv(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 355 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 356 | __cs_want_recv(cs); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 357 | cs_update_mux_polling(cs); |
| 358 | } |
| 359 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 360 | static inline void cs_stop_recv(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 361 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 362 | __cs_stop_recv(cs); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 363 | cs_update_mux_polling(cs); |
| 364 | } |
| 365 | |
Willy Tarreau | 796c5b7 | 2016-11-29 21:47:02 +0100 | [diff] [blame] | 366 | /* this one is used only to stop speculative recv(). It doesn't stop it if the |
| 367 | * fd is already polled in order to avoid expensive polling status changes. |
| 368 | * Since it might require the upper layer to re-enable reading, we'll return 1 |
| 369 | * if we've really stopped something otherwise zero. |
| 370 | */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 371 | static inline int __conn_xprt_done_recv(struct connection *c) |
Willy Tarreau | 796c5b7 | 2016-11-29 21:47:02 +0100 | [diff] [blame] | 372 | { |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 373 | if (!conn_ctrl_ready(c) || !fd_recv_polled(c->handle.fd)) { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 374 | c->flags &= ~CO_FL_XPRT_RD_ENA; |
Willy Tarreau | 796c5b7 | 2016-11-29 21:47:02 +0100 | [diff] [blame] | 375 | return 1; |
| 376 | } |
| 377 | return 0; |
| 378 | } |
| 379 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 380 | static inline void __conn_xprt_want_send(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 381 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 382 | c->flags |= CO_FL_XPRT_WR_ENA; |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 383 | } |
| 384 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 385 | static inline void __conn_xprt_stop_send(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 386 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 387 | c->flags &= ~CO_FL_XPRT_WR_ENA; |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 388 | } |
| 389 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 390 | static inline void __conn_xprt_stop_both(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 391 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 392 | c->flags &= ~(CO_FL_XPRT_WR_ENA | CO_FL_XPRT_RD_ENA); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 395 | static inline void __cs_want_send(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 396 | { |
| 397 | cs->flags |= CS_FL_DATA_WR_ENA; |
| 398 | } |
| 399 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 400 | static inline void __cs_stop_send(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 401 | { |
| 402 | cs->flags &= ~CS_FL_DATA_WR_ENA; |
| 403 | } |
| 404 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 405 | static inline void cs_stop_send(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 406 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 407 | __cs_stop_send(cs); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 408 | cs_update_mux_polling(cs); |
| 409 | } |
| 410 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 411 | static inline void cs_want_send(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 412 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 413 | __cs_want_send(cs); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 414 | cs_update_mux_polling(cs); |
| 415 | } |
| 416 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 417 | static inline void __cs_stop_both(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 418 | { |
| 419 | cs->flags &= ~(CS_FL_DATA_WR_ENA | CS_FL_DATA_RD_ENA); |
| 420 | } |
| 421 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 422 | static inline void cs_stop_both(struct conn_stream *cs) |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 423 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 424 | __cs_stop_both(cs); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 425 | cs_update_mux_polling(cs); |
| 426 | } |
| 427 | |
| 428 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 429 | static inline void conn_xprt_want_recv(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 430 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 431 | __conn_xprt_want_recv(c); |
| 432 | conn_cond_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 435 | static inline void conn_xprt_stop_recv(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 436 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 437 | __conn_xprt_stop_recv(c); |
| 438 | conn_cond_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 441 | static inline void conn_xprt_want_send(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 442 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 443 | __conn_xprt_want_send(c); |
| 444 | conn_cond_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 447 | static inline void conn_xprt_stop_send(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 448 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 449 | __conn_xprt_stop_send(c); |
| 450 | conn_cond_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 451 | } |
| 452 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 453 | static inline void conn_xprt_stop_both(struct connection *c) |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 454 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 455 | __conn_xprt_stop_both(c); |
| 456 | conn_cond_update_xprt_polling(c); |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /***** Event manipulation primitives for use by handshake I/O callbacks *****/ |
| 460 | /* The __conn_* versions do not propagate to lower layers and are only meant |
| 461 | * to be used by handlers called by the connection handler. The other ones |
| 462 | * may be used anywhere. |
| 463 | */ |
| 464 | static inline void __conn_sock_want_recv(struct connection *c) |
| 465 | { |
| 466 | c->flags |= CO_FL_SOCK_RD_ENA; |
| 467 | } |
| 468 | |
| 469 | static inline void __conn_sock_stop_recv(struct connection *c) |
| 470 | { |
| 471 | c->flags &= ~CO_FL_SOCK_RD_ENA; |
| 472 | } |
| 473 | |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 474 | static inline void __conn_sock_want_send(struct connection *c) |
| 475 | { |
| 476 | c->flags |= CO_FL_SOCK_WR_ENA; |
| 477 | } |
| 478 | |
| 479 | static inline void __conn_sock_stop_send(struct connection *c) |
| 480 | { |
| 481 | c->flags &= ~CO_FL_SOCK_WR_ENA; |
| 482 | } |
| 483 | |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 484 | static inline void __conn_sock_stop_both(struct connection *c) |
| 485 | { |
| 486 | c->flags &= ~(CO_FL_SOCK_WR_ENA | CO_FL_SOCK_RD_ENA); |
| 487 | } |
| 488 | |
| 489 | static inline void conn_sock_want_recv(struct connection *c) |
| 490 | { |
| 491 | __conn_sock_want_recv(c); |
| 492 | conn_cond_update_sock_polling(c); |
| 493 | } |
| 494 | |
| 495 | static inline void conn_sock_stop_recv(struct connection *c) |
| 496 | { |
| 497 | __conn_sock_stop_recv(c); |
| 498 | conn_cond_update_sock_polling(c); |
| 499 | } |
| 500 | |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 501 | static inline void conn_sock_want_send(struct connection *c) |
| 502 | { |
| 503 | __conn_sock_want_send(c); |
| 504 | conn_cond_update_sock_polling(c); |
| 505 | } |
| 506 | |
| 507 | static inline void conn_sock_stop_send(struct connection *c) |
| 508 | { |
| 509 | __conn_sock_stop_send(c); |
| 510 | conn_cond_update_sock_polling(c); |
| 511 | } |
| 512 | |
Willy Tarreau | b5e2cbd | 2012-08-17 11:55:04 +0200 | [diff] [blame] | 513 | static inline void conn_sock_stop_both(struct connection *c) |
| 514 | { |
| 515 | __conn_sock_stop_both(c); |
| 516 | conn_cond_update_sock_polling(c); |
| 517 | } |
Willy Tarreau | 8b11708 | 2012-08-06 15:06:49 +0200 | [diff] [blame] | 518 | |
Willy Tarreau | 7b271b2 | 2017-10-25 09:59:22 +0200 | [diff] [blame] | 519 | /* read shutdown, called from the rcv_buf/rcv_pipe handlers when |
| 520 | * detecting an end of connection. |
| 521 | */ |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 522 | static inline void conn_sock_read0(struct connection *c) |
| 523 | { |
| 524 | c->flags |= CO_FL_SOCK_RD_SH; |
| 525 | __conn_sock_stop_recv(c); |
Willy Tarreau | ad38ace | 2013-12-15 14:19:38 +0100 | [diff] [blame] | 526 | /* we don't risk keeping ports unusable if we found the |
| 527 | * zero from the other side. |
| 528 | */ |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 529 | if (conn_ctrl_ready(c)) |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 530 | fdtab[c->handle.fd].linger_risk = 0; |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Willy Tarreau | 7b271b2 | 2017-10-25 09:59:22 +0200 | [diff] [blame] | 533 | /* write shutdown, indication that the upper layer is not willing to send |
Willy Tarreau | a48c141 | 2017-12-22 18:46:33 +0100 | [diff] [blame] | 534 | * anything anymore and wants to close after pending data are sent. The |
| 535 | * <clean> argument will allow not to perform the socket layer shutdown if |
| 536 | * equal to 0. |
Willy Tarreau | 7b271b2 | 2017-10-25 09:59:22 +0200 | [diff] [blame] | 537 | */ |
Willy Tarreau | a48c141 | 2017-12-22 18:46:33 +0100 | [diff] [blame] | 538 | static inline void conn_sock_shutw(struct connection *c, int clean) |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 539 | { |
| 540 | c->flags |= CO_FL_SOCK_WR_SH; |
Willy Tarreau | 7b271b2 | 2017-10-25 09:59:22 +0200 | [diff] [blame] | 541 | conn_refresh_polling_flags(c); |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 542 | __conn_sock_stop_send(c); |
Willy Tarreau | 7b271b2 | 2017-10-25 09:59:22 +0200 | [diff] [blame] | 543 | conn_cond_update_sock_polling(c); |
| 544 | |
Willy Tarreau | a48c141 | 2017-12-22 18:46:33 +0100 | [diff] [blame] | 545 | /* don't perform a clean shutdown if we're going to reset or |
| 546 | * if the shutr was already received. |
| 547 | */ |
| 548 | if (conn_ctrl_ready(c) && !(c->flags & CO_FL_SOCK_RD_SH) && clean) |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 549 | shutdown(c->handle.fd, SHUT_WR); |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 552 | static inline void conn_xprt_shutw(struct connection *c) |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 553 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 554 | __conn_xprt_stop_send(c); |
Willy Tarreau | 729c69f | 2015-03-12 22:51:10 +0100 | [diff] [blame] | 555 | |
| 556 | /* clean data-layer shutdown */ |
| 557 | if (c->xprt && c->xprt->shutw) |
| 558 | c->xprt->shutw(c, 1); |
| 559 | } |
| 560 | |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 561 | static inline void conn_xprt_shutw_hard(struct connection *c) |
Willy Tarreau | 729c69f | 2015-03-12 22:51:10 +0100 | [diff] [blame] | 562 | { |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 563 | __conn_xprt_stop_send(c); |
Willy Tarreau | 729c69f | 2015-03-12 22:51:10 +0100 | [diff] [blame] | 564 | |
| 565 | /* unclean data-layer shutdown */ |
| 566 | if (c->xprt && c->xprt->shutw) |
| 567 | c->xprt->shutw(c, 0); |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Willy Tarreau | ecdb3fe | 2017-10-05 15:25:48 +0200 | [diff] [blame] | 570 | /* shut read */ |
| 571 | static inline void cs_shutr(struct conn_stream *cs, enum cs_shr_mode mode) |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 572 | { |
| 573 | __cs_stop_recv(cs); |
| 574 | |
| 575 | /* clean data-layer shutdown */ |
| 576 | if (cs->conn->mux && cs->conn->mux->shutr) |
Willy Tarreau | ecdb3fe | 2017-10-05 15:25:48 +0200 | [diff] [blame] | 577 | cs->conn->mux->shutr(cs, mode); |
| 578 | cs->flags |= (mode == CS_SHR_DRAIN) ? CS_FL_SHRD : CS_FL_SHRR; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Willy Tarreau | ecdb3fe | 2017-10-05 15:25:48 +0200 | [diff] [blame] | 581 | /* shut write */ |
| 582 | static inline void cs_shutw(struct conn_stream *cs, enum cs_shw_mode mode) |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 583 | { |
| 584 | __cs_stop_send(cs); |
| 585 | |
| 586 | /* clean data-layer shutdown */ |
| 587 | if (cs->conn->mux && cs->conn->mux->shutw) |
Willy Tarreau | ecdb3fe | 2017-10-05 15:25:48 +0200 | [diff] [blame] | 588 | cs->conn->mux->shutw(cs, mode); |
| 589 | cs->flags |= (mode == CS_SHW_NORMAL) ? CS_FL_SHWN : CS_FL_SHWS; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 590 | } |
| 591 | |
Willy Tarreau | 6978db3 | 2017-10-05 18:19:43 +0200 | [diff] [blame] | 592 | /* completely close a conn_stream (but do not detach it) */ |
| 593 | static inline void cs_close(struct conn_stream *cs) |
| 594 | { |
| 595 | cs_shutw(cs, CS_SHW_SILENT); |
| 596 | cs_shutr(cs, CS_SHR_RESET); |
| 597 | cs->flags = CS_FL_NONE; |
| 598 | } |
| 599 | |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 600 | /* detect sock->data read0 transition */ |
Olivier Houchard | 1a0545f | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 601 | static inline int conn_xprt_read0_pending(struct connection *c) |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 602 | { |
Willy Tarreau | 54e917c | 2017-08-30 07:35:35 +0200 | [diff] [blame] | 603 | return (c->flags & CO_FL_SOCK_RD_SH) != 0; |
Willy Tarreau | 3af56a9 | 2012-08-20 16:55:48 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Willy Tarreau | 910c6aa | 2013-10-24 15:08:37 +0200 | [diff] [blame] | 606 | /* prepares a connection to work with protocol <proto> and transport <xprt>. |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 607 | * The transport's is initialized as well, and the mux and its context are |
| 608 | * cleared. |
Willy Tarreau | 910c6aa | 2013-10-24 15:08:37 +0200 | [diff] [blame] | 609 | */ |
| 610 | static inline void conn_prepare(struct connection *conn, const struct protocol *proto, const struct xprt_ops *xprt) |
| 611 | { |
| 612 | conn->ctrl = proto; |
| 613 | conn->xprt = xprt; |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 614 | conn->mux = NULL; |
Willy Tarreau | 910c6aa | 2013-10-24 15:08:37 +0200 | [diff] [blame] | 615 | conn->xprt_st = 0; |
| 616 | conn->xprt_ctx = NULL; |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 617 | conn->mux_ctx = NULL; |
Willy Tarreau | 910c6aa | 2013-10-24 15:08:37 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 620 | /* |
| 621 | * Initializes all required fields for a new conn_strema. |
| 622 | */ |
| 623 | static inline void cs_init(struct conn_stream *cs, struct connection *conn) |
| 624 | { |
| 625 | cs->obj_type = OBJ_TYPE_CS; |
| 626 | cs->flags = CS_FL_NONE; |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 627 | LIST_INIT(&cs->wait_list.list); |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 628 | LIST_INIT(&cs->send_wait_list); |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 629 | cs->conn = conn; |
Willy Tarreau | 5e1cc5e | 2018-03-02 10:43:58 +0100 | [diff] [blame] | 630 | cs->rxbuf = BUF_NULL; |
Christopher Faulet | 3c51802 | 2018-05-23 14:58:55 +0200 | [diff] [blame] | 631 | cs->txbuf = BUF_NULL; |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 632 | } |
| 633 | |
Willy Tarreau | d015577 | 2013-10-14 17:10:08 +0200 | [diff] [blame] | 634 | /* Initializes all required fields for a new connection. Note that it does the |
| 635 | * minimum acceptable initialization for a connection that already exists and |
| 636 | * is about to be reused. It also leaves the addresses untouched, which makes |
| 637 | * it usable across connection retries to reset a connection to a known state. |
| 638 | */ |
| 639 | static inline void conn_init(struct connection *conn) |
| 640 | { |
| 641 | conn->obj_type = OBJ_TYPE_CONN; |
| 642 | conn->flags = CO_FL_NONE; |
Olivier Houchard | c2aae74 | 2017-09-22 18:26:28 +0200 | [diff] [blame] | 643 | conn->tmp_early_data = -1; |
Olivier Houchard | 90084a1 | 2017-11-23 18:21:29 +0100 | [diff] [blame] | 644 | conn->sent_early_data = 0; |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 645 | conn->mux = NULL; |
| 646 | conn->mux_ctx = NULL; |
Willy Tarreau | d015577 | 2013-10-14 17:10:08 +0200 | [diff] [blame] | 647 | conn->owner = NULL; |
Willy Tarreau | b8020ce | 2013-10-24 21:10:08 +0200 | [diff] [blame] | 648 | conn->send_proxy_ofs = 0; |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 649 | conn->handle.fd = DEAD_FD_MAGIC; |
Willy Tarreau | d015577 | 2013-10-14 17:10:08 +0200 | [diff] [blame] | 650 | conn->err_code = CO_ER_NONE; |
| 651 | conn->target = NULL; |
Willy Tarreau | 8e3c6ce | 2017-08-28 15:46:01 +0200 | [diff] [blame] | 652 | conn->xprt_done_cb = NULL; |
Willy Tarreau | 436d333 | 2017-10-08 11:16:46 +0200 | [diff] [blame] | 653 | conn->destroy_cb = NULL; |
KOVACS Krisztian | b3e54fe | 2014-11-17 15:11:45 +0100 | [diff] [blame] | 654 | conn->proxy_netns = NULL; |
Willy Tarreau | d75d40e | 2015-08-04 17:25:58 +0200 | [diff] [blame] | 655 | LIST_INIT(&conn->list); |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 656 | LIST_INIT(&conn->send_wait_list); |
Willy Tarreau | d015577 | 2013-10-14 17:10:08 +0200 | [diff] [blame] | 657 | } |
| 658 | |
Willy Tarreau | 8e3c6ce | 2017-08-28 15:46:01 +0200 | [diff] [blame] | 659 | /* sets <owner> as the connection's owner */ |
Willy Tarreau | 436d333 | 2017-10-08 11:16:46 +0200 | [diff] [blame] | 660 | static inline void conn_set_owner(struct connection *conn, void *owner, void (*cb)(struct connection *)) |
Willy Tarreau | 8e3c6ce | 2017-08-28 15:46:01 +0200 | [diff] [blame] | 661 | { |
| 662 | conn->owner = owner; |
Willy Tarreau | 436d333 | 2017-10-08 11:16:46 +0200 | [diff] [blame] | 663 | conn->destroy_cb = cb; |
Willy Tarreau | 8e3c6ce | 2017-08-28 15:46:01 +0200 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /* registers <cb> as a callback to notify for transport's readiness or failure */ |
| 667 | static inline void conn_set_xprt_done_cb(struct connection *conn, int (*cb)(struct connection *)) |
| 668 | { |
| 669 | conn->xprt_done_cb = cb; |
| 670 | } |
| 671 | |
| 672 | /* unregisters the callback to notify for transport's readiness or failure */ |
| 673 | static inline void conn_clear_xprt_done_cb(struct connection *conn) |
| 674 | { |
| 675 | conn->xprt_done_cb = NULL; |
| 676 | } |
| 677 | |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 678 | /* Tries to allocate a new connection and initialized its main fields. The |
| 679 | * connection is returned on success, NULL on failure. The connection must |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 680 | * be released using pool_free() or conn_free(). |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 681 | */ |
| 682 | static inline struct connection *conn_new() |
| 683 | { |
| 684 | struct connection *conn; |
| 685 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 686 | conn = pool_alloc(pool_head_connection); |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 687 | if (likely(conn != NULL)) |
| 688 | conn_init(conn); |
| 689 | return conn; |
| 690 | } |
| 691 | |
Willy Tarreau | 5e1cc5e | 2018-03-02 10:43:58 +0100 | [diff] [blame] | 692 | /* Releases the conn_stream's rx buf if it exists. The buffer is automatically |
| 693 | * replaced with a pointer to the empty buffer. |
| 694 | */ |
| 695 | static inline void cs_drop_rxbuf(struct conn_stream *cs) |
| 696 | { |
| 697 | if (b_size(&cs->rxbuf)) { |
| 698 | b_free(&cs->rxbuf); |
| 699 | offer_buffers(NULL, tasks_run_queue); |
| 700 | } |
| 701 | } |
| 702 | |
Christopher Faulet | 3c51802 | 2018-05-23 14:58:55 +0200 | [diff] [blame] | 703 | /* Releases the conn_stream's tx buf if it exists. The buffer is automatically |
| 704 | * replaced with a pointer to the empty buffer. |
| 705 | */ |
| 706 | static inline void cs_drop_txbuf(struct conn_stream *cs) |
| 707 | { |
| 708 | if (b_size(&cs->txbuf)) { |
| 709 | b_free(&cs->txbuf); |
| 710 | offer_buffers(NULL, tasks_run_queue); |
| 711 | } |
| 712 | } |
| 713 | |
Willy Tarreau | 5e1cc5e | 2018-03-02 10:43:58 +0100 | [diff] [blame] | 714 | /* Releases a conn_stream previously allocated by cs_new(), as well as any |
| 715 | * buffer it would still hold. |
| 716 | */ |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 717 | static inline void cs_free(struct conn_stream *cs) |
| 718 | { |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 719 | if (cs->wait_list.task) |
| 720 | tasklet_free(cs->wait_list.task); |
Willy Tarreau | 5e1cc5e | 2018-03-02 10:43:58 +0100 | [diff] [blame] | 721 | |
| 722 | cs_drop_rxbuf(cs); |
Christopher Faulet | 3c51802 | 2018-05-23 14:58:55 +0200 | [diff] [blame] | 723 | cs_drop_txbuf(cs); |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 724 | pool_free(pool_head_connstream, cs); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /* Tries to allocate a new conn_stream and initialize its main fields. If |
| 728 | * <conn> is NULL, then a new connection is allocated on the fly, initialized, |
| 729 | * and assigned to cs->conn ; this connection will then have to be released |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 730 | * using pool_free() or conn_free(). The conn_stream is initialized and added |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 731 | * to the mux's stream list on success, then returned. On failure, nothing is |
| 732 | * allocated and NULL is returned. |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 733 | */ |
| 734 | static inline struct conn_stream *cs_new(struct connection *conn) |
| 735 | { |
| 736 | struct conn_stream *cs; |
| 737 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 738 | cs = pool_alloc(pool_head_connstream); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 739 | if (!likely(cs)) |
| 740 | return NULL; |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 741 | |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 742 | cs->wait_list.task = tasklet_new(); |
| 743 | if (!likely(cs->wait_list.task)) { |
| 744 | cs_free(cs); |
| 745 | return NULL; |
| 746 | } |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 747 | if (!conn) { |
| 748 | conn = conn_new(); |
| 749 | if (!likely(conn)) { |
| 750 | cs_free(cs); |
| 751 | return NULL; |
| 752 | } |
| 753 | conn_init(conn); |
| 754 | } |
| 755 | |
| 756 | cs_init(cs, conn); |
| 757 | return cs; |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 758 | } |
| 759 | |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 760 | /* Releases a connection previously allocated by conn_new() */ |
| 761 | static inline void conn_free(struct connection *conn) |
| 762 | { |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 763 | pool_free(pool_head_connection, conn); |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 766 | /* Release a conn_stream, and kill the connection if it was the last one */ |
| 767 | static inline void cs_destroy(struct conn_stream *cs) |
| 768 | { |
Olivier Houchard | 302f9ef | 2018-04-13 15:50:27 +0200 | [diff] [blame] | 769 | if (cs->conn->mux) |
| 770 | cs->conn->mux->detach(cs); |
| 771 | else { |
| 772 | /* It's too early to have a mux, let's just destroy |
| 773 | * the connection |
| 774 | */ |
| 775 | struct connection *conn = cs->conn; |
| 776 | |
| 777 | conn_stop_tracking(conn); |
| 778 | conn_full_close(conn); |
| 779 | if (conn->destroy_cb) |
| 780 | conn->destroy_cb(conn); |
| 781 | conn_free(conn); |
| 782 | } |
Willy Tarreau | 63dd75d | 2017-10-08 15:16:00 +0200 | [diff] [blame] | 783 | cs_free(cs); |
| 784 | } |
| 785 | |
Olivier Houchard | e2b40b9 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 786 | /* Returns the conn from a cs. If cs is NULL, returns NULL */ |
| 787 | static inline struct connection *cs_conn(const struct conn_stream *cs) |
| 788 | { |
| 789 | return cs ? cs->conn : NULL; |
| 790 | } |
Willy Tarreau | b97f3b1 | 2013-10-20 22:56:45 +0200 | [diff] [blame] | 791 | |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 792 | /* Retrieves the connection's source address */ |
| 793 | static inline void conn_get_from_addr(struct connection *conn) |
| 794 | { |
| 795 | if (conn->flags & CO_FL_ADDR_FROM_SET) |
| 796 | return; |
| 797 | |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 798 | if (!conn_ctrl_ready(conn) || !conn->ctrl->get_src) |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 799 | return; |
| 800 | |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 801 | if (conn->ctrl->get_src(conn->handle.fd, (struct sockaddr *)&conn->addr.from, |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 802 | sizeof(conn->addr.from), |
| 803 | obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1) |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 804 | return; |
| 805 | conn->flags |= CO_FL_ADDR_FROM_SET; |
| 806 | } |
| 807 | |
| 808 | /* Retrieves the connection's original destination address */ |
| 809 | static inline void conn_get_to_addr(struct connection *conn) |
| 810 | { |
| 811 | if (conn->flags & CO_FL_ADDR_TO_SET) |
| 812 | return; |
| 813 | |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 814 | if (!conn_ctrl_ready(conn) || !conn->ctrl->get_dst) |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 815 | return; |
| 816 | |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 817 | if (conn->ctrl->get_dst(conn->handle.fd, (struct sockaddr *)&conn->addr.to, |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 818 | sizeof(conn->addr.to), |
| 819 | obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1) |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 820 | return; |
| 821 | conn->flags |= CO_FL_ADDR_TO_SET; |
| 822 | } |
| 823 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 824 | /* Attaches a conn_stream to a data layer and sets the relevant callbacks */ |
| 825 | static inline void cs_attach(struct conn_stream *cs, void *data, const struct data_cb *data_cb) |
Willy Tarreau | dda5e7c | 2012-09-24 17:15:42 +0200 | [diff] [blame] | 826 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 827 | cs->data_cb = data_cb; |
| 828 | cs->data = data; |
Willy Tarreau | bd99aab | 2012-10-02 20:57:19 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Willy Tarreau | 8318885 | 2018-07-18 08:18:20 +0200 | [diff] [blame] | 831 | static inline struct wait_list *wl_set_waitcb(struct wait_list *wl, struct task *(*cb)(struct task *, void *, unsigned short), void *ctx) |
| 832 | { |
| 833 | if (!wl->task->process) { |
| 834 | wl->task->process = cb; |
| 835 | wl->task->context = ctx; |
| 836 | } |
| 837 | return wl; |
| 838 | } |
| 839 | |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 840 | /* Installs the connection's mux layer for upper context <ctx>. |
| 841 | * Returns < 0 on error. |
| 842 | */ |
| 843 | static inline int conn_install_mux(struct connection *conn, const struct mux_ops *mux, void *ctx) |
| 844 | { |
| 845 | conn->mux = mux; |
| 846 | conn->mux_ctx = ctx; |
| 847 | return mux->init ? mux->init(conn) : 0; |
| 848 | } |
| 849 | |
Willy Tarreau | 0af2912 | 2012-12-03 15:35:00 +0100 | [diff] [blame] | 850 | /* returns a human-readable error code for conn->err_code, or NULL if the code |
| 851 | * is unknown. |
| 852 | */ |
| 853 | static inline const char *conn_err_code_str(struct connection *c) |
| 854 | { |
| 855 | switch (c->err_code) { |
| 856 | case CO_ER_NONE: return "Success"; |
Willy Tarreau | 45b34e8 | 2014-01-24 16:06:50 +0100 | [diff] [blame] | 857 | |
| 858 | case CO_ER_CONF_FDLIM: return "Reached configured maxconn value"; |
| 859 | case CO_ER_PROC_FDLIM: return "Too many sockets on the process"; |
| 860 | case CO_ER_SYS_FDLIM: return "Too many sockets on the system"; |
| 861 | case CO_ER_SYS_MEMLIM: return "Out of system buffers"; |
| 862 | case CO_ER_NOPROTO: return "Protocol or address family not supported"; |
| 863 | case CO_ER_SOCK_ERR: return "General socket error"; |
| 864 | case CO_ER_PORT_RANGE: return "Source port range exhausted"; |
| 865 | case CO_ER_CANT_BIND: return "Can't bind to source address"; |
| 866 | case CO_ER_FREE_PORTS: return "Out of local source ports on the system"; |
| 867 | case CO_ER_ADDR_INUSE: return "Local source address already in use"; |
| 868 | |
Willy Tarreau | 8e3bf69 | 2012-12-03 15:41:18 +0100 | [diff] [blame] | 869 | case CO_ER_PRX_EMPTY: return "Connection closed while waiting for PROXY protocol header"; |
| 870 | case CO_ER_PRX_ABORT: return "Connection error while waiting for PROXY protocol header"; |
Willy Tarreau | 0af2912 | 2012-12-03 15:35:00 +0100 | [diff] [blame] | 871 | case CO_ER_PRX_TIMEOUT: return "Timeout while waiting for PROXY protocol header"; |
Willy Tarreau | 8e3bf69 | 2012-12-03 15:41:18 +0100 | [diff] [blame] | 872 | case CO_ER_PRX_TRUNCATED: return "Truncated PROXY protocol header received"; |
| 873 | case CO_ER_PRX_NOT_HDR: return "Received something which does not look like a PROXY protocol header"; |
| 874 | case CO_ER_PRX_BAD_HDR: return "Received an invalid PROXY protocol header"; |
| 875 | case CO_ER_PRX_BAD_PROTO: return "Received an unhandled protocol in the PROXY protocol header"; |
Bertrand Jacquin | 93b227d | 2016-06-04 15:11:10 +0100 | [diff] [blame] | 876 | |
| 877 | case CO_ER_CIP_EMPTY: return "Connection closed while waiting for NetScaler Client IP header"; |
| 878 | case CO_ER_CIP_ABORT: return "Connection error while waiting for NetScaler Client IP header"; |
| 879 | case CO_ER_CIP_TRUNCATED: return "Truncated NetScaler Client IP header received"; |
| 880 | case CO_ER_CIP_BAD_MAGIC: return "Received an invalid NetScaler Client IP magic number"; |
| 881 | case CO_ER_CIP_BAD_PROTO: return "Received an unhandled protocol in the NetScaler Client IP header"; |
| 882 | |
Willy Tarreau | 20879a0 | 2012-12-03 16:32:10 +0100 | [diff] [blame] | 883 | case CO_ER_SSL_EMPTY: return "Connection closed during SSL handshake"; |
| 884 | case CO_ER_SSL_ABORT: return "Connection error during SSL handshake"; |
Willy Tarreau | 0af2912 | 2012-12-03 15:35:00 +0100 | [diff] [blame] | 885 | case CO_ER_SSL_TIMEOUT: return "Timeout during SSL handshake"; |
Willy Tarreau | 20879a0 | 2012-12-03 16:32:10 +0100 | [diff] [blame] | 886 | case CO_ER_SSL_TOO_MANY: return "Too many SSL connections"; |
| 887 | case CO_ER_SSL_NO_MEM: return "Out of memory when initializing an SSL connection"; |
| 888 | case CO_ER_SSL_RENEG: return "Rejected a client-initiated SSL renegociation attempt"; |
| 889 | case CO_ER_SSL_CA_FAIL: return "SSL client CA chain cannot be verified"; |
| 890 | case CO_ER_SSL_CRT_FAIL: return "SSL client certificate not trusted"; |
Willy Tarreau | 71d058c | 2017-07-26 20:09:56 +0200 | [diff] [blame] | 891 | case CO_ER_SSL_MISMATCH: return "Server presented an SSL certificate different from the configured one"; |
| 892 | case CO_ER_SSL_MISMATCH_SNI: return "Server presented an SSL certificate different from the expected one"; |
Willy Tarreau | 20879a0 | 2012-12-03 16:32:10 +0100 | [diff] [blame] | 893 | case CO_ER_SSL_HANDSHAKE: return "SSL handshake failure"; |
Willy Tarreau | b396637 | 2014-04-25 18:54:29 +0200 | [diff] [blame] | 894 | case CO_ER_SSL_HANDSHAKE_HB: return "SSL handshake failure after heartbeat"; |
Willy Tarreau | f51c698 | 2014-04-25 20:02:39 +0200 | [diff] [blame] | 895 | case CO_ER_SSL_KILLED_HB: return "Stopped a TLSv1 heartbeat attack (CVE-2014-0160)"; |
Willy Tarreau | 830bf61 | 2013-12-01 20:29:58 +0100 | [diff] [blame] | 896 | case CO_ER_SSL_NO_TARGET: return "Attempt to use SSL on an unknown target (internal error)"; |
Willy Tarreau | 0af2912 | 2012-12-03 15:35:00 +0100 | [diff] [blame] | 897 | } |
| 898 | return NULL; |
| 899 | } |
| 900 | |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 901 | static inline const char *conn_get_ctrl_name(const struct connection *conn) |
| 902 | { |
| 903 | if (!conn_ctrl_ready(conn)) |
| 904 | return "NONE"; |
| 905 | return conn->ctrl->name; |
| 906 | } |
| 907 | |
| 908 | static inline const char *conn_get_xprt_name(const struct connection *conn) |
| 909 | { |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 910 | if (!conn_xprt_ready(conn)) |
| 911 | return "NONE"; |
Willy Tarreau | 8e0bb0a | 2016-11-24 16:58:12 +0100 | [diff] [blame] | 912 | return conn->xprt->name; |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 915 | static inline const char *conn_get_mux_name(const struct connection *conn) |
| 916 | { |
| 917 | if (!conn->mux) |
| 918 | return "NONE"; |
| 919 | return conn->mux->name; |
| 920 | } |
| 921 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 922 | static inline const char *cs_get_data_name(const struct conn_stream *cs) |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 923 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 924 | if (!cs->data_cb) |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 925 | return "NONE"; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 926 | return cs->data_cb->name; |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Willy Tarreau | 13e1410 | 2016-12-22 20:25:26 +0100 | [diff] [blame] | 929 | /* registers pointer to transport layer <id> (XPRT_*) */ |
| 930 | static inline void xprt_register(int id, struct xprt_ops *xprt) |
| 931 | { |
| 932 | if (id >= XPRT_ENTRIES) |
| 933 | return; |
| 934 | registered_xprt[id] = xprt; |
| 935 | } |
| 936 | |
| 937 | /* returns pointer to transport layer <id> (XPRT_*) or NULL if not registered */ |
| 938 | static inline struct xprt_ops *xprt_get(int id) |
| 939 | { |
| 940 | if (id >= XPRT_ENTRIES) |
| 941 | return NULL; |
| 942 | return registered_xprt[id]; |
| 943 | } |
Willy Tarreau | 2dc770c | 2016-11-23 18:00:08 +0100 | [diff] [blame] | 944 | |
Willy Tarreau | a9c1741 | 2016-12-04 18:42:09 +0100 | [diff] [blame] | 945 | static inline int conn_get_alpn(const struct connection *conn, const char **str, int *len) |
| 946 | { |
| 947 | if (!conn_xprt_ready(conn) || !conn->xprt->get_alpn) |
| 948 | return 0; |
| 949 | return conn->xprt->get_alpn(conn, str, len); |
| 950 | } |
| 951 | |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 952 | /* registers proto mux list <list>. Modifies the list element! */ |
| 953 | static inline void register_mux_proto(struct mux_proto_list *list) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 954 | { |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 955 | LIST_ADDQ(&mux_proto_list.list, &list->list); |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 956 | } |
| 957 | |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 958 | /* unregisters proto mux list <list> */ |
| 959 | static inline void unregister_mux_proto(struct mux_proto_list *list) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 960 | { |
| 961 | LIST_DEL(&list->list); |
| 962 | LIST_INIT(&list->list); |
| 963 | } |
| 964 | |
Christopher Faulet | e15c6c4 | 2018-08-08 10:21:56 +0200 | [diff] [blame] | 965 | static inline struct mux_proto_list *get_mux_proto(const struct ist proto) |
Christopher Faulet | 98d9fe2 | 2018-04-10 14:37:32 +0200 | [diff] [blame] | 966 | { |
| 967 | struct mux_proto_list *item; |
Christopher Faulet | 98d9fe2 | 2018-04-10 14:37:32 +0200 | [diff] [blame] | 968 | |
| 969 | list_for_each_entry(item, &mux_proto_list.list, list) { |
| 970 | if (isteq(proto, item->token)) |
| 971 | return item; |
| 972 | } |
| 973 | return NULL; |
| 974 | } |
| 975 | |
| 976 | /* Lists the known proto mux on <out> */ |
| 977 | static inline void list_mux_proto(FILE *out) |
| 978 | { |
| 979 | struct mux_proto_list *item; |
| 980 | struct ist proto; |
| 981 | char *mode, *side; |
| 982 | |
Christopher Faulet | 9c9ef03 | 2018-08-08 10:25:57 +0200 | [diff] [blame] | 983 | fprintf(out, "Available multiplexer protocols :\n" |
| 984 | "(protocols markes as <default> cannot be specified using 'proto' keyword)\n"); |
Christopher Faulet | 98d9fe2 | 2018-04-10 14:37:32 +0200 | [diff] [blame] | 985 | list_for_each_entry(item, &mux_proto_list.list, list) { |
| 986 | proto = item->token; |
| 987 | |
| 988 | if (item->mode == PROTO_MODE_ANY) |
| 989 | mode = "TCP|HTTP"; |
| 990 | else if (item->mode == PROTO_MODE_TCP) |
| 991 | mode = "TCP"; |
| 992 | else if (item->mode == PROTO_MODE_HTTP) |
| 993 | mode = "HTTP"; |
| 994 | else |
| 995 | mode = "NONE"; |
| 996 | |
| 997 | if (item->side == PROTO_SIDE_BOTH) |
| 998 | side = "FE|BE"; |
| 999 | else if (item->side == PROTO_SIDE_FE) |
| 1000 | side = "FE"; |
| 1001 | else if (item->side == PROTO_SIDE_BE) |
| 1002 | side = "BE"; |
| 1003 | else |
| 1004 | side = "NONE"; |
| 1005 | |
| 1006 | fprintf(out, " %15s : mode=%-10s side=%s\n", |
Christopher Faulet | 9c9ef03 | 2018-08-08 10:25:57 +0200 | [diff] [blame] | 1007 | (proto.len ? proto.ptr : "<default>"), mode, side); |
Christopher Faulet | 98d9fe2 | 2018-04-10 14:37:32 +0200 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1011 | /* returns the first mux in the list matching the exact same <mux_proto> and |
| 1012 | * compatible with the <proto_side> (FE or BE) and the <proto_mode> (TCP or |
| 1013 | * HTTP). <mux_proto> can be empty. Will fall back to the first compatible mux |
| 1014 | * with exactly the same <proto_mode> or with an empty name. May return |
| 1015 | * null if the code improperly registered the default mux to use as a fallback. |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1016 | */ |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1017 | static inline const struct mux_ops *conn_get_best_mux(struct connection *conn, |
| 1018 | const struct ist mux_proto, |
| 1019 | int proto_side, int proto_mode) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1020 | { |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 1021 | struct mux_proto_list *item; |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1022 | struct mux_proto_list *fallback = NULL; |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1023 | |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 1024 | list_for_each_entry(item, &mux_proto_list.list, list) { |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1025 | if (!(item->side & proto_side) || !(item->mode & proto_mode)) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1026 | continue; |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1027 | if (istlen(mux_proto) && isteq(mux_proto, item->token)) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1028 | return item->mux; |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1029 | else if (!istlen(item->token)) { |
| 1030 | if (!fallback || (item->mode == proto_mode && fallback->mode != proto_mode)) |
| 1031 | fallback = item; |
| 1032 | } |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1033 | } |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1034 | return (fallback ? fallback->mux : NULL); |
| 1035 | |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1038 | /* installs the best mux for incoming connection <conn> using the upper context |
| 1039 | * <ctx>. If the mux protocol is forced, we use it to find the best |
| 1040 | * mux. Otherwise we use the ALPN name, if any. Returns < 0 on error. |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1041 | */ |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1042 | static inline int conn_install_mux_fe(struct connection *conn, void *ctx) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1043 | { |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1044 | struct bind_conf *bind_conf = objt_listener(conn->target)->bind_conf; |
| 1045 | const struct mux_ops *mux_ops; |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1046 | |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1047 | if (bind_conf->mux_proto) |
| 1048 | mux_ops = bind_conf->mux_proto->mux; |
| 1049 | else { |
| 1050 | struct ist mux_proto; |
| 1051 | const char *alpn_str = NULL; |
| 1052 | int alpn_len = 0; |
| 1053 | int mode = (1 << (bind_conf->frontend->mode == PR_MODE_HTTP)); |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1054 | |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1055 | conn_get_alpn(conn, &alpn_str, &alpn_len); |
| 1056 | mux_proto = ist2(alpn_str, alpn_len); |
| 1057 | mux_ops = conn_get_best_mux(conn, mux_proto, PROTO_SIDE_FE, mode); |
| 1058 | if (!mux_ops) |
| 1059 | return -1; |
| 1060 | } |
| 1061 | return conn_install_mux(conn, mux_ops, ctx); |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1064 | /* installs the best mux for outgoing connection <conn> using the upper context |
| 1065 | * <ctx>. If the mux protocol is forced, we use it to find the best mux. Returns |
Willy Tarreau | 2e0b2b5 | 2017-09-15 06:59:55 +0200 | [diff] [blame] | 1066 | * < 0 on error. |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1067 | */ |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1068 | static inline int conn_install_mux_be(struct connection *conn, void *ctx) |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1069 | { |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1070 | struct server *srv = objt_server(conn->target); |
Willy Tarreau | 287527a | 2018-08-08 18:40:44 +0200 | [diff] [blame] | 1071 | struct proxy *prx = objt_proxy(conn->target); |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1072 | const struct mux_ops *mux_ops; |
| 1073 | |
Willy Tarreau | 287527a | 2018-08-08 18:40:44 +0200 | [diff] [blame] | 1074 | if (srv) |
| 1075 | prx = srv->proxy; |
| 1076 | |
| 1077 | if (!prx) // target must be either proxy or server |
| 1078 | return -1; |
| 1079 | |
| 1080 | if (srv && srv->mux_proto) |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1081 | mux_ops = srv->mux_proto->mux; |
| 1082 | else { |
| 1083 | int mode; |
| 1084 | |
Willy Tarreau | 287527a | 2018-08-08 18:40:44 +0200 | [diff] [blame] | 1085 | mode = (1 << (prx->mode == PR_MODE_HTTP)); |
Christopher Faulet | 7ce0c89 | 2018-04-10 15:01:45 +0200 | [diff] [blame] | 1086 | mux_ops = conn_get_best_mux(conn, ist(NULL), PROTO_SIDE_BE, mode); |
| 1087 | if (!mux_ops) |
| 1088 | return -1; |
| 1089 | } |
Willy Tarreau | 2e0b2b5 | 2017-09-15 06:59:55 +0200 | [diff] [blame] | 1090 | return conn_install_mux(conn, mux_ops, ctx); |
Willy Tarreau | 2386be6 | 2017-09-21 19:40:52 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
Willy Tarreau | 59f9839 | 2012-07-06 14:13:49 +0200 | [diff] [blame] | 1093 | #endif /* _PROTO_CONNECTION_H */ |
| 1094 | |
| 1095 | /* |
| 1096 | * Local variables: |
| 1097 | * c-indent-level: 8 |
| 1098 | * c-basic-offset: 8 |
| 1099 | * End: |
| 1100 | */ |