blob: 64aae14bade639573f2a4bef90b3548e9b33d0b7 [file] [log] [blame]
Willy Tarreau53a47662017-08-28 10:53:00 +02001/*
2 * Pass-through mux-demux for connections
3 *
4 * Copyright 2017 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <common/config.h>
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 */
23static 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 */
33static 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 */
41static 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 */
49static void mux_pt_send(struct connection *conn)
50{
51 conn->data->send(conn);
52}
53
54/* The mux operations */
55const 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 Tarreauf6490822017-09-21 19:43:21 +020062
63/* ALPN selection : default mux has empty name */
64static struct alpn_mux_list alpn_mux_pt =
65 { .token = IST(""), .mode = ALPN_MODE_ANY, .mux = &mux_pt_ops };
66
67__attribute__((constructor))
68static void __mux_pt_init(void)
69{
70 alpn_register_mux(&alpn_mux_pt);
71}