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 | |
| 13 | #include <common/config.h> |
| 14 | #include <proto/connection.h> |
| 15 | #include <proto/stream.h> |
| 16 | |
| 17 | /* Initialize the mux once it's attached. If conn->mux_ctx is NULL, it is |
| 18 | * assumed that no data layer has yet been instanciated so the mux is |
| 19 | * attached to an incoming connection and will instanciate a new stream. If |
| 20 | * conn->mux_ctx exists, it is assumed that it is an outgoing connection |
| 21 | * requested for this context. Returns < 0 on error. |
| 22 | */ |
| 23 | static int mux_pt_init(struct connection *conn) |
| 24 | { |
| 25 | if (!conn->mux_ctx) |
| 26 | return stream_create_from_conn(conn); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | /* callback to be used by default for the pass-through mux. It calls the data |
| 31 | * layer wake() callback if it is set otherwise returns 0. |
| 32 | */ |
| 33 | static int mux_pt_wake(struct connection *conn) |
| 34 | { |
| 35 | return conn->data->wake ? conn->data->wake(conn) : 0; |
| 36 | } |
| 37 | |
| 38 | /* callback to be used by default for the pass-through mux. It simply calls the |
| 39 | * data layer recv() callback much must be set. |
| 40 | */ |
| 41 | static void mux_pt_recv(struct connection *conn) |
| 42 | { |
| 43 | conn->data->recv(conn); |
| 44 | } |
| 45 | |
| 46 | /* callback to be used by default for the pass-through mux. It simply calls the |
| 47 | * data layer send() callback which must be set. |
| 48 | */ |
| 49 | static void mux_pt_send(struct connection *conn) |
| 50 | { |
| 51 | conn->data->send(conn); |
| 52 | } |
| 53 | |
| 54 | /* The mux operations */ |
| 55 | const struct mux_ops mux_pt_ops = { |
| 56 | .init = mux_pt_init, |
| 57 | .recv = mux_pt_recv, |
| 58 | .send = mux_pt_send, |
| 59 | .wake = mux_pt_wake, |
| 60 | .name = "PASS", |
| 61 | }; |
Willy Tarreau | f649082 | 2017-09-21 19:43:21 +0200 | [diff] [blame] | 62 | |
| 63 | /* ALPN selection : default mux has empty name */ |
| 64 | static struct alpn_mux_list alpn_mux_pt = |
| 65 | { .token = IST(""), .mode = ALPN_MODE_ANY, .mux = &mux_pt_ops }; |
| 66 | |
| 67 | __attribute__((constructor)) |
| 68 | static void __mux_pt_init(void) |
| 69 | { |
| 70 | alpn_register_mux(&alpn_mux_pt); |
| 71 | } |