blob: 5ba9c01b8152384b1507ed447cc9dbb4ce1be8f4 [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
13#include <common/config.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010014#include <common/initcall.h>
Willy Tarreau53a47662017-08-28 10:53:00 +020015#include <proto/connection.h>
16#include <proto/stream.h>
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010017#include <proto/task.h>
18
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 Faulet612e3072020-11-03 09:11:43 +010029 struct connection *conn = NULL;
Christopher Faulet39a96ee2019-04-08 10:52:21 +020030
Christopher Faulet612e3072020-11-03 09:11:43 +010031 if (ctx) {
32 /* The connection must be attached to this mux to be released */
33 if (ctx->conn && ctx->conn->ctx == ctx)
34 conn = ctx->conn;
35
Willy Tarreau3c39a7d2019-06-14 14:42:29 +020036 tasklet_free(ctx->wait_event.tasklet);
Christopher Faulet612e3072020-11-03 09:11:43 +010037
38 if (conn && ctx->wait_event.events != 0)
39 conn->xprt->unsubscribe(conn, conn->xprt_ctx, ctx->wait_event.events,
40 &ctx->wait_event);
41 pool_free(pool_head_pt_ctx, ctx);
42 }
43
44 if (conn) {
Christopher Faulet39a96ee2019-04-08 10:52:21 +020045 conn->mux = NULL;
46 conn->ctx = NULL;
Christopher Faulet612e3072020-11-03 09:11:43 +010047
48 conn_stop_tracking(conn);
49 conn_full_close(conn);
Christopher Faulet39a96ee2019-04-08 10:52:21 +020050 if (conn->destroy_cb)
51 conn->destroy_cb(conn);
Christopher Faulet39a96ee2019-04-08 10:52:21 +020052 conn_free(conn);
53 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010054}
55
56/* Callback, used when we get I/Os while in idle mode */
57static struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned short status)
58{
59 struct mux_pt_ctx *ctx = tctx;
60
Olivier Houcharda5115f22019-10-18 13:56:40 +020061 if (ctx->cs) {
62 /* There's a small race condition.
63 * mux_pt_io_cb() is only supposed to be called if we have no
64 * stream attached. However, maybe the tasklet got woken up,
65 * and this connection was then attached to a new stream.
Olivier Houchardaafb6cc2019-10-18 14:18:29 +020066 * If this happened, just wake the tasklet up if anybody
67 * subscribed to receive events, and otherwise call the wake
68 * method, to make sure the event is noticed.
Olivier Houcharda5115f22019-10-18 13:56:40 +020069 */
Olivier Houchardaafb6cc2019-10-18 14:18:29 +020070 if (ctx->conn->recv_wait) {
71 ctx->conn->recv_wait->events &= ~SUB_RETRY_RECV;
72 tasklet_wakeup(ctx->conn->recv_wait->tasklet);
73 ctx->conn->recv_wait = NULL;
74 } else if (ctx->cs->data_cb->wake)
Olivier Houcharda5115f22019-10-18 13:56:40 +020075 ctx->cs->data_cb->wake(ctx->cs);
76 return NULL;
77 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010078 conn_sock_drain(ctx->conn);
Olivier Houchard6d206de2019-10-18 10:59:30 +020079 if (ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))
80 mux_pt_destroy(ctx);
81 else
Olivier Houcharde179d0e2019-03-21 18:27:17 +010082 ctx->conn->xprt->subscribe(ctx->conn, ctx->conn->xprt_ctx, SUB_RETRY_RECV,
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010083 &ctx->wait_event);
84
85 return NULL;
86}
Willy Tarreau53a47662017-08-28 10:53:00 +020087
Willy Tarreau3d2ee552018-12-19 14:12:10 +010088/* Initialize the mux once it's attached. It is expected that conn->ctx
Olivier Houchard9aaf7782017-09-13 18:30:23 +020089 * points to the existing conn_stream (for outgoing connections) or NULL (for
90 * incoming ones, in which case one will be allocated and a new stream will be
91 * instanciated). Returns < 0 on error.
Willy Tarreau53a47662017-08-28 10:53:00 +020092 */
Christopher Faulet51f73eb2019-04-08 11:22:47 +020093static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess,
94 struct buffer *input)
Willy Tarreau53a47662017-08-28 10:53:00 +020095{
Willy Tarreau3d2ee552018-12-19 14:12:10 +010096 struct conn_stream *cs = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010097 struct mux_pt_ctx *ctx = pool_alloc(pool_head_pt_ctx);
98
99 if (!ctx)
100 goto fail;
101
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200102 ctx->wait_event.tasklet = tasklet_new();
103 if (!ctx->wait_event.tasklet)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100104 goto fail_free_ctx;
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200105 ctx->wait_event.tasklet->context = ctx;
106 ctx->wait_event.tasklet->process = mux_pt_io_cb;
Willy Tarreau4f6516d2018-12-19 13:59:17 +0100107 ctx->wait_event.events = 0;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100108 ctx->conn = conn;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200109
110 if (!cs) {
111 cs = cs_new(conn);
112 if (!cs)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100113 goto fail_free_ctx;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200114
115 if (stream_create_from_cs(cs) < 0)
116 goto fail_free;
117
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200118 }
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100119 conn->ctx = ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100120 ctx->cs = cs;
Olivier Houchard8706c812018-12-04 19:17:25 +0100121 cs->flags |= CS_FL_RCV_MORE;
Willy Tarreau7e9dd732020-01-17 16:19:34 +0100122 if (global.tune.options & GTUNE_USE_SPLICE)
123 cs->flags |= CS_FL_MAY_SPLICE;
Willy Tarreau53a47662017-08-28 10:53:00 +0200124 return 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200125
126 fail_free:
127 cs_free(cs);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100128fail_free_ctx:
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200129 if (ctx->wait_event.tasklet)
130 tasklet_free(ctx->wait_event.tasklet);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100131 pool_free(pool_head_pt_ctx, ctx);
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200132 fail:
133 return -1;
Willy Tarreau53a47662017-08-28 10:53:00 +0200134}
135
136/* callback to be used by default for the pass-through mux. It calls the data
137 * layer wake() callback if it is set otherwise returns 0.
138 */
139static int mux_pt_wake(struct connection *conn)
140{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100141 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100142 struct conn_stream *cs = ctx->cs;
143 int ret = 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200144
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100145 if (cs) {
146 ret = cs->data_cb->wake ? cs->data_cb->wake(cs) : 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200147
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100148 if (ret < 0)
149 return ret;
150 } else {
151 conn_sock_drain(conn);
152 if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) {
153 mux_pt_destroy(ctx);
154 return -1;
155 }
156 }
Willy Tarreauad7f0ad2018-08-24 15:48:59 +0200157
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100158 /* If we had early data, and we're done with the handshake
159 * then whe know the data are safe, and we can remove the flag.
160 */
161 if ((conn->flags & (CO_FL_EARLY_DATA | CO_FL_EARLY_SSL_HS | CO_FL_HANDSHAKE)) ==
162 CO_FL_EARLY_DATA)
163 conn->flags &= ~CO_FL_EARLY_DATA;
Willy Tarreaued339a32017-11-03 15:55:24 +0100164 return ret;
Willy Tarreau53a47662017-08-28 10:53:00 +0200165}
166
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200167/*
168 * Attach a new stream to a connection
169 * (Used for outgoing connections)
170 */
Olivier Houchardf502aca2018-12-14 19:42:40 +0100171static struct conn_stream *mux_pt_attach(struct connection *conn, struct session *sess)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200172{
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100173 struct conn_stream *cs;
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100174 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100175
Olivier Houcharda24832f2019-08-10 23:56:16 +0200176 if (ctx->wait_event.events)
177 conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100178 cs = cs_new(conn);
179 if (!cs)
180 goto fail;
181
182 ctx->cs = cs;
Olivier Houchard8706c812018-12-04 19:17:25 +0100183 cs->flags |= CS_FL_RCV_MORE;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100184 return (cs);
185fail:
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200186 return NULL;
187}
188
Willy Tarreaufafd3982018-11-18 21:29:20 +0100189/* Retrieves a valid conn_stream from this connection, or returns NULL. For
190 * this mux, it's easy as we can only store a single conn_stream.
191 */
192static const struct conn_stream *mux_pt_get_first_cs(const struct connection *conn)
193{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100194 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100195 struct conn_stream *cs = ctx->cs;
Willy Tarreaufafd3982018-11-18 21:29:20 +0100196
197 return cs;
198}
199
Christopher Faulet73c12072019-04-08 11:23:22 +0200200/* Destroy the mux and the associated connection if still attached to this mux
201 * and no longer used */
202static void mux_pt_destroy_meth(void *ctx)
Olivier Houchard060ed432018-11-06 16:32:42 +0100203{
Christopher Faulet73c12072019-04-08 11:23:22 +0200204 struct mux_pt_ctx *pt = ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100205
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200206 if (!(pt->cs) || !(pt->conn) || pt->conn->ctx != pt)
Christopher Faulet73c12072019-04-08 11:23:22 +0200207 mux_pt_destroy(pt);
Olivier Houchard060ed432018-11-06 16:32:42 +0100208}
209
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200210/*
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200211 * Detach the stream from the connection and possibly release the connection.
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200212 */
213static void mux_pt_detach(struct conn_stream *cs)
214{
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200215 struct connection *conn = cs->conn;
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100216 struct mux_pt_ctx *ctx = cs->conn->ctx;
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200217
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100218 /* Subscribe, to know if we got disconnected */
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100219 if (conn->owner != NULL &&
220 !(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) {
221 ctx->cs = NULL;
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100222 conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Olivier Houchard6d206de2019-10-18 10:59:30 +0200223 } else
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100224 /* There's no session attached to that connection, destroy it */
225 mux_pt_destroy(ctx);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200226}
227
Willy Tarreau00f18a32019-01-26 12:19:01 +0100228/* returns the number of streams in use on a connection */
229static int mux_pt_used_streams(struct connection *conn)
Olivier Houchardd540b362018-11-05 18:37:53 +0100230{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100231 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardd540b362018-11-05 18:37:53 +0100232
Willy Tarreau00f18a32019-01-26 12:19:01 +0100233 return ctx->cs ? 1 : 0;
Olivier Houchardd540b362018-11-05 18:37:53 +0100234}
235
Willy Tarreau00f18a32019-01-26 12:19:01 +0100236/* returns the number of streams still available on a connection */
237static int mux_pt_avail_streams(struct connection *conn)
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100238{
Willy Tarreau00f18a32019-01-26 12:19:01 +0100239 return 1 - mux_pt_used_streams(conn);
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100240}
241
Willy Tarreauecdb3fe2017-10-05 15:25:48 +0200242static void mux_pt_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200243{
Willy Tarreau4b795242017-10-05 18:47:38 +0200244 if (cs->flags & CS_FL_SHR)
245 return;
Christopher Fauletd94f8772018-12-17 13:21:02 +0100246 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200247 if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutr)
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100248 cs->conn->xprt->shutr(cs->conn, cs->conn->xprt_ctx,
249 (mode == CS_SHR_DRAIN));
Willy Tarreau4b795242017-10-05 18:47:38 +0200250 if (cs->flags & CS_FL_SHW)
251 conn_full_close(cs->conn);
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100252 /* Maybe we've been put in the list of available idle connections,
253 * get ouf of here
254 */
255 LIST_DEL(&cs->conn->list);
256 LIST_INIT(&cs->conn->list);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200257}
258
Willy Tarreauecdb3fe2017-10-05 15:25:48 +0200259static void mux_pt_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200260{
Willy Tarreau4b795242017-10-05 18:47:38 +0200261 if (cs->flags & CS_FL_SHW)
262 return;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200263 if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutw)
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100264 cs->conn->xprt->shutw(cs->conn, cs->conn->xprt_ctx,
265 (mode == CS_SHW_NORMAL));
Willy Tarreau4b795242017-10-05 18:47:38 +0200266 if (!(cs->flags & CS_FL_SHR))
Willy Tarreaua48c1412017-12-22 18:46:33 +0100267 conn_sock_shutw(cs->conn, (mode == CS_SHW_NORMAL));
Willy Tarreau4b795242017-10-05 18:47:38 +0200268 else
269 conn_full_close(cs->conn);
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100270 /* Maybe we've been put in the list of available idle connections,
271 * get ouf of here
272 */
273 LIST_DEL(&cs->conn->list);
274 LIST_INIT(&cs->conn->list);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200275}
276
277/*
278 * Called from the upper layer, to get more data
279 */
Willy Tarreau7f3225f2018-06-19 06:15:17 +0200280static 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 +0200281{
Willy Tarreaud9cf5402018-07-18 11:29:06 +0200282 size_t ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200283
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200284 if (!count) {
Christopher Fauletd94f8772018-12-17 13:21:02 +0100285 cs->flags |= (CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200286 return 0;
287 }
Willy Tarreaue0f24ee2018-12-14 10:51:23 +0100288 b_realign_if_empty(buf);
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100289 ret = cs->conn->xprt->rcv_buf(cs->conn, cs->conn->xprt_ctx, buf, count, flags);
Olivier Houchard8706c812018-12-04 19:17:25 +0100290 if (conn_xprt_read0_pending(cs->conn)) {
Willy Tarreaua9559572019-07-15 06:47:54 +0200291 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Christopher Faulet87a8f352019-03-22 14:51:36 +0100292 cs->flags |= CS_FL_EOS;
Olivier Houchard8706c812018-12-04 19:17:25 +0100293 }
294 if (cs->conn->flags & CO_FL_ERROR) {
Willy Tarreaua9559572019-07-15 06:47:54 +0200295 cs->flags &= ~(CS_FL_RCV_MORE | CS_FL_WANT_ROOM);
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200296 cs->flags |= CS_FL_ERROR;
Olivier Houchard8706c812018-12-04 19:17:25 +0100297 }
Willy Tarreaud9cf5402018-07-18 11:29:06 +0200298 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200299}
300
301/* Called from the upper layer, to send data */
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200302static 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 +0200303{
Olivier Houchardb72d98a2018-11-30 13:17:48 +0100304 size_t ret;
305
306 if (cs->conn->flags & CO_FL_HANDSHAKE)
307 return 0;
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100308 ret = cs->conn->xprt->snd_buf(cs->conn, cs->conn->xprt_ctx, buf, count, flags);
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200309
310 if (ret > 0)
311 b_del(buf, ret);
312 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200313}
314
Olivier Houchard6ff20392018-07-17 18:46:31 +0200315/* Called from the upper layer, to subscribe to events */
316static int mux_pt_subscribe(struct conn_stream *cs, int event_type, void *param)
317{
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100318 return (cs->conn->xprt->subscribe(cs->conn, cs->conn->xprt_ctx, event_type, param));
Olivier Houchard6ff20392018-07-17 18:46:31 +0200319}
320
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200321static int mux_pt_unsubscribe(struct conn_stream *cs, int event_type, void *param)
322{
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100323 return (cs->conn->xprt->unsubscribe(cs->conn, cs->conn->xprt_ctx, event_type, param));
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200324}
325
Willy Tarreaue5733232019-05-22 19:24:06 +0200326#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200327/* Send and get, using splicing */
328static int mux_pt_rcv_pipe(struct conn_stream *cs, struct pipe *pipe, unsigned int count)
329{
330 int ret;
331
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100332 ret = cs->conn->xprt->rcv_pipe(cs->conn, cs->conn->xprt_ctx, pipe, count);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200333 if (conn_xprt_read0_pending(cs->conn))
Christopher Faulet87a8f352019-03-22 14:51:36 +0100334 cs->flags |= CS_FL_EOS;
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200335 if (cs->conn->flags & CO_FL_ERROR)
336 cs->flags |= CS_FL_ERROR;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200337 return (ret);
338}
339
340static int mux_pt_snd_pipe(struct conn_stream *cs, struct pipe *pipe)
341{
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100342 return (cs->conn->xprt->snd_pipe(cs->conn, cs->conn->xprt_ctx, pipe));
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200343}
Olivier Houchard7da120b2017-11-01 13:55:10 +0100344#endif
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200345
Olivier Houchard198d1292019-10-25 16:19:26 +0200346static int mux_pt_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
347{
348 int ret = 0;
349 switch (mux_ctl) {
350 case MUX_STATUS:
351 if (conn->flags & CO_FL_CONNECTED)
352 ret |= MUX_STATUS_READY;
353 return ret;
354 default:
355 return -1;
356 }
357}
358
Willy Tarreau53a47662017-08-28 10:53:00 +0200359/* The mux operations */
360const struct mux_ops mux_pt_ops = {
361 .init = mux_pt_init,
Willy Tarreau53a47662017-08-28 10:53:00 +0200362 .wake = mux_pt_wake,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200363 .rcv_buf = mux_pt_rcv_buf,
364 .snd_buf = mux_pt_snd_buf,
Olivier Houchard6ff20392018-07-17 18:46:31 +0200365 .subscribe = mux_pt_subscribe,
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200366 .unsubscribe = mux_pt_unsubscribe,
Willy Tarreaue5733232019-05-22 19:24:06 +0200367#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200368 .rcv_pipe = mux_pt_rcv_pipe,
369 .snd_pipe = mux_pt_snd_pipe,
370#endif
371 .attach = mux_pt_attach,
Willy Tarreaufafd3982018-11-18 21:29:20 +0100372 .get_first_cs = mux_pt_get_first_cs,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200373 .detach = mux_pt_detach,
Olivier Houchardd540b362018-11-05 18:37:53 +0100374 .avail_streams = mux_pt_avail_streams,
Willy Tarreau00f18a32019-01-26 12:19:01 +0100375 .used_streams = mux_pt_used_streams,
Olivier Houchard060ed432018-11-06 16:32:42 +0100376 .destroy = mux_pt_destroy_meth,
Olivier Houchard198d1292019-10-25 16:19:26 +0200377 .ctl = mux_pt_ctl,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200378 .shutr = mux_pt_shutr,
379 .shutw = mux_pt_shutw,
Willy Tarreau28f1cb92017-12-20 16:14:44 +0100380 .flags = MX_FL_NONE,
Willy Tarreau53a47662017-08-28 10:53:00 +0200381 .name = "PASS",
382};
Willy Tarreauf6490822017-09-21 19:43:21 +0200383
Christopher Faulet32f61c02018-04-10 14:33:41 +0200384/* PROT selection : default mux has empty name */
385static struct mux_proto_list mux_proto_pt =
386 { .token = IST(""), .mode = PROTO_MODE_ANY, .side = PROTO_SIDE_BOTH, .mux = &mux_pt_ops };
Willy Tarreauf6490822017-09-21 19:43:21 +0200387
Willy Tarreau0108d902018-11-25 19:14:37 +0100388INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_pt);