blob: 97b3b835da0942edfcff8db040303b8291f2fd29 [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>
Christopher Faulet1329f2a2021-12-16 17:32:56 +010016#include <haproxy/conn_stream.h>
Christopher Fauletc0ae0972021-04-08 16:45:11 +020017#include <haproxy/pipe-t.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020018#include <haproxy/stream.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020019#include <haproxy/task.h>
Christopher Fauletc0ae0972021-04-08 16:45:11 +020020#include <haproxy/trace.h>
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010021
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010022struct mux_pt_ctx {
23 struct conn_stream *cs;
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +010024 struct cs_endpoint *endp;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +010025 struct connection *conn;
26 struct wait_event wait_event;
27};
28
Willy Tarreau8ceae722018-11-26 11:58:30 +010029DECLARE_STATIC_POOL(pool_head_pt_ctx, "mux_pt", sizeof(struct mux_pt_ctx));
30
Christopher Fauletc0ae0972021-04-08 16:45:11 +020031/* trace source and events */
32static void pt_trace(enum trace_level level, uint64_t mask,
33 const struct trace_source *src,
34 const struct ist where, const struct ist func,
35 const void *a1, const void *a2, const void *a3, const void *a4);
36
37/* The event representation is split like this :
38 * pt_ctx - internal PT context
39 * strm - application layer
40 */
41static const struct trace_event pt_trace_events[] = {
42#define PT_EV_CONN_NEW (1ULL << 0)
43 { .mask = PT_EV_CONN_NEW, .name = "pt_conn_new", .desc = "new PT connection" },
44#define PT_EV_CONN_WAKE (1ULL << 1)
45 { .mask = PT_EV_CONN_WAKE, .name = "pt_conn_wake", .desc = "PT connection woken up" },
46#define PT_EV_CONN_END (1ULL << 2)
47 { .mask = PT_EV_CONN_END, .name = "pt_conn_end", .desc = "PT connection terminated" },
48#define PT_EV_CONN_ERR (1ULL << 3)
49 { .mask = PT_EV_CONN_ERR, .name = "pt_conn_err", .desc = "error on PT connection" },
50#define PT_EV_STRM_NEW (1ULL << 4)
51 { .mask = PT_EV_STRM_NEW, .name = "strm_new", .desc = "app-layer stream creation" },
52#define PT_EV_STRM_SHUT (1ULL << 5)
53 { .mask = PT_EV_STRM_SHUT, .name = "strm_shut", .desc = "stream shutdown" },
54#define PT_EV_STRM_END (1ULL << 6)
55 { .mask = PT_EV_STRM_END, .name = "strm_end", .desc = "detaching app-layer stream" },
56#define PT_EV_STRM_ERR (1ULL << 7)
57 { .mask = PT_EV_STRM_ERR, .name = "strm_err", .desc = "stream error" },
58#define PT_EV_RX_DATA (1ULL << 8)
59 { .mask = PT_EV_RX_DATA, .name = "pt_rx_data", .desc = "Rx on PT connection" },
60#define PT_EV_TX_DATA (1ULL << 9)
61 { .mask = PT_EV_TX_DATA, .name = "pt_tx_data", .desc = "Tx on PT connection" },
62
63 {}
64};
65
66
67static const struct name_desc pt_trace_decoding[] = {
68#define PT_VERB_CLEAN 1
69 { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" },
70#define PT_VERB_MINIMAL 2
71 { .name="minimal", .desc="report only h1c/h1s state and flags, no real decoding" },
72#define PT_VERB_SIMPLE 3
73 { .name="simple", .desc="add request/response status line or htx info when available" },
74#define PT_VERB_ADVANCED 4
75 { .name="advanced", .desc="add header fields or frame decoding when available" },
76#define PT_VERB_COMPLETE 5
77 { .name="complete", .desc="add full data dump when available" },
78 { /* end */ }
79};
80
Willy Tarreau6eb3d372021-04-10 19:29:26 +020081static struct trace_source trace_pt __read_mostly = {
Christopher Fauletc0ae0972021-04-08 16:45:11 +020082 .name = IST("pt"),
83 .desc = "Passthrough multiplexer",
84 .arg_def = TRC_ARG1_CONN, // TRACE()'s first argument is always a connection
85 .default_cb = pt_trace,
86 .known_events = pt_trace_events,
87 .lockon_args = NULL,
88 .decoding = pt_trace_decoding,
89 .report_events = ~0, // report everything by default
90};
91
92#define TRACE_SOURCE &trace_pt
93INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
94
95static inline void pt_trace_buf(const struct buffer *buf, size_t ofs, size_t len)
96{
97 size_t block1, block2;
98 int line, ptr, newptr;
99
100 block1 = b_contig_data(buf, ofs);
101 block2 = 0;
102 if (block1 > len)
103 block1 = len;
104 block2 = len - block1;
105
106 ofs = b_peek_ofs(buf, ofs);
107
108 line = 0;
109 ptr = ofs;
110 while (ptr < ofs + block1) {
111 newptr = dump_text_line(&trace_buf, b_orig(buf), b_size(buf), ofs + block1, &line, ptr);
112 if (newptr == ptr)
113 break;
114 ptr = newptr;
115 }
116
117 line = ptr = 0;
118 while (ptr < block2) {
119 newptr = dump_text_line(&trace_buf, b_orig(buf), b_size(buf), block2, &line, ptr);
120 if (newptr == ptr)
121 break;
122 ptr = newptr;
123 }
124}
125
126/* the PT traces always expect that arg1, if non-null, is of type connection
127 * (from which we can derive the pt context), that arg2, if non-null, is a
128 * conn-stream, and that arg3, if non-null, is a buffer.
129 */
130static void pt_trace(enum trace_level level, uint64_t mask, const struct trace_source *src,
131 const struct ist where, const struct ist func,
132 const void *a1, const void *a2, const void *a3, const void *a4)
133{
134 const struct connection *conn = a1;
135 const struct mux_pt_ctx *ctx = conn ? conn->ctx : NULL;
136 const struct conn_stream *cs = a2;
137 const struct buffer *buf = a3;
138 const size_t *val = a4;
139
Christopher Faulet1bceee22022-03-24 10:51:08 +0100140 if (!ctx || src->verbosity < PT_VERB_CLEAN)
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200141 return;
142
143 /* Display frontend/backend info by default */
144 chunk_appendf(&trace_buf, " : [%c]", (conn_is_back(conn) ? 'B' : 'F'));
145
146 if (src->verbosity == PT_VERB_CLEAN)
147 return;
148
Christopher Faulet1bceee22022-03-24 10:51:08 +0100149 if (!cs)
150 cs = ctx->cs;
151
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200152 /* Display the value to the 4th argument (level > STATE) */
153 if (src->level > TRACE_LEVEL_STATE && val)
154 chunk_appendf(&trace_buf, " - VAL=%lu", (long)*val);
155
156 /* Display conn and cs info, if defined (pointer + flags) */
157 chunk_appendf(&trace_buf, " - conn=%p(0x%08x)", conn, conn->flags);
Christopher Faulet1bceee22022-03-24 10:51:08 +0100158 chunk_appendf(&trace_buf, " endp=%p(0x%08x)", ctx->endp, ctx->endp->flags);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200159 if (cs)
160 chunk_appendf(&trace_buf, " cs=%p(0x%08x)", cs, cs->flags);
161
162 if (src->verbosity == PT_VERB_MINIMAL)
163 return;
164
165 /* Display buffer info, if defined (level > USER & verbosity > SIMPLE) */
166 if (src->level > TRACE_LEVEL_USER && buf) {
167 int full = 0, max = 3000, chunk = 1024;
168
169 /* Full info (level > STATE && verbosity > SIMPLE) */
170 if (src->level > TRACE_LEVEL_STATE) {
171 if (src->verbosity == PT_VERB_COMPLETE)
172 full = 1;
173 else if (src->verbosity == PT_VERB_ADVANCED) {
174 full = 1;
175 max = 256;
176 chunk = 64;
177 }
178 }
179
180 chunk_appendf(&trace_buf, " buf=%u@%p+%u/%u",
181 (unsigned int)b_data(buf), b_orig(buf),
182 (unsigned int)b_head_ofs(buf), (unsigned int)b_size(buf));
183
184 if (b_data(buf) && full) {
185 chunk_memcat(&trace_buf, "\n", 1);
186 if (b_data(buf) < max)
187 pt_trace_buf(buf, 0, b_data(buf));
188 else {
189 pt_trace_buf(buf, 0, chunk);
190 chunk_memcat(&trace_buf, " ...\n", 6);
191 pt_trace_buf(buf, b_data(buf) - chunk, chunk);
192 }
193 }
194 }
195}
196
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100197static void mux_pt_destroy(struct mux_pt_ctx *ctx)
198{
Christopher Faulet5a7ca292020-11-03 09:11:43 +0100199 struct connection *conn = NULL;
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200200
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200201 TRACE_POINT(PT_EV_CONN_END);
202
Christopher Faulet5a7ca292020-11-03 09:11:43 +0100203 if (ctx) {
204 /* The connection must be attached to this mux to be released */
205 if (ctx->conn && ctx->conn->ctx == ctx)
206 conn = ctx->conn;
207
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200208 TRACE_DEVEL("freeing pt context", PT_EV_CONN_END, conn);
209
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200210 tasklet_free(ctx->wait_event.tasklet);
Christopher Faulet5a7ca292020-11-03 09:11:43 +0100211
212 if (conn && ctx->wait_event.events != 0)
213 conn->xprt->unsubscribe(conn, conn->xprt_ctx, ctx->wait_event.events,
214 &ctx->wait_event);
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100215 BUG_ON(ctx->endp && !(ctx->endp->flags & CS_EP_ORPHAN));
216 cs_endpoint_free(ctx->endp);
Christopher Faulet5a7ca292020-11-03 09:11:43 +0100217 pool_free(pool_head_pt_ctx, ctx);
218 }
219
220 if (conn) {
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200221 conn->mux = NULL;
222 conn->ctx = NULL;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200223 TRACE_DEVEL("freeing conn", PT_EV_CONN_END, conn);
Christopher Faulet5a7ca292020-11-03 09:11:43 +0100224
225 conn_stop_tracking(conn);
226 conn_full_close(conn);
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200227 if (conn->destroy_cb)
228 conn->destroy_cb(conn);
Christopher Faulet39a96ee2019-04-08 10:52:21 +0200229 conn_free(conn);
230 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100231}
232
Willy Tarreau691d5032021-01-20 14:55:01 +0100233/* Callback, used when we get I/Os while in idle mode. This one is exported so
234 * that "show fd" can resolve it.
235 */
Willy Tarreau144f84a2021-03-02 16:09:26 +0100236struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned int status)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100237{
238 struct mux_pt_ctx *ctx = tctx;
239
Christopher Faulet1bceee22022-03-24 10:51:08 +0100240 TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn);
241 if (!(ctx->endp->flags & CS_EP_ORPHAN)) {
Olivier Houchardea510fc2019-10-18 13:56:40 +0200242 /* There's a small race condition.
243 * mux_pt_io_cb() is only supposed to be called if we have no
244 * stream attached. However, maybe the tasklet got woken up,
245 * and this connection was then attached to a new stream.
Olivier Houchard2ed389d2019-10-18 14:18:29 +0200246 * If this happened, just wake the tasklet up if anybody
247 * subscribed to receive events, and otherwise call the wake
248 * method, to make sure the event is noticed.
Olivier Houchardea510fc2019-10-18 13:56:40 +0200249 */
Willy Tarreau7872d1f2020-01-10 07:06:05 +0100250 if (ctx->conn->subs) {
251 ctx->conn->subs->events = 0;
252 tasklet_wakeup(ctx->conn->subs->tasklet);
253 ctx->conn->subs = NULL;
Olivier Houchard2ed389d2019-10-18 14:18:29 +0200254 } else if (ctx->cs->data_cb->wake)
Olivier Houchardea510fc2019-10-18 13:56:40 +0200255 ctx->cs->data_cb->wake(ctx->cs);
Christopher Faulet1bceee22022-03-24 10:51:08 +0100256 TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn);
Willy Tarreau74163142021-03-13 11:30:19 +0100257 return t;
Olivier Houchardea510fc2019-10-18 13:56:40 +0200258 }
Willy Tarreau2ded48d2020-12-11 16:20:34 +0100259 conn_ctrl_drain(ctx->conn);
Willy Tarreau74163142021-03-13 11:30:19 +0100260 if (ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH)) {
Christopher Faulete2c65ba2021-04-10 09:02:32 +0200261 TRACE_DEVEL("leaving destroying pt context", PT_EV_CONN_WAKE, ctx->conn);
Olivier Houchard9dce2c52019-10-18 10:59:30 +0200262 mux_pt_destroy(ctx);
Willy Tarreau74163142021-03-13 11:30:19 +0100263 t = NULL;
264 }
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200265 else {
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100266 ctx->conn->xprt->subscribe(ctx->conn, ctx->conn->xprt_ctx, SUB_RETRY_RECV,
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200267 &ctx->wait_event);
Christopher Faulete2c65ba2021-04-10 09:02:32 +0200268 TRACE_DEVEL("leaving subscribing for reads", PT_EV_CONN_WAKE, ctx->conn);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200269 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100270
Willy Tarreau74163142021-03-13 11:30:19 +0100271 return t;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100272}
Willy Tarreau53a47662017-08-28 10:53:00 +0200273
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100274/* Initialize the mux once it's attached. It is expected that conn->ctx
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200275 * points to the existing conn_stream (for outgoing connections) or NULL (for
276 * incoming ones, in which case one will be allocated and a new stream will be
Ilya Shipitsin46a030c2020-07-05 16:36:08 +0500277 * instantiated). Returns < 0 on error.
Willy Tarreau53a47662017-08-28 10:53:00 +0200278 */
Christopher Faulet51f73eb2019-04-08 11:22:47 +0200279static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess,
280 struct buffer *input)
Willy Tarreau53a47662017-08-28 10:53:00 +0200281{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100282 struct conn_stream *cs = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100283 struct mux_pt_ctx *ctx = pool_alloc(pool_head_pt_ctx);
284
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200285 TRACE_ENTER(PT_EV_CONN_NEW);
286
287 if (!ctx) {
288 TRACE_ERROR("PT context allocation failure", PT_EV_CONN_NEW|PT_EV_CONN_END|PT_EV_CONN_ERR);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100289 goto fail;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200290 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100291
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200292 ctx->wait_event.tasklet = tasklet_new();
293 if (!ctx->wait_event.tasklet)
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100294 goto fail_free_ctx;
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200295 ctx->wait_event.tasklet->context = ctx;
296 ctx->wait_event.tasklet->process = mux_pt_io_cb;
Willy Tarreau4f6516d2018-12-19 13:59:17 +0100297 ctx->wait_event.events = 0;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100298 ctx->conn = conn;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200299
300 if (!cs) {
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100301 ctx->endp = cs_endpoint_new();
302 if (!ctx->endp) {
303 TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn);
Christopher Fauletb669d682022-03-22 18:37:19 +0100304 goto fail_free_ctx;
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100305 }
306 ctx->endp->target = ctx;
307 ctx->endp->ctx = conn;
308 ctx->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN);
Christopher Fauleta9e8b392022-03-23 11:01:09 +0100309
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100310 cs = cs_new_from_mux(ctx->endp, sess, input);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200311 if (!cs) {
312 TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn);
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100313 goto fail_free_endp;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200314 }
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200315 TRACE_POINT(PT_EV_STRM_NEW, conn, cs);
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200316 }
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100317 else {
Christopher Faulet070b91b2022-03-31 19:27:18 +0200318 if (cs_attach_mux(cs, ctx, conn) < 0)
319 goto fail_free_ctx;
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100320 ctx->endp = cs->endp;
321 }
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100322 conn->ctx = ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100323 ctx->cs = cs;
Christopher Faulet1bceee22022-03-24 10:51:08 +0100324 ctx->endp->flags |= CS_EP_RCV_MORE;
Willy Tarreau17ccd1a2020-01-17 16:19:34 +0100325 if (global.tune.options & GTUNE_USE_SPLICE)
Christopher Faulet1bceee22022-03-24 10:51:08 +0100326 ctx->endp->flags |= CS_EP_MAY_SPLICE;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200327
Christopher Faulet1bceee22022-03-24 10:51:08 +0100328 TRACE_LEAVE(PT_EV_CONN_NEW, conn);
Willy Tarreau53a47662017-08-28 10:53:00 +0200329 return 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200330
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100331 fail_free_endp:
332 cs_endpoint_free(ctx->endp);
Christopher Fauleta9e8b392022-03-23 11:01:09 +0100333 fail_free_ctx:
Willy Tarreau3c39a7d2019-06-14 14:42:29 +0200334 if (ctx->wait_event.tasklet)
335 tasklet_free(ctx->wait_event.tasklet);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100336 pool_free(pool_head_pt_ctx, ctx);
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200337 fail:
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200338 TRACE_DEVEL("leaving in error", PT_EV_CONN_NEW|PT_EV_CONN_END|PT_EV_CONN_ERR);
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200339 return -1;
Willy Tarreau53a47662017-08-28 10:53:00 +0200340}
341
342/* callback to be used by default for the pass-through mux. It calls the data
343 * layer wake() callback if it is set otherwise returns 0.
344 */
345static int mux_pt_wake(struct connection *conn)
346{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100347 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100348 int ret = 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200349
Christopher Faulet1bceee22022-03-24 10:51:08 +0100350 TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn);
351 if (!(ctx->endp->flags & CS_EP_ORPHAN)) {
352 ret = ctx->cs->data_cb->wake ? ctx->cs->data_cb->wake(ctx->cs) : 0;
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200353
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200354 if (ret < 0) {
Christopher Faulet1bceee22022-03-24 10:51:08 +0100355 TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100356 return ret;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200357 }
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100358 } else {
Willy Tarreau2ded48d2020-12-11 16:20:34 +0100359 conn_ctrl_drain(conn);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100360 if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) {
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200361 TRACE_DEVEL("leaving destroying PT context", PT_EV_CONN_WAKE, ctx->conn);
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100362 mux_pt_destroy(ctx);
363 return -1;
364 }
365 }
Willy Tarreauad7f0ad2018-08-24 15:48:59 +0200366
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100367 /* If we had early data, and we're done with the handshake
Ilya Shipitsin46a030c2020-07-05 16:36:08 +0500368 * then we know the data are safe, and we can remove the flag.
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100369 */
Willy Tarreau911db9b2020-01-23 16:27:54 +0100370 if ((conn->flags & (CO_FL_EARLY_DATA | CO_FL_EARLY_SSL_HS | CO_FL_WAIT_XPRT)) ==
Olivier Houchard7fc96d52017-11-23 18:25:47 +0100371 CO_FL_EARLY_DATA)
372 conn->flags &= ~CO_FL_EARLY_DATA;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200373
374 TRACE_LEAVE(PT_EV_CONN_WAKE, ctx->conn);
Willy Tarreaued339a32017-11-03 15:55:24 +0100375 return ret;
Willy Tarreau53a47662017-08-28 10:53:00 +0200376}
377
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200378/*
379 * Attach a new stream to a connection
380 * (Used for outgoing connections)
381 */
Christopher Faulete00ad352021-12-16 14:44:31 +0100382static int mux_pt_attach(struct connection *conn, struct conn_stream *cs, struct session *sess)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200383{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100384 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100385
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200386 TRACE_ENTER(PT_EV_STRM_NEW, conn);
Olivier Houchardea32b0f2019-08-10 23:56:16 +0200387 if (ctx->wait_event.events)
388 conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Christopher Faulet070b91b2022-03-31 19:27:18 +0200389 if (cs_attach_mux(cs, ctx, conn) < 0)
390 return -1;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100391 ctx->cs = cs;
Christopher Faulet1bceee22022-03-24 10:51:08 +0100392 ctx->endp = cs->endp;
393 ctx->endp->flags |= CS_EP_RCV_MORE;
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200394
395 TRACE_LEAVE(PT_EV_STRM_NEW, conn, cs);
Christopher Faulete00ad352021-12-16 14:44:31 +0100396 return 0;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200397}
398
Willy Tarreaufafd3982018-11-18 21:29:20 +0100399/* Retrieves a valid conn_stream from this connection, or returns NULL. For
400 * this mux, it's easy as we can only store a single conn_stream.
401 */
402static const struct conn_stream *mux_pt_get_first_cs(const struct connection *conn)
403{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100404 struct mux_pt_ctx *ctx = conn->ctx;
Willy Tarreaufafd3982018-11-18 21:29:20 +0100405
Christopher Faulet1bceee22022-03-24 10:51:08 +0100406 return ctx->cs;
Willy Tarreaufafd3982018-11-18 21:29:20 +0100407}
408
Christopher Faulet73c12072019-04-08 11:23:22 +0200409/* Destroy the mux and the associated connection if still attached to this mux
410 * and no longer used */
411static void mux_pt_destroy_meth(void *ctx)
Olivier Houchard060ed432018-11-06 16:32:42 +0100412{
Christopher Faulet73c12072019-04-08 11:23:22 +0200413 struct mux_pt_ctx *pt = ctx;
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100414
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200415 TRACE_POINT(PT_EV_CONN_END, pt->conn, pt->cs);
Christopher Faulet1bceee22022-03-24 10:51:08 +0100416 if ((pt->endp->flags & CS_EP_ORPHAN) || !(pt->conn) || pt->conn->ctx != pt) {
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100417 if (pt->conn->ctx != pt)
418 pt->endp = NULL;
Christopher Faulet73c12072019-04-08 11:23:22 +0200419 mux_pt_destroy(pt);
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100420 }
Olivier Houchard060ed432018-11-06 16:32:42 +0100421}
422
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200423/*
Willy Tarreau2c52a2b2017-10-08 11:00:17 +0200424 * Detach the stream from the connection and possibly release the connection.
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200425 */
426static void mux_pt_detach(struct conn_stream *cs)
427{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100428 struct connection *conn = __cs_conn(cs);
Christopher Faulet2da02ae2022-02-24 13:45:27 +0100429 struct mux_pt_ctx *ctx;
430
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200431 TRACE_ENTER(PT_EV_STRM_END, conn, cs);
432
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100433 ctx = conn->ctx;
434 ctx->cs = NULL;
435
Olivier Houchardb6c32ee2018-11-05 18:28:43 +0100436 /* Subscribe, to know if we got disconnected */
Christopher Fauletfbff8542022-03-09 15:55:58 +0100437 if (!conn_is_back(conn) && conn->owner != NULL &&
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100438 !(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) {
Olivier Houcharde179d0e2019-03-21 18:27:17 +0100439 conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200440 } else {
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100441 /* There's no session attached to that connection, destroy it */
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200442 TRACE_DEVEL("killing dead connection", PT_EV_STRM_END, conn, cs);
Olivier Houchard7c6f8b12018-11-13 16:48:36 +0100443 mux_pt_destroy(ctx);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200444 }
445
446 TRACE_LEAVE(PT_EV_STRM_END);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200447}
448
Willy Tarreau00f18a32019-01-26 12:19:01 +0100449/* returns the number of streams in use on a connection */
450static int mux_pt_used_streams(struct connection *conn)
Olivier Houchardd540b362018-11-05 18:37:53 +0100451{
Willy Tarreau3d2ee552018-12-19 14:12:10 +0100452 struct mux_pt_ctx *ctx = conn->ctx;
Olivier Houchardd540b362018-11-05 18:37:53 +0100453
Christopher Faulet1bceee22022-03-24 10:51:08 +0100454 return (!(ctx->endp->flags & CS_EP_ORPHAN) ? 1 : 0);
Olivier Houchardd540b362018-11-05 18:37:53 +0100455}
456
Willy Tarreau00f18a32019-01-26 12:19:01 +0100457/* returns the number of streams still available on a connection */
458static int mux_pt_avail_streams(struct connection *conn)
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100459{
Willy Tarreau00f18a32019-01-26 12:19:01 +0100460 return 1 - mux_pt_used_streams(conn);
Olivier Houchard8defe4b2018-12-02 01:31:17 +0100461}
462
Christopher Faulet07976562022-03-31 11:05:05 +0200463static void mux_pt_shutr(struct conn_stream *cs, enum co_shr_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200464{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100465 struct connection *conn = __cs_conn(cs);
Christopher Faulet897d6122021-12-17 17:28:35 +0100466
467 TRACE_ENTER(PT_EV_STRM_SHUT, conn, cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200468
Christopher Faulete9e48202022-03-22 18:13:29 +0100469 if (cs->endp->flags & CS_EP_SHR)
Willy Tarreau4b795242017-10-05 18:47:38 +0200470 return;
Christopher Fauletb041b232022-03-24 10:27:02 +0100471 cs->endp->flags &= ~(CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
Christopher Faulet897d6122021-12-17 17:28:35 +0100472 if (conn_xprt_ready(conn) && conn->xprt->shutr)
473 conn->xprt->shutr(conn, conn->xprt_ctx,
Christopher Faulet07976562022-03-31 11:05:05 +0200474 (mode == CO_SHR_DRAIN));
475 else if (mode == CO_SHR_DRAIN)
Christopher Faulet897d6122021-12-17 17:28:35 +0100476 conn_ctrl_drain(conn);
Christopher Faulete9e48202022-03-22 18:13:29 +0100477 if (cs->endp->flags & CS_EP_SHW)
Christopher Faulet897d6122021-12-17 17:28:35 +0100478 conn_full_close(conn);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200479
Christopher Faulet897d6122021-12-17 17:28:35 +0100480 TRACE_LEAVE(PT_EV_STRM_SHUT, conn, cs);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200481}
482
Christopher Faulet07976562022-03-31 11:05:05 +0200483static void mux_pt_shutw(struct conn_stream *cs, enum co_shw_mode mode)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200484{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100485 struct connection *conn = __cs_conn(cs);
Christopher Faulet897d6122021-12-17 17:28:35 +0100486
487 TRACE_ENTER(PT_EV_STRM_SHUT, conn, cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200488
Christopher Faulete9e48202022-03-22 18:13:29 +0100489 if (cs->endp->flags & CS_EP_SHW)
Willy Tarreau4b795242017-10-05 18:47:38 +0200490 return;
Christopher Faulet897d6122021-12-17 17:28:35 +0100491 if (conn_xprt_ready(conn) && conn->xprt->shutw)
492 conn->xprt->shutw(conn, conn->xprt_ctx,
Christopher Faulet07976562022-03-31 11:05:05 +0200493 (mode == CO_SHW_NORMAL));
Christopher Faulete9e48202022-03-22 18:13:29 +0100494 if (!(cs->endp->flags & CS_EP_SHR))
Christopher Faulet07976562022-03-31 11:05:05 +0200495 conn_sock_shutw(conn, (mode == CO_SHW_NORMAL));
Willy Tarreau4b795242017-10-05 18:47:38 +0200496 else
Christopher Faulet897d6122021-12-17 17:28:35 +0100497 conn_full_close(conn);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200498
Christopher Faulet897d6122021-12-17 17:28:35 +0100499 TRACE_LEAVE(PT_EV_STRM_SHUT, conn, cs);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200500}
501
502/*
503 * Called from the upper layer, to get more data
Christopher Faulet564e39c2021-09-21 15:50:55 +0200504 *
505 * The caller is responsible for defragmenting <buf> if necessary. But <flags>
506 * must be tested to know the calling context. If CO_RFL_BUF_FLUSH is set, it
507 * means the caller wants to flush input data (from the mux buffer and the
508 * channel buffer) to be able to use kernel splicing or any kind of mux-to-mux
509 * xfer. If CO_RFL_KEEP_RECV is set, the mux must always subscribe for read
510 * events before giving back. CO_RFL_BUF_WET is set if <buf> is congested with
511 * data scheduled for leaving soon. CO_RFL_BUF_NOT_STUCK is set to instruct the
512 * mux it may optimize the data copy to <buf> if necessary. Otherwise, it should
513 * copy as much data as possible.
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200514 */
Willy Tarreau7f3225f2018-06-19 06:15:17 +0200515static 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 +0200516{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100517 struct connection *conn = __cs_conn(cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200518 size_t ret = 0;
519
Christopher Faulet897d6122021-12-17 17:28:35 +0100520 TRACE_ENTER(PT_EV_RX_DATA, conn, cs, buf, (size_t[]){count});
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200521
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200522 if (!count) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100523 cs->endp->flags |= (CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200524 goto end;
Christopher Faulet4eb7d742018-10-11 15:29:21 +0200525 }
Willy Tarreaue0f24ee2018-12-14 10:51:23 +0100526 b_realign_if_empty(buf);
Christopher Faulet897d6122021-12-17 17:28:35 +0100527 ret = conn->xprt->rcv_buf(conn, conn->xprt_ctx, buf, count, flags);
528 if (conn_xprt_read0_pending(conn)) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100529 cs->endp->flags &= ~(CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
530 cs->endp->flags |= CS_EP_EOS;
Christopher Faulet897d6122021-12-17 17:28:35 +0100531 TRACE_DEVEL("read0 on connection", PT_EV_RX_DATA, conn, cs);
Olivier Houchard8706c812018-12-04 19:17:25 +0100532 }
Christopher Faulet897d6122021-12-17 17:28:35 +0100533 if (conn->flags & CO_FL_ERROR) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100534 cs->endp->flags &= ~(CS_EP_RCV_MORE | CS_EP_WANT_ROOM);
535 cs->endp->flags |= CS_EP_ERROR;
Christopher Faulet897d6122021-12-17 17:28:35 +0100536 TRACE_DEVEL("error on connection", PT_EV_RX_DATA|PT_EV_CONN_ERR, conn, cs);
Olivier Houchard8706c812018-12-04 19:17:25 +0100537 }
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200538 end:
Christopher Faulet897d6122021-12-17 17:28:35 +0100539 TRACE_LEAVE(PT_EV_RX_DATA, conn, cs, buf, (size_t[]){ret});
Willy Tarreaud9cf5402018-07-18 11:29:06 +0200540 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200541}
542
543/* Called from the upper layer, to send data */
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200544static 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 +0200545{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100546 struct connection *conn = __cs_conn(cs);
Olivier Houchardb72d98a2018-11-30 13:17:48 +0100547 size_t ret;
548
Christopher Faulet897d6122021-12-17 17:28:35 +0100549 TRACE_ENTER(PT_EV_TX_DATA, conn, cs, buf, (size_t[]){count});
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200550
Christopher Faulet897d6122021-12-17 17:28:35 +0100551 ret = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, count, flags);
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200552
553 if (ret > 0)
554 b_del(buf, ret);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200555
Willy Tarreau413713f2022-03-31 16:47:46 +0200556 if (conn->flags & CO_FL_ERROR) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100557 cs->endp->flags |= CS_EP_ERROR;
Willy Tarreau413713f2022-03-31 16:47:46 +0200558 TRACE_DEVEL("error on connection", PT_EV_TX_DATA|PT_EV_CONN_ERR, conn, cs);
559 }
560
Christopher Faulet897d6122021-12-17 17:28:35 +0100561 TRACE_LEAVE(PT_EV_TX_DATA, conn, cs, buf, (size_t[]){ret});
Christopher Fauletd44a9b32018-07-27 11:59:41 +0200562 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200563}
564
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100565/* Called from the upper layer, to subscribe <es> to events <event_type>. The
566 * event subscriber <es> is not allowed to change from a previous call as long
567 * as at least one event is still subscribed. The <event_type> must only be a
568 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
569 */
570static int mux_pt_subscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
Olivier Houchard6ff20392018-07-17 18:46:31 +0200571{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100572 struct connection *conn = __cs_conn(cs);
Christopher Faulet897d6122021-12-17 17:28:35 +0100573
574 TRACE_POINT(PT_EV_RX_DATA|PT_EV_TX_DATA, conn, cs, 0, (size_t[]){event_type});
575 return conn->xprt->subscribe(conn, conn->xprt_ctx, event_type, es);
Olivier Houchard6ff20392018-07-17 18:46:31 +0200576}
577
Willy Tarreauee1a6fc2020-01-17 07:52:13 +0100578/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
579 * The <es> pointer is not allowed to differ from the one passed to the
580 * subscribe() call. It always returns zero.
581 */
582static int mux_pt_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200583{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100584 struct connection *conn = __cs_conn(cs);
Christopher Faulet897d6122021-12-17 17:28:35 +0100585
586 TRACE_POINT(PT_EV_RX_DATA|PT_EV_TX_DATA, conn, cs, 0, (size_t[]){event_type});
587 return conn->xprt->unsubscribe(conn, conn->xprt_ctx, event_type, es);
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200588}
589
Willy Tarreaue5733232019-05-22 19:24:06 +0200590#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200591/* Send and get, using splicing */
592static int mux_pt_rcv_pipe(struct conn_stream *cs, struct pipe *pipe, unsigned int count)
593{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100594 struct connection *conn = __cs_conn(cs);
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200595 int ret;
596
Christopher Faulet897d6122021-12-17 17:28:35 +0100597 TRACE_ENTER(PT_EV_RX_DATA, conn, cs, 0, (size_t[]){count});
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200598
Christopher Faulet897d6122021-12-17 17:28:35 +0100599 ret = conn->xprt->rcv_pipe(conn, conn->xprt_ctx, pipe, count);
600 if (conn_xprt_read0_pending(conn)) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100601 cs->endp->flags |= CS_EP_EOS;
Christopher Faulet897d6122021-12-17 17:28:35 +0100602 TRACE_DEVEL("read0 on connection", PT_EV_RX_DATA, conn, cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200603 }
Christopher Faulet897d6122021-12-17 17:28:35 +0100604 if (conn->flags & CO_FL_ERROR) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100605 cs->endp->flags |= CS_EP_ERROR;
Christopher Faulet897d6122021-12-17 17:28:35 +0100606 TRACE_DEVEL("error on connection", PT_EV_RX_DATA|PT_EV_CONN_ERR, conn, cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200607 }
608
Christopher Faulet897d6122021-12-17 17:28:35 +0100609 TRACE_LEAVE(PT_EV_RX_DATA, conn, cs, 0, (size_t[]){ret});
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200610 return (ret);
611}
612
613static int mux_pt_snd_pipe(struct conn_stream *cs, struct pipe *pipe)
614{
Christopher Faulet693b23b2022-02-28 09:09:05 +0100615 struct connection *conn = __cs_conn(cs);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200616 int ret;
617
Christopher Faulet897d6122021-12-17 17:28:35 +0100618 TRACE_ENTER(PT_EV_TX_DATA, conn, cs, 0, (size_t[]){pipe->data});
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200619
Christopher Faulet897d6122021-12-17 17:28:35 +0100620 ret = conn->xprt->snd_pipe(conn, conn->xprt_ctx, pipe);
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200621
Willy Tarreau413713f2022-03-31 16:47:46 +0200622 if (conn->flags & CO_FL_ERROR) {
Christopher Fauletb041b232022-03-24 10:27:02 +0100623 cs->endp->flags |= CS_EP_ERROR;
Willy Tarreau413713f2022-03-31 16:47:46 +0200624 TRACE_DEVEL("error on connection", PT_EV_TX_DATA|PT_EV_CONN_ERR, conn, cs);
625 }
626
Christopher Faulet897d6122021-12-17 17:28:35 +0100627 TRACE_LEAVE(PT_EV_TX_DATA, conn, cs, 0, (size_t[]){ret});
Christopher Fauletc0ae0972021-04-08 16:45:11 +0200628 return ret;
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200629}
Olivier Houchard7da120b2017-11-01 13:55:10 +0100630#endif
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200631
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200632static int mux_pt_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
633{
634 int ret = 0;
635 switch (mux_ctl) {
636 case MUX_STATUS:
Willy Tarreau911db9b2020-01-23 16:27:54 +0100637 if (!(conn->flags & CO_FL_WAIT_XPRT))
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200638 ret |= MUX_STATUS_READY;
639 return ret;
Christopher Faulet4c8ad842020-10-06 14:59:17 +0200640 case MUX_EXIT_STATUS:
641 return MUX_ES_UNKNOWN;
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200642 default:
643 return -1;
644 }
645}
646
Willy Tarreau53a47662017-08-28 10:53:00 +0200647/* The mux operations */
Christopher Faulet28da3f52021-02-05 16:44:46 +0100648const struct mux_ops mux_tcp_ops = {
Willy Tarreau53a47662017-08-28 10:53:00 +0200649 .init = mux_pt_init,
Willy Tarreau53a47662017-08-28 10:53:00 +0200650 .wake = mux_pt_wake,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200651 .rcv_buf = mux_pt_rcv_buf,
652 .snd_buf = mux_pt_snd_buf,
Olivier Houchard6ff20392018-07-17 18:46:31 +0200653 .subscribe = mux_pt_subscribe,
Olivier Houchard83a0cd82018-09-28 17:57:58 +0200654 .unsubscribe = mux_pt_unsubscribe,
Willy Tarreaue5733232019-05-22 19:24:06 +0200655#if defined(USE_LINUX_SPLICE)
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200656 .rcv_pipe = mux_pt_rcv_pipe,
657 .snd_pipe = mux_pt_snd_pipe,
658#endif
659 .attach = mux_pt_attach,
Willy Tarreaufafd3982018-11-18 21:29:20 +0100660 .get_first_cs = mux_pt_get_first_cs,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200661 .detach = mux_pt_detach,
Olivier Houchardd540b362018-11-05 18:37:53 +0100662 .avail_streams = mux_pt_avail_streams,
Willy Tarreau00f18a32019-01-26 12:19:01 +0100663 .used_streams = mux_pt_used_streams,
Olivier Houchard060ed432018-11-06 16:32:42 +0100664 .destroy = mux_pt_destroy_meth,
Olivier Houchard9b8e11e2019-10-25 16:19:26 +0200665 .ctl = mux_pt_ctl,
Olivier Houchard7a3f0df2017-09-13 18:30:23 +0200666 .shutr = mux_pt_shutr,
667 .shutw = mux_pt_shutw,
Willy Tarreau28f1cb92017-12-20 16:14:44 +0100668 .flags = MX_FL_NONE,
Willy Tarreau53a47662017-08-28 10:53:00 +0200669 .name = "PASS",
670};
Willy Tarreauf6490822017-09-21 19:43:21 +0200671
Christopher Faulet28da3f52021-02-05 16:44:46 +0100672
673const struct mux_ops mux_pt_ops = {
674 .init = mux_pt_init,
675 .wake = mux_pt_wake,
676 .rcv_buf = mux_pt_rcv_buf,
677 .snd_buf = mux_pt_snd_buf,
678 .subscribe = mux_pt_subscribe,
679 .unsubscribe = mux_pt_unsubscribe,
680#if defined(USE_LINUX_SPLICE)
681 .rcv_pipe = mux_pt_rcv_pipe,
682 .snd_pipe = mux_pt_snd_pipe,
683#endif
684 .attach = mux_pt_attach,
685 .get_first_cs = mux_pt_get_first_cs,
686 .detach = mux_pt_detach,
687 .avail_streams = mux_pt_avail_streams,
688 .used_streams = mux_pt_used_streams,
689 .destroy = mux_pt_destroy_meth,
690 .ctl = mux_pt_ctl,
691 .shutr = mux_pt_shutr,
692 .shutw = mux_pt_shutw,
693 .flags = MX_FL_NONE|MX_FL_NO_UPG,
694 .name = "PASS",
695};
696
Christopher Faulet32f61c02018-04-10 14:33:41 +0200697/* PROT selection : default mux has empty name */
Christopher Faulet28da3f52021-02-05 16:44:46 +0100698static struct mux_proto_list mux_proto_none =
699 { .token = IST("none"), .mode = PROTO_MODE_TCP, .side = PROTO_SIDE_BOTH, .mux = &mux_pt_ops };
700static struct mux_proto_list mux_proto_tcp =
701 { .token = IST(""), .mode = PROTO_MODE_TCP, .side = PROTO_SIDE_BOTH, .mux = &mux_tcp_ops };
Willy Tarreauf6490822017-09-21 19:43:21 +0200702
Christopher Faulet28da3f52021-02-05 16:44:46 +0100703INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_none);
704INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_tcp);