Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 13 | #include <haproxy/api.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 14 | #include <haproxy/buf.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 15 | #include <haproxy/connection.h> |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 16 | #include <haproxy/pipe-t.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 17 | #include <haproxy/stconn.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 18 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 19 | #include <haproxy/task.h> |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 20 | #include <haproxy/trace.h> |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 21 | |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 22 | struct mux_pt_ctx { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 23 | struct sedesc *sd; |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 24 | struct connection *conn; |
| 25 | struct wait_event wait_event; |
| 26 | }; |
| 27 | |
Willy Tarreau | 8ceae72 | 2018-11-26 11:58:30 +0100 | [diff] [blame] | 28 | DECLARE_STATIC_POOL(pool_head_pt_ctx, "mux_pt", sizeof(struct mux_pt_ctx)); |
| 29 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 30 | /* trace source and events */ |
| 31 | static void pt_trace(enum trace_level level, uint64_t mask, |
| 32 | const struct trace_source *src, |
| 33 | const struct ist where, const struct ist func, |
| 34 | const void *a1, const void *a2, const void *a3, const void *a4); |
| 35 | |
| 36 | /* The event representation is split like this : |
| 37 | * pt_ctx - internal PT context |
| 38 | * strm - application layer |
| 39 | */ |
| 40 | static const struct trace_event pt_trace_events[] = { |
| 41 | #define PT_EV_CONN_NEW (1ULL << 0) |
| 42 | { .mask = PT_EV_CONN_NEW, .name = "pt_conn_new", .desc = "new PT connection" }, |
| 43 | #define PT_EV_CONN_WAKE (1ULL << 1) |
| 44 | { .mask = PT_EV_CONN_WAKE, .name = "pt_conn_wake", .desc = "PT connection woken up" }, |
| 45 | #define PT_EV_CONN_END (1ULL << 2) |
| 46 | { .mask = PT_EV_CONN_END, .name = "pt_conn_end", .desc = "PT connection terminated" }, |
| 47 | #define PT_EV_CONN_ERR (1ULL << 3) |
| 48 | { .mask = PT_EV_CONN_ERR, .name = "pt_conn_err", .desc = "error on PT connection" }, |
| 49 | #define PT_EV_STRM_NEW (1ULL << 4) |
| 50 | { .mask = PT_EV_STRM_NEW, .name = "strm_new", .desc = "app-layer stream creation" }, |
| 51 | #define PT_EV_STRM_SHUT (1ULL << 5) |
| 52 | { .mask = PT_EV_STRM_SHUT, .name = "strm_shut", .desc = "stream shutdown" }, |
| 53 | #define PT_EV_STRM_END (1ULL << 6) |
| 54 | { .mask = PT_EV_STRM_END, .name = "strm_end", .desc = "detaching app-layer stream" }, |
| 55 | #define PT_EV_STRM_ERR (1ULL << 7) |
| 56 | { .mask = PT_EV_STRM_ERR, .name = "strm_err", .desc = "stream error" }, |
| 57 | #define PT_EV_RX_DATA (1ULL << 8) |
| 58 | { .mask = PT_EV_RX_DATA, .name = "pt_rx_data", .desc = "Rx on PT connection" }, |
| 59 | #define PT_EV_TX_DATA (1ULL << 9) |
| 60 | { .mask = PT_EV_TX_DATA, .name = "pt_tx_data", .desc = "Tx on PT connection" }, |
| 61 | |
| 62 | {} |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | static const struct name_desc pt_trace_decoding[] = { |
| 67 | #define PT_VERB_CLEAN 1 |
| 68 | { .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" }, |
| 69 | #define PT_VERB_MINIMAL 2 |
| 70 | { .name="minimal", .desc="report only h1c/h1s state and flags, no real decoding" }, |
| 71 | #define PT_VERB_SIMPLE 3 |
| 72 | { .name="simple", .desc="add request/response status line or htx info when available" }, |
| 73 | #define PT_VERB_ADVANCED 4 |
| 74 | { .name="advanced", .desc="add header fields or frame decoding when available" }, |
| 75 | #define PT_VERB_COMPLETE 5 |
| 76 | { .name="complete", .desc="add full data dump when available" }, |
| 77 | { /* end */ } |
| 78 | }; |
| 79 | |
Willy Tarreau | 6eb3d37 | 2021-04-10 19:29:26 +0200 | [diff] [blame] | 80 | static struct trace_source trace_pt __read_mostly = { |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 81 | .name = IST("pt"), |
| 82 | .desc = "Passthrough multiplexer", |
| 83 | .arg_def = TRC_ARG1_CONN, // TRACE()'s first argument is always a connection |
| 84 | .default_cb = pt_trace, |
| 85 | .known_events = pt_trace_events, |
| 86 | .lockon_args = NULL, |
| 87 | .decoding = pt_trace_decoding, |
| 88 | .report_events = ~0, // report everything by default |
| 89 | }; |
| 90 | |
| 91 | #define TRACE_SOURCE &trace_pt |
| 92 | INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); |
| 93 | |
Willy Tarreau | 32c095b | 2022-05-18 07:36:10 +0200 | [diff] [blame] | 94 | /* returns the stconn associated to the stream */ |
| 95 | static forceinline struct stconn *pt_sc(const struct mux_pt_ctx *pt) |
| 96 | { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 97 | return pt->sd->sc; |
Willy Tarreau | 32c095b | 2022-05-18 07:36:10 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 100 | static inline void pt_trace_buf(const struct buffer *buf, size_t ofs, size_t len) |
| 101 | { |
| 102 | size_t block1, block2; |
| 103 | int line, ptr, newptr; |
| 104 | |
| 105 | block1 = b_contig_data(buf, ofs); |
| 106 | block2 = 0; |
| 107 | if (block1 > len) |
| 108 | block1 = len; |
| 109 | block2 = len - block1; |
| 110 | |
| 111 | ofs = b_peek_ofs(buf, ofs); |
| 112 | |
| 113 | line = 0; |
| 114 | ptr = ofs; |
| 115 | while (ptr < ofs + block1) { |
| 116 | newptr = dump_text_line(&trace_buf, b_orig(buf), b_size(buf), ofs + block1, &line, ptr); |
| 117 | if (newptr == ptr) |
| 118 | break; |
| 119 | ptr = newptr; |
| 120 | } |
| 121 | |
| 122 | line = ptr = 0; |
| 123 | while (ptr < block2) { |
| 124 | newptr = dump_text_line(&trace_buf, b_orig(buf), b_size(buf), block2, &line, ptr); |
| 125 | if (newptr == ptr) |
| 126 | break; |
| 127 | ptr = newptr; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /* the PT traces always expect that arg1, if non-null, is of type connection |
| 132 | * (from which we can derive the pt context), that arg2, if non-null, is a |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 133 | * stream connector, and that arg3, if non-null, is a buffer. |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 134 | */ |
| 135 | static void pt_trace(enum trace_level level, uint64_t mask, const struct trace_source *src, |
| 136 | const struct ist where, const struct ist func, |
| 137 | const void *a1, const void *a2, const void *a3, const void *a4) |
| 138 | { |
| 139 | const struct connection *conn = a1; |
| 140 | const struct mux_pt_ctx *ctx = conn ? conn->ctx : NULL; |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 141 | const struct stconn *sc = a2; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 142 | const struct buffer *buf = a3; |
| 143 | const size_t *val = a4; |
| 144 | |
Christopher Faulet | 1bceee2 | 2022-03-24 10:51:08 +0100 | [diff] [blame] | 145 | if (!ctx || src->verbosity < PT_VERB_CLEAN) |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 146 | return; |
| 147 | |
| 148 | /* Display frontend/backend info by default */ |
| 149 | chunk_appendf(&trace_buf, " : [%c]", (conn_is_back(conn) ? 'B' : 'F')); |
| 150 | |
| 151 | if (src->verbosity == PT_VERB_CLEAN) |
| 152 | return; |
| 153 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 154 | if (!sc) |
| 155 | sc = pt_sc(ctx); |
Christopher Faulet | 1bceee2 | 2022-03-24 10:51:08 +0100 | [diff] [blame] | 156 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 157 | /* Display the value to the 4th argument (level > STATE) */ |
| 158 | if (src->level > TRACE_LEVEL_STATE && val) |
| 159 | chunk_appendf(&trace_buf, " - VAL=%lu", (long)*val); |
| 160 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 161 | /* Display conn and sc info, if defined (pointer + flags) */ |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 162 | chunk_appendf(&trace_buf, " - conn=%p(0x%08x)", conn, conn->flags); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 163 | chunk_appendf(&trace_buf, " sd=%p(0x%08x)", ctx->sd, se_fl_get(ctx->sd)); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 164 | if (sc) |
| 165 | chunk_appendf(&trace_buf, " sc=%p(0x%08x)", sc, sc->flags); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 166 | |
| 167 | if (src->verbosity == PT_VERB_MINIMAL) |
| 168 | return; |
| 169 | |
| 170 | /* Display buffer info, if defined (level > USER & verbosity > SIMPLE) */ |
| 171 | if (src->level > TRACE_LEVEL_USER && buf) { |
| 172 | int full = 0, max = 3000, chunk = 1024; |
| 173 | |
| 174 | /* Full info (level > STATE && verbosity > SIMPLE) */ |
| 175 | if (src->level > TRACE_LEVEL_STATE) { |
| 176 | if (src->verbosity == PT_VERB_COMPLETE) |
| 177 | full = 1; |
| 178 | else if (src->verbosity == PT_VERB_ADVANCED) { |
| 179 | full = 1; |
| 180 | max = 256; |
| 181 | chunk = 64; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | chunk_appendf(&trace_buf, " buf=%u@%p+%u/%u", |
| 186 | (unsigned int)b_data(buf), b_orig(buf), |
| 187 | (unsigned int)b_head_ofs(buf), (unsigned int)b_size(buf)); |
| 188 | |
| 189 | if (b_data(buf) && full) { |
| 190 | chunk_memcat(&trace_buf, "\n", 1); |
| 191 | if (b_data(buf) < max) |
| 192 | pt_trace_buf(buf, 0, b_data(buf)); |
| 193 | else { |
| 194 | pt_trace_buf(buf, 0, chunk); |
| 195 | chunk_memcat(&trace_buf, " ...\n", 6); |
| 196 | pt_trace_buf(buf, b_data(buf) - chunk, chunk); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 202 | static void mux_pt_destroy(struct mux_pt_ctx *ctx) |
| 203 | { |
Christopher Faulet | 5a7ca29 | 2020-11-03 09:11:43 +0100 | [diff] [blame] | 204 | struct connection *conn = NULL; |
Christopher Faulet | 39a96ee | 2019-04-08 10:52:21 +0200 | [diff] [blame] | 205 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 206 | TRACE_POINT(PT_EV_CONN_END); |
| 207 | |
Christopher Faulet | 4de1bff | 2022-04-14 11:36:41 +0200 | [diff] [blame] | 208 | /* The connection must be attached to this mux to be released */ |
| 209 | if (ctx->conn && ctx->conn->ctx == ctx) |
| 210 | conn = ctx->conn; |
Christopher Faulet | 5a7ca29 | 2020-11-03 09:11:43 +0100 | [diff] [blame] | 211 | |
Christopher Faulet | 4de1bff | 2022-04-14 11:36:41 +0200 | [diff] [blame] | 212 | tasklet_free(ctx->wait_event.tasklet); |
Christopher Faulet | 5a7ca29 | 2020-11-03 09:11:43 +0100 | [diff] [blame] | 213 | |
Christopher Faulet | 4de1bff | 2022-04-14 11:36:41 +0200 | [diff] [blame] | 214 | if (conn && ctx->wait_event.events != 0) |
| 215 | conn->xprt->unsubscribe(conn, conn->xprt_ctx, ctx->wait_event.events, |
| 216 | &ctx->wait_event); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 217 | BUG_ON(ctx->sd && !se_fl_test(ctx->sd, SE_FL_ORPHAN)); |
| 218 | sedesc_free(ctx->sd); |
Christopher Faulet | 4de1bff | 2022-04-14 11:36:41 +0200 | [diff] [blame] | 219 | pool_free(pool_head_pt_ctx, ctx); |
Christopher Faulet | 5a7ca29 | 2020-11-03 09:11:43 +0100 | [diff] [blame] | 220 | |
| 221 | if (conn) { |
Christopher Faulet | 39a96ee | 2019-04-08 10:52:21 +0200 | [diff] [blame] | 222 | conn->mux = NULL; |
| 223 | conn->ctx = NULL; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 224 | TRACE_DEVEL("freeing conn", PT_EV_CONN_END, conn); |
Christopher Faulet | 5a7ca29 | 2020-11-03 09:11:43 +0100 | [diff] [blame] | 225 | |
| 226 | conn_stop_tracking(conn); |
| 227 | conn_full_close(conn); |
Christopher Faulet | 39a96ee | 2019-04-08 10:52:21 +0200 | [diff] [blame] | 228 | if (conn->destroy_cb) |
| 229 | conn->destroy_cb(conn); |
Christopher Faulet | 39a96ee | 2019-04-08 10:52:21 +0200 | [diff] [blame] | 230 | conn_free(conn); |
| 231 | } |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Willy Tarreau | 691d503 | 2021-01-20 14:55:01 +0100 | [diff] [blame] | 234 | /* Callback, used when we get I/Os while in idle mode. This one is exported so |
| 235 | * that "show fd" can resolve it. |
| 236 | */ |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 237 | struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned int status) |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 238 | { |
| 239 | struct mux_pt_ctx *ctx = tctx; |
| 240 | |
Christopher Faulet | 1bceee2 | 2022-03-24 10:51:08 +0100 | [diff] [blame] | 241 | TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 242 | if (!se_fl_test(ctx->sd, SE_FL_ORPHAN)) { |
Olivier Houchard | ea510fc | 2019-10-18 13:56:40 +0200 | [diff] [blame] | 243 | /* There's a small race condition. |
| 244 | * mux_pt_io_cb() is only supposed to be called if we have no |
| 245 | * stream attached. However, maybe the tasklet got woken up, |
| 246 | * and this connection was then attached to a new stream. |
Olivier Houchard | 2ed389d | 2019-10-18 14:18:29 +0200 | [diff] [blame] | 247 | * If this happened, just wake the tasklet up if anybody |
| 248 | * subscribed to receive events, and otherwise call the wake |
| 249 | * method, to make sure the event is noticed. |
Olivier Houchard | ea510fc | 2019-10-18 13:56:40 +0200 | [diff] [blame] | 250 | */ |
Willy Tarreau | 7872d1f | 2020-01-10 07:06:05 +0100 | [diff] [blame] | 251 | if (ctx->conn->subs) { |
| 252 | ctx->conn->subs->events = 0; |
| 253 | tasklet_wakeup(ctx->conn->subs->tasklet); |
| 254 | ctx->conn->subs = NULL; |
Willy Tarreau | 2f2318d | 2022-05-18 10:17:16 +0200 | [diff] [blame] | 255 | } else if (pt_sc(ctx)->app_ops->wake) |
| 256 | pt_sc(ctx)->app_ops->wake(pt_sc(ctx)); |
Willy Tarreau | e68bc61 | 2022-05-27 11:23:05 +0200 | [diff] [blame] | 257 | TRACE_DEVEL("leaving waking up SC", PT_EV_CONN_WAKE, ctx->conn); |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 258 | return t; |
Olivier Houchard | ea510fc | 2019-10-18 13:56:40 +0200 | [diff] [blame] | 259 | } |
Willy Tarreau | 2ded48d | 2020-12-11 16:20:34 +0100 | [diff] [blame] | 260 | conn_ctrl_drain(ctx->conn); |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 261 | if (ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH)) { |
Christopher Faulet | e2c65ba | 2021-04-10 09:02:32 +0200 | [diff] [blame] | 262 | TRACE_DEVEL("leaving destroying pt context", PT_EV_CONN_WAKE, ctx->conn); |
Olivier Houchard | 9dce2c5 | 2019-10-18 10:59:30 +0200 | [diff] [blame] | 263 | mux_pt_destroy(ctx); |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 264 | t = NULL; |
| 265 | } |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 266 | else { |
Olivier Houchard | e179d0e | 2019-03-21 18:27:17 +0100 | [diff] [blame] | 267 | ctx->conn->xprt->subscribe(ctx->conn, ctx->conn->xprt_ctx, SUB_RETRY_RECV, |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 268 | &ctx->wait_event); |
Christopher Faulet | e2c65ba | 2021-04-10 09:02:32 +0200 | [diff] [blame] | 269 | TRACE_DEVEL("leaving subscribing for reads", PT_EV_CONN_WAKE, ctx->conn); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 270 | } |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 271 | |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 272 | return t; |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 273 | } |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 274 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 275 | /* Initialize the mux once it's attached. It is expected that conn->ctx points |
| 276 | * to the existing stream connector (for outgoing connections) or NULL (for |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 277 | * incoming ones, in which case one will be allocated and a new stream will be |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 278 | * instantiated). Returns < 0 on error. |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 279 | */ |
Christopher Faulet | 51f73eb | 2019-04-08 11:22:47 +0200 | [diff] [blame] | 280 | static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess, |
| 281 | struct buffer *input) |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 282 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 283 | struct stconn *sc = conn->ctx; |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 284 | struct mux_pt_ctx *ctx = pool_alloc(pool_head_pt_ctx); |
| 285 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 286 | TRACE_ENTER(PT_EV_CONN_NEW); |
| 287 | |
| 288 | if (!ctx) { |
| 289 | TRACE_ERROR("PT context allocation failure", PT_EV_CONN_NEW|PT_EV_CONN_END|PT_EV_CONN_ERR); |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 290 | goto fail; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 291 | } |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 292 | |
Willy Tarreau | 3c39a7d | 2019-06-14 14:42:29 +0200 | [diff] [blame] | 293 | ctx->wait_event.tasklet = tasklet_new(); |
| 294 | if (!ctx->wait_event.tasklet) |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 295 | goto fail_free_ctx; |
Willy Tarreau | 3c39a7d | 2019-06-14 14:42:29 +0200 | [diff] [blame] | 296 | ctx->wait_event.tasklet->context = ctx; |
| 297 | ctx->wait_event.tasklet->process = mux_pt_io_cb; |
Willy Tarreau | 4f6516d | 2018-12-19 13:59:17 +0100 | [diff] [blame] | 298 | ctx->wait_event.events = 0; |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 299 | ctx->conn = conn; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 300 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 301 | if (!sc) { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 302 | ctx->sd = sedesc_new(); |
| 303 | if (!ctx->sd) { |
Willy Tarreau | e68bc61 | 2022-05-27 11:23:05 +0200 | [diff] [blame] | 304 | TRACE_ERROR("SC allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn); |
Christopher Faulet | b669d68 | 2022-03-22 18:37:19 +0100 | [diff] [blame] | 305 | goto fail_free_ctx; |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 306 | } |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 307 | ctx->sd->se = ctx; |
| 308 | ctx->sd->conn = conn; |
| 309 | se_fl_set(ctx->sd, SE_FL_T_MUX | SE_FL_ORPHAN); |
Christopher Faulet | a9e8b39 | 2022-03-23 11:01:09 +0100 | [diff] [blame] | 310 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 311 | sc = sc_new_from_endp(ctx->sd, sess, input); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 312 | if (!sc) { |
Willy Tarreau | e68bc61 | 2022-05-27 11:23:05 +0200 | [diff] [blame] | 313 | TRACE_ERROR("SC allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 314 | goto fail_free_sd; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 315 | } |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 316 | TRACE_POINT(PT_EV_STRM_NEW, conn, sc); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 317 | } |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 318 | else { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 319 | if (sc_attach_mux(sc, ctx, conn) < 0) |
Christopher Faulet | 070b91b | 2022-03-31 19:27:18 +0200 | [diff] [blame] | 320 | goto fail_free_ctx; |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 321 | ctx->sd = sc->sedesc; |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 322 | } |
Willy Tarreau | 3d2ee55 | 2018-12-19 14:12:10 +0100 | [diff] [blame] | 323 | conn->ctx = ctx; |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 324 | se_fl_set(ctx->sd, SE_FL_RCV_MORE); |
Willy Tarreau | 17ccd1a | 2020-01-17 16:19:34 +0100 | [diff] [blame] | 325 | if (global.tune.options & GTUNE_USE_SPLICE) |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 326 | se_fl_set(ctx->sd, SE_FL_MAY_SPLICE); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 327 | |
Christopher Faulet | 1bceee2 | 2022-03-24 10:51:08 +0100 | [diff] [blame] | 328 | TRACE_LEAVE(PT_EV_CONN_NEW, conn); |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 329 | return 0; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 330 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 331 | fail_free_sd: |
| 332 | sedesc_free(ctx->sd); |
Christopher Faulet | a9e8b39 | 2022-03-23 11:01:09 +0100 | [diff] [blame] | 333 | fail_free_ctx: |
Tim Duesterhus | b1ec21d | 2023-04-22 17:47:32 +0200 | [diff] [blame] | 334 | tasklet_free(ctx->wait_event.tasklet); |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 335 | pool_free(pool_head_pt_ctx, ctx); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 336 | fail: |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 337 | TRACE_DEVEL("leaving in error", PT_EV_CONN_NEW|PT_EV_CONN_END|PT_EV_CONN_ERR); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 338 | return -1; |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* callback to be used by default for the pass-through mux. It calls the data |
| 342 | * layer wake() callback if it is set otherwise returns 0. |
| 343 | */ |
| 344 | static int mux_pt_wake(struct connection *conn) |
| 345 | { |
Willy Tarreau | 3d2ee55 | 2018-12-19 14:12:10 +0100 | [diff] [blame] | 346 | struct mux_pt_ctx *ctx = conn->ctx; |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 347 | int ret = 0; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 348 | |
Christopher Faulet | 1bceee2 | 2022-03-24 10:51:08 +0100 | [diff] [blame] | 349 | TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 350 | if (!se_fl_test(ctx->sd, SE_FL_ORPHAN)) { |
Willy Tarreau | 2f2318d | 2022-05-18 10:17:16 +0200 | [diff] [blame] | 351 | ret = pt_sc(ctx)->app_ops->wake ? pt_sc(ctx)->app_ops->wake(pt_sc(ctx)) : 0; |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 352 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 353 | if (ret < 0) { |
Willy Tarreau | e68bc61 | 2022-05-27 11:23:05 +0200 | [diff] [blame] | 354 | TRACE_DEVEL("leaving waking up SC", PT_EV_CONN_WAKE, ctx->conn); |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 355 | return ret; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 356 | } |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 357 | } else { |
Willy Tarreau | 2ded48d | 2020-12-11 16:20:34 +0100 | [diff] [blame] | 358 | conn_ctrl_drain(conn); |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 359 | if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) { |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 360 | TRACE_DEVEL("leaving destroying PT context", PT_EV_CONN_WAKE, ctx->conn); |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 361 | mux_pt_destroy(ctx); |
| 362 | return -1; |
| 363 | } |
| 364 | } |
Willy Tarreau | ad7f0ad | 2018-08-24 15:48:59 +0200 | [diff] [blame] | 365 | |
Olivier Houchard | 7fc96d5 | 2017-11-23 18:25:47 +0100 | [diff] [blame] | 366 | /* If we had early data, and we're done with the handshake |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 367 | * then we know the data are safe, and we can remove the flag. |
Olivier Houchard | 7fc96d5 | 2017-11-23 18:25:47 +0100 | [diff] [blame] | 368 | */ |
Willy Tarreau | 911db9b | 2020-01-23 16:27:54 +0100 | [diff] [blame] | 369 | if ((conn->flags & (CO_FL_EARLY_DATA | CO_FL_EARLY_SSL_HS | CO_FL_WAIT_XPRT)) == |
Olivier Houchard | 7fc96d5 | 2017-11-23 18:25:47 +0100 | [diff] [blame] | 370 | CO_FL_EARLY_DATA) |
| 371 | conn->flags &= ~CO_FL_EARLY_DATA; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 372 | |
| 373 | TRACE_LEAVE(PT_EV_CONN_WAKE, ctx->conn); |
Willy Tarreau | ed339a3 | 2017-11-03 15:55:24 +0100 | [diff] [blame] | 374 | return ret; |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 377 | /* |
| 378 | * Attach a new stream to a connection |
| 379 | * (Used for outgoing connections) |
| 380 | */ |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 381 | static int mux_pt_attach(struct connection *conn, struct sedesc *sd, struct session *sess) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 382 | { |
Willy Tarreau | 3d2ee55 | 2018-12-19 14:12:10 +0100 | [diff] [blame] | 383 | struct mux_pt_ctx *ctx = conn->ctx; |
Olivier Houchard | 7c6f8b1 | 2018-11-13 16:48:36 +0100 | [diff] [blame] | 384 | |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 385 | TRACE_ENTER(PT_EV_STRM_NEW, conn); |
Olivier Houchard | ea32b0f | 2019-08-10 23:56:16 +0200 | [diff] [blame] | 386 | if (ctx->wait_event.events) |
| 387 | conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 388 | if (sc_attach_mux(sd->sc, ctx, conn) < 0) |
Christopher Faulet | 070b91b | 2022-03-31 19:27:18 +0200 | [diff] [blame] | 389 | return -1; |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 390 | ctx->sd = sd; |
| 391 | se_fl_set(ctx->sd, SE_FL_RCV_MORE); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 392 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 393 | TRACE_LEAVE(PT_EV_STRM_NEW, conn, sd->sc); |
Christopher Faulet | e00ad35 | 2021-12-16 14:44:31 +0100 | [diff] [blame] | 394 | return 0; |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 395 | } |
| 396 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 397 | /* Retrieves a valid stream connector from this connection, or returns NULL. |
| 398 | * For this mux, it's easy as we can only store a single stream connector. |
Willy Tarreau | fafd398 | 2018-11-18 21:29:20 +0100 | [diff] [blame] | 399 | */ |
Willy Tarreau | d137353 | 2022-05-27 11:00:59 +0200 | [diff] [blame] | 400 | static struct stconn *mux_pt_get_first_sc(const struct connection *conn) |
Willy Tarreau | fafd398 | 2018-11-18 21:29:20 +0100 | [diff] [blame] | 401 | { |
Willy Tarreau | 3d2ee55 | 2018-12-19 14:12:10 +0100 | [diff] [blame] | 402 | struct mux_pt_ctx *ctx = conn->ctx; |
Willy Tarreau | fafd398 | 2018-11-18 21:29:20 +0100 | [diff] [blame] | 403 | |
Willy Tarreau | 32c095b | 2022-05-18 07:36:10 +0200 | [diff] [blame] | 404 | return pt_sc(ctx); |
Willy Tarreau | fafd398 | 2018-11-18 21:29:20 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Christopher Faulet | 73c1207 | 2019-04-08 11:23:22 +0200 | [diff] [blame] | 407 | /* Destroy the mux and the associated connection if still attached to this mux |
| 408 | * and no longer used */ |
| 409 | static void mux_pt_destroy_meth(void *ctx) |
Olivier Houchard | 060ed43 | 2018-11-06 16:32:42 +0100 | [diff] [blame] | 410 | { |
Christopher Faulet | 73c1207 | 2019-04-08 11:23:22 +0200 | [diff] [blame] | 411 | struct mux_pt_ctx *pt = ctx; |
Olivier Houchard | 7c6f8b1 | 2018-11-13 16:48:36 +0100 | [diff] [blame] | 412 | |
Willy Tarreau | 32c095b | 2022-05-18 07:36:10 +0200 | [diff] [blame] | 413 | TRACE_POINT(PT_EV_CONN_END, pt->conn, pt_sc(pt)); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 414 | if (se_fl_test(pt->sd, SE_FL_ORPHAN) || pt->conn->ctx != pt) { |
Christopher Faulet | 7c452cc | 2022-04-14 11:08:26 +0200 | [diff] [blame] | 415 | if (pt->conn->ctx != pt) { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 416 | pt->sd = NULL; |
Christopher Faulet | 7c452cc | 2022-04-14 11:08:26 +0200 | [diff] [blame] | 417 | } |
Christopher Faulet | 73c1207 | 2019-04-08 11:23:22 +0200 | [diff] [blame] | 418 | mux_pt_destroy(pt); |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 419 | } |
Olivier Houchard | 060ed43 | 2018-11-06 16:32:42 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 422 | /* |
Willy Tarreau | 2c52a2b | 2017-10-08 11:00:17 +0200 | [diff] [blame] | 423 | * Detach the stream from the connection and possibly release the connection. |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 424 | */ |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 425 | static void mux_pt_detach(struct sedesc *sd) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 426 | { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 427 | struct connection *conn = sd->conn; |
Christopher Faulet | 2da02ae | 2022-02-24 13:45:27 +0100 | [diff] [blame] | 428 | struct mux_pt_ctx *ctx; |
| 429 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 430 | TRACE_ENTER(PT_EV_STRM_END, conn, sd->sc); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 431 | |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 432 | ctx = conn->ctx; |
Christopher Faulet | 9ec2f4d | 2022-03-23 15:15:29 +0100 | [diff] [blame] | 433 | |
Olivier Houchard | b6c32ee | 2018-11-05 18:28:43 +0100 | [diff] [blame] | 434 | /* Subscribe, to know if we got disconnected */ |
Christopher Faulet | fbff854 | 2022-03-09 15:55:58 +0100 | [diff] [blame] | 435 | if (!conn_is_back(conn) && conn->owner != NULL && |
Olivier Houchard | 7c6f8b1 | 2018-11-13 16:48:36 +0100 | [diff] [blame] | 436 | !(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH))) { |
Olivier Houchard | e179d0e | 2019-03-21 18:27:17 +0100 | [diff] [blame] | 437 | conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 438 | } else { |
Olivier Houchard | 7c6f8b1 | 2018-11-13 16:48:36 +0100 | [diff] [blame] | 439 | /* There's no session attached to that connection, destroy it */ |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 440 | TRACE_DEVEL("killing dead connection", PT_EV_STRM_END, conn, sd->sc); |
Olivier Houchard | 7c6f8b1 | 2018-11-13 16:48:36 +0100 | [diff] [blame] | 441 | mux_pt_destroy(ctx); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | TRACE_LEAVE(PT_EV_STRM_END); |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Willy Tarreau | 00f18a3 | 2019-01-26 12:19:01 +0100 | [diff] [blame] | 447 | /* returns the number of streams in use on a connection */ |
| 448 | static int mux_pt_used_streams(struct connection *conn) |
Olivier Houchard | d540b36 | 2018-11-05 18:37:53 +0100 | [diff] [blame] | 449 | { |
Willy Tarreau | 3d2ee55 | 2018-12-19 14:12:10 +0100 | [diff] [blame] | 450 | struct mux_pt_ctx *ctx = conn->ctx; |
Olivier Houchard | d540b36 | 2018-11-05 18:37:53 +0100 | [diff] [blame] | 451 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 452 | return (!se_fl_test(ctx->sd, SE_FL_ORPHAN) ? 1 : 0); |
Olivier Houchard | d540b36 | 2018-11-05 18:37:53 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Willy Tarreau | 00f18a3 | 2019-01-26 12:19:01 +0100 | [diff] [blame] | 455 | /* returns the number of streams still available on a connection */ |
| 456 | static int mux_pt_avail_streams(struct connection *conn) |
Olivier Houchard | 8defe4b | 2018-12-02 01:31:17 +0100 | [diff] [blame] | 457 | { |
Willy Tarreau | 00f18a3 | 2019-01-26 12:19:01 +0100 | [diff] [blame] | 458 | return 1 - mux_pt_used_streams(conn); |
Olivier Houchard | 8defe4b | 2018-12-02 01:31:17 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 461 | static void mux_pt_shutr(struct stconn *sc, enum co_shr_mode mode) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 462 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 463 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 464 | struct mux_pt_ctx *ctx = conn->ctx; |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 465 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 466 | TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 467 | |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 468 | se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 469 | if (conn_xprt_ready(conn) && conn->xprt->shutr) |
| 470 | conn->xprt->shutr(conn, conn->xprt_ctx, |
Christopher Faulet | 0797656 | 2022-03-31 11:05:05 +0200 | [diff] [blame] | 471 | (mode == CO_SHR_DRAIN)); |
| 472 | else if (mode == CO_SHR_DRAIN) |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 473 | conn_ctrl_drain(conn); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 474 | if (se_fl_test(ctx->sd, SE_FL_SHW)) |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 475 | conn_full_close(conn); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 476 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 477 | TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc); |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 480 | static void mux_pt_shutw(struct stconn *sc, enum co_shw_mode mode) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 481 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 482 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 483 | struct mux_pt_ctx *ctx = conn->ctx; |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 484 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 485 | TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 486 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 487 | if (conn_xprt_ready(conn) && conn->xprt->shutw) |
| 488 | conn->xprt->shutw(conn, conn->xprt_ctx, |
Christopher Faulet | 0797656 | 2022-03-31 11:05:05 +0200 | [diff] [blame] | 489 | (mode == CO_SHW_NORMAL)); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 490 | if (!se_fl_test(ctx->sd, SE_FL_SHR)) |
Christopher Faulet | 0797656 | 2022-03-31 11:05:05 +0200 | [diff] [blame] | 491 | conn_sock_shutw(conn, (mode == CO_SHW_NORMAL)); |
Willy Tarreau | 4b79524 | 2017-10-05 18:47:38 +0200 | [diff] [blame] | 492 | else |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 493 | conn_full_close(conn); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 494 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 495 | TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc); |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Called from the upper layer, to get more data |
Christopher Faulet | 564e39c | 2021-09-21 15:50:55 +0200 | [diff] [blame] | 500 | * |
| 501 | * The caller is responsible for defragmenting <buf> if necessary. But <flags> |
| 502 | * must be tested to know the calling context. If CO_RFL_BUF_FLUSH is set, it |
| 503 | * means the caller wants to flush input data (from the mux buffer and the |
| 504 | * channel buffer) to be able to use kernel splicing or any kind of mux-to-mux |
| 505 | * xfer. If CO_RFL_KEEP_RECV is set, the mux must always subscribe for read |
| 506 | * events before giving back. CO_RFL_BUF_WET is set if <buf> is congested with |
| 507 | * data scheduled for leaving soon. CO_RFL_BUF_NOT_STUCK is set to instruct the |
| 508 | * mux it may optimize the data copy to <buf> if necessary. Otherwise, it should |
| 509 | * copy as much data as possible. |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 510 | */ |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 511 | static size_t mux_pt_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, int flags) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 512 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 513 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 514 | struct mux_pt_ctx *ctx = conn->ctx; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 515 | size_t ret = 0; |
| 516 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 517 | TRACE_ENTER(PT_EV_RX_DATA, conn, sc, buf, (size_t[]){count}); |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 518 | |
Christopher Faulet | 4eb7d74 | 2018-10-11 15:29:21 +0200 | [diff] [blame] | 519 | if (!count) { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 520 | se_fl_set(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 521 | goto end; |
Christopher Faulet | 4eb7d74 | 2018-10-11 15:29:21 +0200 | [diff] [blame] | 522 | } |
Willy Tarreau | e0f24ee | 2018-12-14 10:51:23 +0100 | [diff] [blame] | 523 | b_realign_if_empty(buf); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 524 | ret = conn->xprt->rcv_buf(conn, conn->xprt_ctx, buf, count, flags); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 525 | if (conn->flags & CO_FL_ERROR) { |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 526 | se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
Christopher Faulet | 872b01c | 2023-03-20 08:25:38 +0100 | [diff] [blame] | 527 | if (conn_xprt_read0_pending(conn)) |
| 528 | se_fl_set(ctx->sd, SE_FL_EOS); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 529 | se_fl_set(ctx->sd, SE_FL_ERROR); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 530 | TRACE_DEVEL("error on connection", PT_EV_RX_DATA|PT_EV_CONN_ERR, conn, sc); |
Olivier Houchard | 8706c81 | 2018-12-04 19:17:25 +0100 | [diff] [blame] | 531 | } |
Christopher Faulet | 872b01c | 2023-03-20 08:25:38 +0100 | [diff] [blame] | 532 | else if (conn_xprt_read0_pending(conn)) { |
| 533 | se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); |
| 534 | se_fl_set(ctx->sd, (SE_FL_EOI|SE_FL_EOS)); |
| 535 | TRACE_DEVEL("read0 on connection", PT_EV_RX_DATA, conn, sc); |
| 536 | } |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 537 | end: |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 538 | TRACE_LEAVE(PT_EV_RX_DATA, conn, sc, buf, (size_t[]){ret}); |
Willy Tarreau | d9cf540 | 2018-07-18 11:29:06 +0200 | [diff] [blame] | 539 | return ret; |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /* Called from the upper layer, to send data */ |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 543 | static size_t mux_pt_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, int flags) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 544 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 545 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 546 | struct mux_pt_ctx *ctx = conn->ctx; |
Olivier Houchard | b72d98a | 2018-11-30 13:17:48 +0100 | [diff] [blame] | 547 | size_t ret; |
| 548 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 549 | TRACE_ENTER(PT_EV_TX_DATA, conn, sc, buf, (size_t[]){count}); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 550 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 551 | ret = conn->xprt->snd_buf(conn, conn->xprt_ctx, buf, count, flags); |
Christopher Faulet | d44a9b3 | 2018-07-27 11:59:41 +0200 | [diff] [blame] | 552 | |
| 553 | if (ret > 0) |
| 554 | b_del(buf, ret); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 555 | |
Willy Tarreau | 413713f | 2022-03-31 16:47:46 +0200 | [diff] [blame] | 556 | if (conn->flags & CO_FL_ERROR) { |
Christopher Faulet | e5d02c3 | 2023-03-13 11:07:37 +0100 | [diff] [blame] | 557 | if (conn_xprt_read0_pending(conn)) |
| 558 | se_fl_set(ctx->sd, SE_FL_EOS); |
Christopher Faulet | b65af26 | 2022-10-05 11:01:56 +0200 | [diff] [blame] | 559 | se_fl_set_error(ctx->sd); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 560 | TRACE_DEVEL("error on connection", PT_EV_TX_DATA|PT_EV_CONN_ERR, conn, sc); |
Willy Tarreau | 413713f | 2022-03-31 16:47:46 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 563 | TRACE_LEAVE(PT_EV_TX_DATA, conn, sc, buf, (size_t[]){ret}); |
Christopher Faulet | d44a9b3 | 2018-07-27 11:59:41 +0200 | [diff] [blame] | 564 | return ret; |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 565 | } |
| 566 | |
Willy Tarreau | ee1a6fc | 2020-01-17 07:52:13 +0100 | [diff] [blame] | 567 | /* Called from the upper layer, to subscribe <es> to events <event_type>. The |
| 568 | * event subscriber <es> is not allowed to change from a previous call as long |
| 569 | * as at least one event is still subscribed. The <event_type> must only be a |
| 570 | * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0. |
| 571 | */ |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 572 | static int mux_pt_subscribe(struct stconn *sc, int event_type, struct wait_event *es) |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 573 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 574 | struct connection *conn = __sc_conn(sc); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 575 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 576 | TRACE_POINT(PT_EV_RX_DATA|PT_EV_TX_DATA, conn, sc, 0, (size_t[]){event_type}); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 577 | return conn->xprt->subscribe(conn, conn->xprt_ctx, event_type, es); |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Willy Tarreau | ee1a6fc | 2020-01-17 07:52:13 +0100 | [diff] [blame] | 580 | /* Called from the upper layer, to unsubscribe <es> from events <event_type>. |
| 581 | * The <es> pointer is not allowed to differ from the one passed to the |
| 582 | * subscribe() call. It always returns zero. |
| 583 | */ |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 584 | static int mux_pt_unsubscribe(struct stconn *sc, int event_type, struct wait_event *es) |
Olivier Houchard | 83a0cd8 | 2018-09-28 17:57:58 +0200 | [diff] [blame] | 585 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 586 | struct connection *conn = __sc_conn(sc); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 587 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 588 | TRACE_POINT(PT_EV_RX_DATA|PT_EV_TX_DATA, conn, sc, 0, (size_t[]){event_type}); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 589 | return conn->xprt->unsubscribe(conn, conn->xprt_ctx, event_type, es); |
Olivier Houchard | 83a0cd8 | 2018-09-28 17:57:58 +0200 | [diff] [blame] | 590 | } |
| 591 | |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 592 | #if defined(USE_LINUX_SPLICE) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 593 | /* Send and get, using splicing */ |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 594 | static int mux_pt_rcv_pipe(struct stconn *sc, struct pipe *pipe, unsigned int count) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 595 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 596 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 597 | struct mux_pt_ctx *ctx = conn->ctx; |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 598 | int ret; |
| 599 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 600 | TRACE_ENTER(PT_EV_RX_DATA, conn, sc, 0, (size_t[]){count}); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 601 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 602 | ret = conn->xprt->rcv_pipe(conn, conn->xprt_ctx, pipe, count); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 603 | if (conn->flags & CO_FL_ERROR) { |
Christopher Faulet | 872b01c | 2023-03-20 08:25:38 +0100 | [diff] [blame] | 604 | if (conn_xprt_read0_pending(conn)) |
| 605 | se_fl_set(ctx->sd, SE_FL_EOS); |
Willy Tarreau | 9e00da1 | 2022-05-27 16:17:23 +0200 | [diff] [blame] | 606 | se_fl_set(ctx->sd, SE_FL_ERROR); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 607 | TRACE_DEVEL("error on connection", PT_EV_RX_DATA|PT_EV_CONN_ERR, conn, sc); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 608 | } |
Christopher Faulet | 872b01c | 2023-03-20 08:25:38 +0100 | [diff] [blame] | 609 | else if (conn_xprt_read0_pending(conn)) { |
| 610 | se_fl_set(ctx->sd, (SE_FL_EOS|SE_FL_EOI)); |
| 611 | TRACE_DEVEL("read0 on connection", PT_EV_RX_DATA, conn, sc); |
| 612 | } |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 613 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 614 | TRACE_LEAVE(PT_EV_RX_DATA, conn, sc, 0, (size_t[]){ret}); |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 615 | return (ret); |
| 616 | } |
| 617 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 618 | static int mux_pt_snd_pipe(struct stconn *sc, struct pipe *pipe) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 619 | { |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 620 | struct connection *conn = __sc_conn(sc); |
Willy Tarreau | 7a2705f | 2022-05-10 11:21:15 +0200 | [diff] [blame] | 621 | struct mux_pt_ctx *ctx = conn->ctx; |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 622 | int ret; |
| 623 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 624 | TRACE_ENTER(PT_EV_TX_DATA, conn, sc, 0, (size_t[]){pipe->data}); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 625 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 626 | ret = conn->xprt->snd_pipe(conn, conn->xprt_ctx, pipe); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 627 | |
Willy Tarreau | 413713f | 2022-03-31 16:47:46 +0200 | [diff] [blame] | 628 | if (conn->flags & CO_FL_ERROR) { |
Christopher Faulet | e5d02c3 | 2023-03-13 11:07:37 +0100 | [diff] [blame] | 629 | if (conn_xprt_read0_pending(conn)) |
| 630 | se_fl_set(ctx->sd, SE_FL_EOS); |
Christopher Faulet | b65af26 | 2022-10-05 11:01:56 +0200 | [diff] [blame] | 631 | se_fl_set_error(ctx->sd); |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 632 | TRACE_DEVEL("error on connection", PT_EV_TX_DATA|PT_EV_CONN_ERR, conn, sc); |
Willy Tarreau | 413713f | 2022-03-31 16:47:46 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Willy Tarreau | 7577d9d | 2022-05-27 10:43:18 +0200 | [diff] [blame] | 635 | TRACE_LEAVE(PT_EV_TX_DATA, conn, sc, 0, (size_t[]){ret}); |
Christopher Faulet | c0ae097 | 2021-04-08 16:45:11 +0200 | [diff] [blame] | 636 | return ret; |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 637 | } |
Olivier Houchard | 7da120b | 2017-11-01 13:55:10 +0100 | [diff] [blame] | 638 | #endif |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 639 | |
Olivier Houchard | 9b8e11e | 2019-10-25 16:19:26 +0200 | [diff] [blame] | 640 | static int mux_pt_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output) |
| 641 | { |
| 642 | int ret = 0; |
| 643 | switch (mux_ctl) { |
| 644 | case MUX_STATUS: |
Willy Tarreau | 911db9b | 2020-01-23 16:27:54 +0100 | [diff] [blame] | 645 | if (!(conn->flags & CO_FL_WAIT_XPRT)) |
Olivier Houchard | 9b8e11e | 2019-10-25 16:19:26 +0200 | [diff] [blame] | 646 | ret |= MUX_STATUS_READY; |
| 647 | return ret; |
Christopher Faulet | 4c8ad84 | 2020-10-06 14:59:17 +0200 | [diff] [blame] | 648 | case MUX_EXIT_STATUS: |
| 649 | return MUX_ES_UNKNOWN; |
Olivier Houchard | 9b8e11e | 2019-10-25 16:19:26 +0200 | [diff] [blame] | 650 | default: |
| 651 | return -1; |
| 652 | } |
| 653 | } |
| 654 | |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 655 | /* The mux operations */ |
Christopher Faulet | 28da3f5 | 2021-02-05 16:44:46 +0100 | [diff] [blame] | 656 | const struct mux_ops mux_tcp_ops = { |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 657 | .init = mux_pt_init, |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 658 | .wake = mux_pt_wake, |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 659 | .rcv_buf = mux_pt_rcv_buf, |
| 660 | .snd_buf = mux_pt_snd_buf, |
Olivier Houchard | 6ff2039 | 2018-07-17 18:46:31 +0200 | [diff] [blame] | 661 | .subscribe = mux_pt_subscribe, |
Olivier Houchard | 83a0cd8 | 2018-09-28 17:57:58 +0200 | [diff] [blame] | 662 | .unsubscribe = mux_pt_unsubscribe, |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 663 | #if defined(USE_LINUX_SPLICE) |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 664 | .rcv_pipe = mux_pt_rcv_pipe, |
| 665 | .snd_pipe = mux_pt_snd_pipe, |
| 666 | #endif |
| 667 | .attach = mux_pt_attach, |
Willy Tarreau | d137353 | 2022-05-27 11:00:59 +0200 | [diff] [blame] | 668 | .get_first_sc = mux_pt_get_first_sc, |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 669 | .detach = mux_pt_detach, |
Olivier Houchard | d540b36 | 2018-11-05 18:37:53 +0100 | [diff] [blame] | 670 | .avail_streams = mux_pt_avail_streams, |
Willy Tarreau | 00f18a3 | 2019-01-26 12:19:01 +0100 | [diff] [blame] | 671 | .used_streams = mux_pt_used_streams, |
Olivier Houchard | 060ed43 | 2018-11-06 16:32:42 +0100 | [diff] [blame] | 672 | .destroy = mux_pt_destroy_meth, |
Olivier Houchard | 9b8e11e | 2019-10-25 16:19:26 +0200 | [diff] [blame] | 673 | .ctl = mux_pt_ctl, |
Olivier Houchard | 7a3f0df | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 674 | .shutr = mux_pt_shutr, |
| 675 | .shutw = mux_pt_shutw, |
Willy Tarreau | 28f1cb9 | 2017-12-20 16:14:44 +0100 | [diff] [blame] | 676 | .flags = MX_FL_NONE, |
Willy Tarreau | 53a4766 | 2017-08-28 10:53:00 +0200 | [diff] [blame] | 677 | .name = "PASS", |
| 678 | }; |
Willy Tarreau | f649082 | 2017-09-21 19:43:21 +0200 | [diff] [blame] | 679 | |
Christopher Faulet | 28da3f5 | 2021-02-05 16:44:46 +0100 | [diff] [blame] | 680 | |
| 681 | const struct mux_ops mux_pt_ops = { |
| 682 | .init = mux_pt_init, |
| 683 | .wake = mux_pt_wake, |
| 684 | .rcv_buf = mux_pt_rcv_buf, |
| 685 | .snd_buf = mux_pt_snd_buf, |
| 686 | .subscribe = mux_pt_subscribe, |
| 687 | .unsubscribe = mux_pt_unsubscribe, |
| 688 | #if defined(USE_LINUX_SPLICE) |
| 689 | .rcv_pipe = mux_pt_rcv_pipe, |
| 690 | .snd_pipe = mux_pt_snd_pipe, |
| 691 | #endif |
| 692 | .attach = mux_pt_attach, |
Willy Tarreau | d137353 | 2022-05-27 11:00:59 +0200 | [diff] [blame] | 693 | .get_first_sc = mux_pt_get_first_sc, |
Christopher Faulet | 28da3f5 | 2021-02-05 16:44:46 +0100 | [diff] [blame] | 694 | .detach = mux_pt_detach, |
| 695 | .avail_streams = mux_pt_avail_streams, |
| 696 | .used_streams = mux_pt_used_streams, |
| 697 | .destroy = mux_pt_destroy_meth, |
| 698 | .ctl = mux_pt_ctl, |
| 699 | .shutr = mux_pt_shutr, |
| 700 | .shutw = mux_pt_shutw, |
| 701 | .flags = MX_FL_NONE|MX_FL_NO_UPG, |
| 702 | .name = "PASS", |
| 703 | }; |
| 704 | |
Christopher Faulet | 32f61c0 | 2018-04-10 14:33:41 +0200 | [diff] [blame] | 705 | /* PROT selection : default mux has empty name */ |
Christopher Faulet | 28da3f5 | 2021-02-05 16:44:46 +0100 | [diff] [blame] | 706 | static struct mux_proto_list mux_proto_none = |
| 707 | { .token = IST("none"), .mode = PROTO_MODE_TCP, .side = PROTO_SIDE_BOTH, .mux = &mux_pt_ops }; |
| 708 | static struct mux_proto_list mux_proto_tcp = |
| 709 | { .token = IST(""), .mode = PROTO_MODE_TCP, .side = PROTO_SIDE_BOTH, .mux = &mux_tcp_ops }; |
Willy Tarreau | f649082 | 2017-09-21 19:43:21 +0200 | [diff] [blame] | 710 | |
Christopher Faulet | 28da3f5 | 2021-02-05 16:44:46 +0100 | [diff] [blame] | 711 | INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_none); |
| 712 | INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_tcp); |