blob: bbfcf5ba9698f5054a21c8a5e739a9b5d4bb614d [file] [log] [blame]
Willy Tarreau53a47662017-08-28 10:53:00 +02001/*
2 * Pass-through mux-demux for connections
3 *
4 * Copyright 2017 Willy Tarreau <w@1wt.eu>
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
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020013#include <haproxy/api.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020014#include <haproxy/buf.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020015#include <haproxy/connection.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020016#include <haproxy/stream.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020017#include <haproxy/task.h>
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010018
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010019struct mux_pt_ctx {
20 struct conn_stream *cs;
21 struct connection *conn;
22 struct wait_event wait_event;
23};
24
Willy Tarreau8ceae722018-11-26 11:58:30 +010025DECLARE_STATIC_POOL(pool_head_pt_ctx, "mux_pt", sizeof(struct mux_pt_ctx));
26
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010027static void mux_pt_destroy(struct mux_pt_ctx *ctx)
28{
Christopher Faulet61840e72019-04-15 09:33:32 +020029 /* The connection must be aattached to this mux to be released */
30 if (ctx && ctx->conn && ctx->conn->ctx == ctx) {
31 struct connection *conn = ctx->conn;
Christopher Faulet39a96ee2019-04-08 10:52:21 +020032
Christopher Faulet39a96ee2019-04-08 10:52:21 +020033 conn_stop_tracking(conn);
34 conn_full_close(conn);
Willy Tarreau3c39a7d2019-06-14 14:42:29 +020035 tasklet_free(ctx->wait_event.tasklet);
Christopher Faulet39a96ee2019-04-08 10:52:21 +020036 conn->mux = NULL;
37 conn->ctx = NULL;
38 if (conn->destroy_cb)
39 conn->destroy_cb(conn);
40 /* We don't bother unsubscribing here, as we're about to destroy
41 * both the connection and the mux_pt_ctx
42 */
43 conn_free(conn);
44 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010045 pool_free(pool_head_pt_ctx, ctx);
46}
47
48/* Callback, used when we get I/Os while in idle mode */
49static struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned short status)
50{
51 struct mux_pt_ctx *ctx = tctx;
52
Olivier Houchardea510fc2019-10-18 13:56:40 +020053 if (ctx->cs) {
54 /* There's a small race condition.
55 * mux_pt_io_cb() is only supposed to be called if we have no
56 * stream attached. However, maybe the tasklet got woken up,
57 * and this connection was then attached to a new stream.
Olivier Houchard2ed389d2019-10-18 14:18:29 +020058 * If this happened, just wake the tasklet up if anybody
59 * subscribed to receive events, and otherwise call the wake
60 * method, to make sure the event is noticed.
Olivier Houchardea510fc2019-10-18 13:56:40 +020061 */
Willy Tarreau7872d1f2020-01-10 07:06:05 +010062 if (ctx->conn->subs) {
63 ctx->conn->subs->events = 0;
64 tasklet_wakeup(ctx->conn->subs->tasklet);
65 ctx->conn->subs = NULL;
Olivier Houchard2ed389d2019-10-18 14:18:29 +020066 } else if (ctx->cs->data_cb->wake)
Olivier Houchardea510fc2019-10-18 13:56:40 +020067 ctx->cs->data_cb->wake(ctx->cs);
68 return NULL;
69 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010070 conn_sock_drain(ctx->conn);
Olivier Houchard9dce2c52019-10-18 10:59:30 +020071 if (ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))
72 mux_pt_destroy(ctx);
73 else
Olivier Houcharde179d0e2019-03-21 18:27:17 +010074 ctx->conn->xprt->subscribe(ctx->conn, ctx->conn->xprt_ctx, SUB_RETRY_RECV,
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010075 &ctx->wait_event);
76
77 return NULL;
78}
Willy Tarreau53a47662017-08-28 10:53:00 +020079
Willy Tarreau3d2ee552018-12-19 14:12:10 +010080/* Initialize the mux once it's attached. It is expected that conn->ctx
Olivier Houchard9aaf7782017-09-13 18:30:23 +020081 * points to the existing conn_stream (for outgoing connections) or NULL (for
82 * incoming ones, in which case one will be allocated and a new stream will be
83 * instanciated). Returns < 0 on error.
Willy Tarreau53a47662017-08-28 10:53:00 +020084 */
Christopher Faulet51f73eb2019-04-08 11:22:47 +020085static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess,
86 struct buffer *input)
Willy Tarreau53a47662017-08-28 10:53:00 +020087{
Willy Tarreau3d2ee552018-12-19 14:12:10 +010088 struct conn_stream *cs = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010089 struct mux_pt_ctx *ctx = pool_alloc(pool_head_pt_ctx);
90
91 if (!ctx)
92 goto fail;
93
Willy Tarreau3c39a7d2019-06-14 14:42:29 +020094 ctx->wait_event.tasklet = tasklet_new();
95 if (!ctx->wait_event.tasklet)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010096 goto fail_free_ctx;
Willy Tarreau3c39a7d2019-06-14 14:42:29 +020097 ctx->wait_event.tasklet->context = ctx;
98 ctx->wait_event.tasklet->process = mux_pt_io_cb;
Willy Tarreau4f6516d2018-12-19 13:59:17 +010099 ctx->wait_event.events = 0;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100100 ctx->conn = conn;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200101
102 if (!cs) {
103 cs = cs_new(conn);
104 if (!cs)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100105 goto fail_free_ctx;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200106
107 if (stream_create_from_cs(cs) < 0)
108 goto fail_free;
109
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200110 }
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100111 conn->ctx = ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100112 ctx->cs = cs;
Olivier Houchard8706c812018-12-04 19:17:25 +0100113 cs->flags |= CS_FL_RCV_MORE;
Willy Tarreau17ccd1a2020-01-17 16:19:34 +0100114 if (global.tune.options & GTUNE_USE_SPLICE)
115 cs->flags |= CS_FL_MAY_SPLICE;
Willy Tarreau53a47662017-08-28 10:53:00 +0200116 return 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200117
118 fail_free:
119 cs_free(cs);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100120fail_free_ctx:
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200121 if (ctx->wait_event.tasklet)
122 tasklet_free(ctx->wait_event.tasklet);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100123 pool_free(pool_head_pt_ctx, ctx);
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200124 fail:
125 return -1;
Willy Tarreau53a47662017-08-28 10:53:00 +0200126}
127
128/* callback to be used by default for the pass-through mux. It calls the data
129 * layer wake() callback if it is set otherwise returns 0.
130 */
131static int mux_pt_wake(struct connection *conn)
132{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100133 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100134 struct conn_stream *cs = ctx->cs;
135 int ret = 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200136
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100137 if (cs) {
138 ret = cs->data_cb->wake ? cs->data_cb->wake(cs) : 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200139
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100140 if (ret < 0)
141 return ret;
142 } else {
143 conn_sock_drain(conn);
144 if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) {
145 mux_pt_destroy(ctx);
146 return -1;
147 }
148 }
Willy Tarreauad7f0ad2018-08-24 15:48:59 +0200149
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100150 /* If we had early data, and we're done with the handshake
151 * then whe know the data are safe, and we can remove the flag.
152 */
Willy Tarreau911db9b2020-01-23 16:27:54 +0100153 if ((conn->flags & (CO_FL_EARLY_DATA | CO_FL_EARLY_SSL_HS | CO_FL_WAIT_XPRT)) ==
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100154 CO_FL_EARLY_DATA)
155 conn->flags &= ~CO_FL_EARLY_DATA;
Willy Tarreaued339a32017-11-03 15:55:24 +0100156 return ret;
Willy Tarreau53a47662017-08-28 10:53:00 +0200157}
158
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200159/*
160 * Attach a new stream to a connection
161 * (Used for outgoing connections)
162 */
Olivier Houchardf502aca2018-12-14 19:42:40 +0100163static struct conn_stream *mux_pt_attach(struct connection *conn, struct session *sess)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200164{
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100165 struct conn_stream *cs;
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100166 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100167
Olivier Houchardea32b0f2019-08-10 23:56:16 +0200168 if (ctx->wait_event.events)
169 conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100170 cs = cs_new(conn);
171 if (!cs)
172 goto fail;
173
174 ctx->cs = cs;
Olivier Houchard8706c812018-12-04 19:17:25 +0100175 cs->flags |= CS_FL_RCV_MORE;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100176 return (cs);
177fail:
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200178 return NULL;
179}
180
Willy Tarreaufafd3982018-11-18 21:29:20 +0100181/* Retrieves a valid conn_stream from this connection, or returns NULL. For
182 * this mux, it's easy as we can only store a single conn_stream.
183 */
184static const struct conn_stream *mux_pt_get_first_cs(const struct connection *conn)
185{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100186 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100187 struct conn_stream *cs = ctx->cs;
Willy Tarreaufafd3982018-11-18 21:29:20 +0100188
189 return cs;
190}
191
Christopher Faulet73c12072019-04-08 11:23:22 +0200192/* Destroy the mux and the associated connection if still attached to this mux
193 * and no longer used */
194static void mux_pt_destroy_meth(void *ctx)
Olivier Houchard060ed432018-11-06 16:32:42 +0100195{
Christopher Faulet73c12072019-04-08 11:23:22 +0200196 struct mux_pt_ctx *pt = ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100197
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200198 if (!(pt->cs) || !(pt->conn) || pt->conn->ctx != pt)
Christopher Faulet73c12072019-04-08 11:23:22 +0200199 mux_pt_destroy(pt);
Olivier Houchard060ed432018-11-06 16:32:42 +0100200}
201
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200202/*
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200203 * Detach the stream from the connection and possibly release the connection.
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200204 */
205static void mux_pt_detach(struct conn_stream *cs)
206{
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200207 struct connection *conn = cs->conn;
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100208 struct mux_pt_ctx *ctx = cs->conn->ctx;
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200209
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100210 /* Subscribe, to know if we got disconnected */
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100211 if (conn->owner != NULL &&
212 !(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) {
213 ctx->cs = NULL;
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100214 conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Olivier Houchard9dce2c52019-10-18 10:59:30 +0200215 } else
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100216 /* There's no session attached to that connection, destroy it */
217 mux_pt_destroy(ctx);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200218}
219
Willy Tarreau00f18a32019-01-26 12:19:01 +0100220/* returns the number of streams in use on a connection */
221static int mux_pt_used_streams(struct connection *conn)
Olivier Houchardd540b362018-11-05 18:37:53 +0100222{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100223 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardd540b362018-11-05 18:37:53 +0100224
Willy Tarreau00f18a32019-01-26 12:19:01 +0100225 return ctx->cs ? 1 : 0;
Olivier Houchardd540b362018-11-05 18:37:53 +0100226}
227
Willy Tarreau00f18a32019-01-26 12:19:01 +0100228/* returns the number of streams still available on a connection */
229static int mux_pt_avail_streams(struct connection *conn)
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100230{
Willy Tarreau00f18a32019-01-26 12:19:01 +0100231 return 1 - mux_pt_used_streams(conn);
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100232}
233
Willy Tarreauecdb3fe2017-10-05 15:25:48 +0200234static void mux_pt_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200235{
Willy Tarreau4b795242017-10-05 18:47:38 +0200236 if (cs->flags & CS_FL_SHR)
237 return;
Christopher Fauletd94f8772018-12-17 13:21:02 +0100238 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200239 if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutr)
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100240 cs->conn->xprt->shutr(cs->conn, cs->conn->xprt_ctx,
241 (mode == CS_SHR_DRAIN));
Willy Tarreau4b795242017-10-05 18:47:38 +0200242 if (cs->flags & CS_FL_SHW)
243 conn_full_close(cs->conn);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200244}
245
Willy Tarreauecdb3fe2017-10-05 15:25:48 +0200246static void mux_pt_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200247{
Willy Tarreau4b795242017-10-05 18:47:38 +0200248 if (cs->flags & CS_FL_SHW)
249 return;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200250 if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutw)
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100251 cs->conn->xprt->shutw(cs->conn, cs->conn->xprt_ctx,
252 (mode == CS_SHW_NORMAL));
Willy Tarreau4b795242017-10-05 18:47:38 +0200253 if (!(cs->flags & CS_FL_SHR))
Willy Tarreaua48c1412017-12-22 18:46:33 +0100254 conn_sock_shutw(cs->conn, (mode == CS_SHW_NORMAL));
Willy Tarreau4b795242017-10-05 18:47:38 +0200255 else
256 conn_full_close(cs->conn);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200257}
258
259/*
260 * Called from the upper layer, to get more data
261 */
Willy Tarreau7f3225f2018-06-19 06:15:17 +0200262static size_t mux_pt_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200263{
Willy Tarreaud9cf5402018-07-18 11:29:06 +0200264 size_t ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200265
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200266 if (!count) {
Christopher Fauletd94f8772018-12-17 13:21:02 +0100267 cs->flags |= (CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200268 return 0;
269 }
Willy Tarreaue0f24ee2018-12-14 10:51:23 +0100270 b_realign_if_empty(buf);
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100271 ret = cs->conn->xprt->rcv_buf(cs->conn, cs->conn->xprt_ctx, buf, count, flags);
Olivier Houchard8706c812018-12-04 19:17:25 +0100272 if (conn_xprt_read0_pending(cs->conn)) {
Willy Tarreau9cca8df2019-07-15 06:47:54 +0200273 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Christopher Faulet87a8f352019-03-22 14:51:36 +0100274 cs->flags |= CS_FL_EOS;
Olivier Houchard8706c812018-12-04 19:17:25 +0100275 }
276 if (cs->conn->flags & CO_FL_ERROR) {
Willy Tarreau9cca8df2019-07-15 06:47:54 +0200277 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200278 cs->flags |= CS_FL_ERROR;
Olivier Houchard8706c812018-12-04 19:17:25 +0100279 }
Willy Tarreaud9cf5402018-07-18 11:29:06 +0200280 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200281}
282
283/* Called from the upper layer, to send data */
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200284static size_t mux_pt_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200285{
Olivier Houchardb72d98a2018-11-30 13:17:48 +0100286 size_t ret;
287
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100288 ret = cs->conn->xprt->snd_buf(cs->conn, cs->conn->xprt_ctx, buf, count, flags);
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200289
290 if (ret > 0)
291 b_del(buf, ret);
292 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200293}
294
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100295/* Called from the upper layer, to subscribe <es> to events <event_type>. The
296 * event subscriber <es> is not allowed to change from a previous call as long
297 * as at least one event is still subscribed. The <event_type> must only be a
298 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
299 */
300static int mux_pt_subscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
Olivier Houchard6ff20392018-07-17 18:46:31 +0200301{
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100302 return cs->conn->xprt->subscribe(cs->conn, cs->conn->xprt_ctx, event_type, es);
Olivier Houchard6ff20392018-07-17 18:46:31 +0200303}
304
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100305/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
306 * The <es> pointer is not allowed to differ from the one passed to the
307 * subscribe() call. It always returns zero.
308 */
309static int mux_pt_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200310{
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100311 return cs->conn->xprt->unsubscribe(cs->conn, cs->conn->xprt_ctx, event_type, es);
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200312}
313
Willy Tarreaue5733232019-05-22 19:24:06 +0200314#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200315/* Send and get, using splicing */
316static int mux_pt_rcv_pipe(struct conn_stream *cs, struct pipe *pipe, unsigned int count)
317{
318 int ret;
319
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100320 ret = cs->conn->xprt->rcv_pipe(cs->conn, cs->conn->xprt_ctx, pipe, count);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200321 if (conn_xprt_read0_pending(cs->conn))
Christopher Faulet87a8f352019-03-22 14:51:36 +0100322 cs->flags |= CS_FL_EOS;
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200323 if (cs->conn->flags & CO_FL_ERROR)
324 cs->flags |= CS_FL_ERROR;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200325 return (ret);
326}
327
328static int mux_pt_snd_pipe(struct conn_stream *cs, struct pipe *pipe)
329{
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100330 return (cs->conn->xprt->snd_pipe(cs->conn, cs->conn->xprt_ctx, pipe));
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200331}
Olivier Houchard7da120b2017-11-01 13:55:10 +0100332#endif
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200333
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200334static int mux_pt_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
335{
336 int ret = 0;
337 switch (mux_ctl) {
338 case MUX_STATUS:
Willy Tarreau911db9b2020-01-23 16:27:54 +0100339 if (!(conn->flags & CO_FL_WAIT_XPRT))
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200340 ret |= MUX_STATUS_READY;
341 return ret;
342 default:
343 return -1;
344 }
345}
346
Willy Tarreau53a47662017-08-28 10:53:00 +0200347/* The mux operations */
348const struct mux_ops mux_pt_ops = {
349 .init = mux_pt_init,
Willy Tarreau53a47662017-08-28 10:53:00 +0200350 .wake = mux_pt_wake,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200351 .rcv_buf = mux_pt_rcv_buf,
352 .snd_buf = mux_pt_snd_buf,
Olivier Houchard6ff20392018-07-17 18:46:31 +0200353 .subscribe = mux_pt_subscribe,
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200354 .unsubscribe = mux_pt_unsubscribe,
Willy Tarreaue5733232019-05-22 19:24:06 +0200355#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200356 .rcv_pipe = mux_pt_rcv_pipe,
357 .snd_pipe = mux_pt_snd_pipe,
358#endif
359 .attach = mux_pt_attach,
Willy Tarreaufafd3982018-11-18 21:29:20 +0100360 .get_first_cs = mux_pt_get_first_cs,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200361 .detach = mux_pt_detach,
Olivier Houchardd540b362018-11-05 18:37:53 +0100362 .avail_streams = mux_pt_avail_streams,
Willy Tarreau00f18a32019-01-26 12:19:01 +0100363 .used_streams = mux_pt_used_streams,
Olivier Houchard060ed432018-11-06 16:32:42 +0100364 .destroy = mux_pt_destroy_meth,
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200365 .ctl = mux_pt_ctl,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200366 .shutr = mux_pt_shutr,
367 .shutw = mux_pt_shutw,
Willy Tarreau28f1cb92017-12-20 16:14:44 +0100368 .flags = MX_FL_NONE,
Willy Tarreau53a47662017-08-28 10:53:00 +0200369 .name = "PASS",
370};
Willy Tarreauf6490822017-09-21 19:43:21 +0200371
Christopher Faulet32f61c02018-04-10 14:33:41 +0200372/* PROT selection : default mux has empty name */
373static struct mux_proto_list mux_proto_pt =
Christopher Faulet31930372019-07-15 10:16:58 +0200374 { .token = IST(""), .mode = PROTO_MODE_TCP, .side = PROTO_SIDE_BOTH, .mux = &mux_pt_ops };
Willy Tarreauf6490822017-09-21 19:43:21 +0200375
Willy Tarreau0108d902018-11-25 19:14:37 +0100376INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_pt);