REORG: conn_stream: move conn-stream stuff in dedicated files

Move code dealing with the conn-streams in dedicated files.
This commit is contained in:
Christopher Faulet 2021-12-16 17:32:56 +01:00
parent e2b38b31bb
commit 1329f2a12a
17 changed files with 340 additions and 238 deletions

View File

@ -935,7 +935,7 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/http_ana.o src/mux_h1.o \
src/base64.o src/uri_auth.o src/time.o src/ebsttree.o src/ebistree.o \ src/base64.o src/uri_auth.o src/time.o src/ebsttree.o src/ebistree.o \
src/dynbuf.o src/auth.o src/wdt.o src/pipe.o src/http_acl.o \ src/dynbuf.o src/auth.o src/wdt.o src/pipe.o src/http_acl.o \
src/hpack-huff.o src/hpack-enc.o src/dict.o src/init.o src/freq_ctr.o \ src/hpack-huff.o src/hpack-enc.o src/dict.o src/init.o src/freq_ctr.o \
src/ebtree.o src/hash.o src/dgram.o src/version.o src/ebtree.o src/hash.o src/dgram.o src/version.o src/conn_stream.o
ifneq ($(TRACE),) ifneq ($(TRACE),)
OBJS += src/calltrace.o OBJS += src/calltrace.o

View File

@ -0,0 +1,102 @@
/*
* include/haproxy/conn_stream-t.h
* This file describes the conn-stream struct and associated constants.
*
* Copyright 2021 Christopher Faulet <cfaulet@haproxy.com>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HAPROXY_CONN_STREAM_T_H
#define _HAPROXY_CONN_STREAM_T_H
#include <haproxy/obj_type-t.h>
struct connection;
/* conn_stream flags */
enum {
CS_FL_NONE = 0x00000000, /* Just for initialization purposes */
CS_FL_SHRD = 0x00000010, /* read shut, draining extra data */
CS_FL_SHRR = 0x00000020, /* read shut, resetting extra data */
CS_FL_SHR = CS_FL_SHRD | CS_FL_SHRR, /* read shut status */
CS_FL_SHWN = 0x00000040, /* write shut, verbose mode */
CS_FL_SHWS = 0x00000080, /* write shut, silent mode */
CS_FL_SHW = CS_FL_SHWN | CS_FL_SHWS, /* write shut status */
CS_FL_ERROR = 0x00000100, /* a fatal error was reported */
CS_FL_RCV_MORE = 0x00000200, /* We may have more bytes to transfer */
CS_FL_WANT_ROOM = 0x00000400, /* More bytes to transfer, but not enough room */
CS_FL_ERR_PENDING = 0x00000800, /* An error is pending, but there's still data to be read */
CS_FL_EOS = 0x00001000, /* End of stream delivered to data layer */
/* unused: 0x00002000 */
CS_FL_EOI = 0x00004000, /* end-of-input reached */
CS_FL_MAY_SPLICE = 0x00008000, /* caller may use rcv_pipe() only if this flag is set */
CS_FL_WAIT_FOR_HS = 0x00010000, /* This stream is waiting for handhskae */
CS_FL_KILL_CONN = 0x00020000, /* must kill the connection when the CS closes */
/* following flags are supposed to be set by the mux and read/unset by
* the stream-interface :
*/
CS_FL_NOT_FIRST = 0x00100000, /* this stream is not the first one */
/* flags set by the mux relayed to the stream */
CS_FL_WEBSOCKET = 0x00200000, /* websocket stream */
};
/* cs_shutr() modes */
enum cs_shr_mode {
CS_SHR_DRAIN = 0, /* read shutdown, drain any extra stuff */
CS_SHR_RESET = 1, /* read shutdown, reset any extra stuff */
};
/* cs_shutw() modes */
enum cs_shw_mode {
CS_SHW_NORMAL = 0, /* regular write shutdown */
CS_SHW_SILENT = 1, /* imminent close, don't notify peer */
};
struct conn_stream;
/* data_cb describes the data layer's recv and send callbacks which are called
* when I/O activity was detected after the transport layer is ready. These
* callbacks are supposed to make use of the xprt_ops above to exchange data
* from/to buffers and pipes. The <wake> callback is used to report activity
* at the transport layer, which can be a connection opening/close, or any
* data movement. It may abort a connection by returning < 0.
*/
struct data_cb {
int (*wake)(struct conn_stream *cs); /* data-layer callback to report activity */
char name[8]; /* data layer name, zero-terminated */
};
/*
* This structure describes the elements of a connection relevant to a stream
*/
struct conn_stream {
enum obj_type obj_type; /* differentiates connection from applet context */
/* 3 bytes hole here */
unsigned int flags; /* CS_FL_* */
struct connection *conn; /* xprt-level connection */
void *data; /* pointer to upper layer's entity (eg: stream interface) */
const struct data_cb *data_cb; /* data layer callbacks. Must be set before xprt->init() */
void *ctx; /* mux-specific context */
};
#endif /* _HAPROXY_CONN_STREAM_T_H */

View File

@ -0,0 +1,165 @@
/*
* include/haproxy/conn_stream.h
* This file contains conn-stream function prototypes
*
* Copyright 2021 Christopher Faulet <cfaulet@haproxy.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HAPROXY_CONN_STREAM_H
#define _HAPROXY_CONN_STREAM_H
#include <haproxy/api.h>
#include <haproxy/connection.h>
#include <haproxy/conn_stream-t.h>
#include <haproxy/obj_type.h>
#include <haproxy/pool-t.h>
extern struct pool_head *pool_head_connstream;
#define IS_HTX_CS(cs) (IS_HTX_CONN((cs)->conn))
struct conn_stream *cs_new(struct connection *conn, void *target);
void cs_free(struct conn_stream *cs);
/*
* Initializes all required fields for a new conn_strema.
*/
static inline void cs_init(struct conn_stream *cs, struct connection *conn)
{
cs->obj_type = OBJ_TYPE_CS;
cs->flags = CS_FL_NONE;
cs->conn = conn;
cs->ctx = conn;
}
/* Returns the conn from a cs. If cs is NULL, returns NULL */
static inline struct connection *cs_conn(const struct conn_stream *cs)
{
return cs ? cs->conn : NULL;
}
/* Attaches a conn_stream to a data layer and sets the relevant callbacks */
static inline void cs_attach(struct conn_stream *cs, void *data, const struct data_cb *data_cb)
{
cs->data_cb = data_cb;
cs->data = data;
}
/* Detach the conn_stream from the connection, if any. If a mux owns the
* connection ->detach() callback is called. Otherwise, it means the conn-stream
* owns the connection. In this case the connection is closed and released. The
* conn-stream is not released.
*/
static inline void cs_detach(struct conn_stream *cs)
{
if (cs_conn(cs)) {
if (cs->conn->mux)
cs->conn->mux->detach(cs);
else {
/* It's too early to have a mux, let's just destroy
* the connection
*/
struct connection *conn = cs->conn;
conn_stop_tracking(conn);
conn_full_close(conn);
if (conn->destroy_cb)
conn->destroy_cb(conn);
conn_free(conn);
}
}
cs_init(cs, NULL);
}
/* Release a conn_stream */
static inline void cs_destroy(struct conn_stream *cs)
{
cs_detach(cs);
cs_free(cs);
}
static inline const char *cs_get_data_name(const struct conn_stream *cs)
{
if (!cs || !cs->data_cb)
return "NONE";
return cs->data_cb->name;
}
/* shut read */
static inline void cs_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
{
if (!cs_conn(cs) || cs->flags & CS_FL_SHR)
return;
/* clean data-layer shutdown */
if (cs->conn->mux && cs->conn->mux->shutr)
cs->conn->mux->shutr(cs, mode);
cs->flags |= (mode == CS_SHR_DRAIN) ? CS_FL_SHRD : CS_FL_SHRR;
}
/* shut write */
static inline void cs_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
{
if (!cs_conn(cs) || cs->flags & CS_FL_SHW)
return;
/* clean data-layer shutdown */
if (cs->conn->mux && cs->conn->mux->shutw)
cs->conn->mux->shutw(cs, mode);
cs->flags |= (mode == CS_SHW_NORMAL) ? CS_FL_SHWN : CS_FL_SHWS;
}
/* completely close a conn_stream (but do not detach it) */
static inline void cs_close(struct conn_stream *cs)
{
cs_shutw(cs, CS_SHW_SILENT);
cs_shutr(cs, CS_SHR_RESET);
}
/* completely close a conn_stream after draining possibly pending data (but do not detach it) */
static inline void cs_drain_and_close(struct conn_stream *cs)
{
cs_shutw(cs, CS_SHW_SILENT);
cs_shutr(cs, CS_SHR_DRAIN);
}
/* sets CS_FL_ERROR or CS_FL_ERR_PENDING on the cs */
static inline void cs_set_error(struct conn_stream *cs)
{
if (cs->flags & CS_FL_EOS)
cs->flags |= CS_FL_ERROR;
else
cs->flags |= CS_FL_ERR_PENDING;
}
/* Retrieves any valid conn_stream from this connection, preferably the first
* valid one. The purpose is to be able to figure one other end of a private
* connection for purposes like source binding or proxy protocol header
* emission. In such cases, any conn_stream is expected to be valid so the
* mux is encouraged to return the first one it finds. If the connection has
* no mux or the mux has no get_first_cs() method or the mux has no valid
* conn_stream, NULL is returned. The output pointer is purposely marked
* const to discourage the caller from modifying anything there.
*/
static inline const struct conn_stream *cs_get_first(const struct connection *conn)
{
if (!conn || !conn->mux || !conn->mux->get_first_cs)
return NULL;
return conn->mux->get_first_cs(conn);
}
#endif /* _HAPROXY_CONN_STREAM_H */

View File

@ -33,6 +33,7 @@
#include <haproxy/api-t.h> #include <haproxy/api-t.h>
#include <haproxy/buf-t.h> #include <haproxy/buf-t.h>
#include <haproxy/conn_stream-t.h>
#include <haproxy/obj_type-t.h> #include <haproxy/obj_type-t.h>
#include <haproxy/port_range-t.h> #include <haproxy/port_range-t.h>
#include <haproxy/protocol-t.h> #include <haproxy/protocol-t.h>
@ -59,50 +60,6 @@ enum sub_event_type {
SUB_RETRY_SEND = 0x00000002, /* Schedule the tasklet when we can attempt to send again */ SUB_RETRY_SEND = 0x00000002, /* Schedule the tasklet when we can attempt to send again */
}; };
/* conn_stream flags */
enum {
CS_FL_NONE = 0x00000000, /* Just for initialization purposes */
CS_FL_SHRD = 0x00000010, /* read shut, draining extra data */
CS_FL_SHRR = 0x00000020, /* read shut, resetting extra data */
CS_FL_SHR = CS_FL_SHRD | CS_FL_SHRR, /* read shut status */
CS_FL_SHWN = 0x00000040, /* write shut, verbose mode */
CS_FL_SHWS = 0x00000080, /* write shut, silent mode */
CS_FL_SHW = CS_FL_SHWN | CS_FL_SHWS, /* write shut status */
CS_FL_ERROR = 0x00000100, /* a fatal error was reported */
CS_FL_RCV_MORE = 0x00000200, /* We may have more bytes to transfer */
CS_FL_WANT_ROOM = 0x00000400, /* More bytes to transfer, but not enough room */
CS_FL_ERR_PENDING = 0x00000800, /* An error is pending, but there's still data to be read */
CS_FL_EOS = 0x00001000, /* End of stream delivered to data layer */
/* unused: 0x00002000 */
CS_FL_EOI = 0x00004000, /* end-of-input reached */
CS_FL_MAY_SPLICE = 0x00008000, /* caller may use rcv_pipe() only if this flag is set */
CS_FL_WAIT_FOR_HS = 0x00010000, /* This stream is waiting for handhskae */
CS_FL_KILL_CONN = 0x00020000, /* must kill the connection when the CS closes */
/* following flags are supposed to be set by the mux and read/unset by
* the stream-interface :
*/
CS_FL_NOT_FIRST = 0x00100000, /* this stream is not the first one */
/* flags set by the mux relayed to the stream */
CS_FL_WEBSOCKET = 0x00200000, /* websocket stream */
};
/* cs_shutr() modes */
enum cs_shr_mode {
CS_SHR_DRAIN = 0, /* read shutdown, drain any extra stuff */
CS_SHR_RESET = 1, /* read shutdown, reset any extra stuff */
};
/* cs_shutw() modes */
enum cs_shw_mode {
CS_SHW_NORMAL = 0, /* regular write shutdown */
CS_SHW_SILENT = 1, /* imminent close, don't notify peer */
};
/* For each direction, we have a CO_FL_XPRT_<DIR>_ENA flag, which /* For each direction, we have a CO_FL_XPRT_<DIR>_ENA flag, which
* indicates if read or write is desired in that direction for the respective * indicates if read or write is desired in that direction for the respective
* layers. The current status corresponding to the current layer being used is * layers. The current status corresponding to the current layer being used is
@ -446,18 +403,6 @@ struct mux_stopping_data {
struct task *task; /* task woken up on soft-stop */ struct task *task; /* task woken up on soft-stop */
}; };
/* data_cb describes the data layer's recv and send callbacks which are called
* when I/O activity was detected after the transport layer is ready. These
* callbacks are supposed to make use of the xprt_ops above to exchange data
* from/to buffers and pipes. The <wake> callback is used to report activity
* at the transport layer, which can be a connection opening/close, or any
* data movement. It may abort a connection by returning < 0.
*/
struct data_cb {
int (*wake)(struct conn_stream *cs); /* data-layer callback to report activity */
char name[8]; /* data layer name, zero-terminated */
};
struct my_tcphdr { struct my_tcphdr {
uint16_t source; uint16_t source;
uint16_t dest; uint16_t dest;
@ -480,19 +425,6 @@ struct conn_src {
#endif #endif
}; };
/*
* This structure describes the elements of a connection relevant to a stream
*/
struct conn_stream {
enum obj_type obj_type; /* differentiates connection from applet context */
/* 3 bytes hole here */
unsigned int flags; /* CS_FL_* */
struct connection *conn; /* xprt-level connection */
void *data; /* pointer to upper layer's entity (eg: stream interface) */
const struct data_cb *data_cb; /* data layer callbacks. Must be set before xprt->init() */
void *ctx; /* mux-specific context */
};
/* Hash header flag reflecting the input parameters present /* Hash header flag reflecting the input parameters present
* CAUTION! Always update CONN_HASH_PARAMS_TYPE_COUNT when adding a new entry. * CAUTION! Always update CONN_HASH_PARAMS_TYPE_COUNT when adding a new entry.
*/ */

View File

@ -27,6 +27,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/buf.h> #include <haproxy/buf.h>
#include <haproxy/connection-t.h> #include <haproxy/connection-t.h>
#include <haproxy/conn_stream-t.h>
#include <haproxy/fd.h> #include <haproxy/fd.h>
#include <haproxy/list.h> #include <haproxy/list.h>
#include <haproxy/listener-t.h> #include <haproxy/listener-t.h>
@ -37,16 +38,15 @@
#include <haproxy/task-t.h> #include <haproxy/task-t.h>
extern struct pool_head *pool_head_connection; extern struct pool_head *pool_head_connection;
extern struct pool_head *pool_head_connstream;
extern struct pool_head *pool_head_conn_hash_node; extern struct pool_head *pool_head_conn_hash_node;
extern struct pool_head *pool_head_sockaddr; extern struct pool_head *pool_head_sockaddr;
extern struct pool_head *pool_head_authority; extern struct pool_head *pool_head_authority;
extern struct pool_head *pool_head_uniqueid;
extern struct xprt_ops *registered_xprt[XPRT_ENTRIES]; extern struct xprt_ops *registered_xprt[XPRT_ENTRIES];
extern struct mux_proto_list mux_proto_list; extern struct mux_proto_list mux_proto_list;
extern struct mux_stopping_data mux_stopping_data[MAX_THREADS]; extern struct mux_stopping_data mux_stopping_data[MAX_THREADS];
#define IS_HTX_CONN(conn) ((conn)->mux && ((conn)->mux->flags & MX_FL_HTX)) #define IS_HTX_CONN(conn) ((conn)->mux && ((conn)->mux->flags & MX_FL_HTX))
#define IS_HTX_CS(cs) (IS_HTX_CONN((cs)->conn))
/* receive a PROXY protocol header over a connection */ /* receive a PROXY protocol header over a connection */
int conn_recv_proxy(struct connection *conn, int flag); int conn_recv_proxy(struct connection *conn, int flag);
@ -88,8 +88,6 @@ void conn_free(struct connection *conn);
struct conn_hash_node *conn_alloc_hash_node(struct connection *conn); struct conn_hash_node *conn_alloc_hash_node(struct connection *conn);
struct sockaddr_storage *sockaddr_alloc(struct sockaddr_storage **sap, const struct sockaddr_storage *orig, socklen_t len); struct sockaddr_storage *sockaddr_alloc(struct sockaddr_storage **sap, const struct sockaddr_storage *orig, socklen_t len);
void sockaddr_free(struct sockaddr_storage **sap); void sockaddr_free(struct sockaddr_storage **sap);
void cs_free(struct conn_stream *cs);
struct conn_stream *cs_new(struct connection *conn, void *target);
/* connection hash stuff */ /* connection hash stuff */
@ -246,58 +244,6 @@ static inline void conn_xprt_shutw_hard(struct connection *c)
c->xprt->shutw(c, c->xprt_ctx, 0); c->xprt->shutw(c, c->xprt_ctx, 0);
} }
/* Returns the conn from a cs. If cs is NULL, returns NULL */
static inline struct connection *cs_conn(const struct conn_stream *cs)
{
return cs ? cs->conn : NULL;
}
/* shut read */
static inline void cs_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
{
if (!cs_conn(cs) || cs->flags & CS_FL_SHR)
return;
/* clean data-layer shutdown */
if (cs->conn->mux && cs->conn->mux->shutr)
cs->conn->mux->shutr(cs, mode);
cs->flags |= (mode == CS_SHR_DRAIN) ? CS_FL_SHRD : CS_FL_SHRR;
}
/* shut write */
static inline void cs_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
{
if (!cs_conn(cs) || cs->flags & CS_FL_SHW)
return;
/* clean data-layer shutdown */
if (cs->conn->mux && cs->conn->mux->shutw)
cs->conn->mux->shutw(cs, mode);
cs->flags |= (mode == CS_SHW_NORMAL) ? CS_FL_SHWN : CS_FL_SHWS;
}
/* completely close a conn_stream (but do not detach it) */
static inline void cs_close(struct conn_stream *cs)
{
cs_shutw(cs, CS_SHW_SILENT);
cs_shutr(cs, CS_SHR_RESET);
}
/* completely close a conn_stream after draining possibly pending data (but do not detach it) */
static inline void cs_drain_and_close(struct conn_stream *cs)
{
cs_shutw(cs, CS_SHW_SILENT);
cs_shutr(cs, CS_SHR_DRAIN);
}
/* sets CS_FL_ERROR or CS_FL_ERR_PENDING on the cs */
static inline void cs_set_error(struct conn_stream *cs)
{
if (cs->flags & CS_FL_EOS)
cs->flags |= CS_FL_ERROR;
else
cs->flags |= CS_FL_ERR_PENDING;
}
/* detect sock->data read0 transition */ /* detect sock->data read0 transition */
static inline int conn_xprt_read0_pending(struct connection *c) static inline int conn_xprt_read0_pending(struct connection *c)
@ -328,17 +274,6 @@ static inline int conn_prepare(struct connection *conn, const struct protocol *p
return ret; return ret;
} }
/*
* Initializes all required fields for a new conn_strema.
*/
static inline void cs_init(struct conn_stream *cs, struct connection *conn)
{
cs->obj_type = OBJ_TYPE_CS;
cs->flags = CS_FL_NONE;
cs->conn = conn;
cs->ctx = conn;
}
/* returns 0 if the connection is valid and is a frontend connection, otherwise /* returns 0 if the connection is valid and is a frontend connection, otherwise
* returns 1 indicating it's a backend connection. And uninitialized connection * returns 1 indicating it's a backend connection. And uninitialized connection
* also returns 1 to better handle the usage in the middle of initialization. * also returns 1 to better handle the usage in the middle of initialization.
@ -367,22 +302,6 @@ static inline void conn_set_private(struct connection *conn)
} }
} }
/* Retrieves any valid conn_stream from this connection, preferably the first
* valid one. The purpose is to be able to figure one other end of a private
* connection for purposes like source binding or proxy protocol header
* emission. In such cases, any conn_stream is expected to be valid so the
* mux is encouraged to return the first one it finds. If the connection has
* no mux or the mux has no get_first_cs() method or the mux has no valid
* conn_stream, NULL is returned. The output pointer is purposely marked
* const to discourage the caller from modifying anything there.
*/
static inline const struct conn_stream *cs_get_first(const struct connection *conn)
{
if (!conn || !conn->mux || !conn->mux->get_first_cs)
return NULL;
return conn->mux->get_first_cs(conn);
}
static inline void conn_force_unsubscribe(struct connection *conn) static inline void conn_force_unsubscribe(struct connection *conn)
{ {
if (!conn->subs) if (!conn->subs)
@ -391,39 +310,6 @@ static inline void conn_force_unsubscribe(struct connection *conn)
conn->subs = NULL; conn->subs = NULL;
} }
/* Detach the conn_stream from the connection, if any. If a mux owns the
* connection ->detach() callback is called. Otherwise, it means the conn-stream
* owns the connection. In this case the connection is closed and released. The
* conn-stream is not released.
*/
static inline void cs_detach(struct conn_stream *cs)
{
if (cs_conn(cs)) {
if (cs->conn->mux)
cs->conn->mux->detach(cs);
else {
/* It's too early to have a mux, let's just destroy
* the connection
*/
struct connection *conn = cs->conn;
conn_stop_tracking(conn);
conn_full_close(conn);
if (conn->destroy_cb)
conn->destroy_cb(conn);
conn_free(conn);
}
}
cs_init(cs, NULL);
}
/* Release a conn_stream */
static inline void cs_destroy(struct conn_stream *cs)
{
cs_detach(cs);
cs_free(cs);
}
/* Returns the source address of the connection or NULL if not set */ /* Returns the source address of the connection or NULL if not set */
static inline const struct sockaddr_storage *conn_src(struct connection *conn) static inline const struct sockaddr_storage *conn_src(struct connection *conn)
{ {
@ -540,13 +426,6 @@ static inline void conn_set_quickack(const struct connection *conn, int value)
#endif #endif
} }
/* Attaches a conn_stream to a data layer and sets the relevant callbacks */
static inline void cs_attach(struct conn_stream *cs, void *data, const struct data_cb *data_cb)
{
cs->data_cb = data_cb;
cs->data = data;
}
static inline struct wait_event *wl_set_waitcb(struct wait_event *wl, struct task *(*cb)(struct task *, void *, unsigned int), void *ctx) static inline struct wait_event *wl_set_waitcb(struct wait_event *wl, struct task *(*cb)(struct task *, void *, unsigned int), void *ctx)
{ {
if (!wl->tasklet->process) { if (!wl->tasklet->process) {
@ -597,13 +476,6 @@ static inline const char *conn_get_mux_name(const struct connection *conn)
return conn->mux->name; return conn->mux->name;
} }
static inline const char *cs_get_data_name(const struct conn_stream *cs)
{
if (!cs || !cs->data_cb)
return "NONE";
return cs->data_cb->name;
}
/* registers pointer to transport layer <id> (XPRT_*) */ /* registers pointer to transport layer <id> (XPRT_*) */
static inline void xprt_register(int id, struct xprt_ops *xprt) static inline void xprt_register(int id, struct xprt_ops *xprt)
{ {

View File

@ -26,6 +26,8 @@
#include <haproxy/applet.h> #include <haproxy/applet.h>
#include <haproxy/channel.h> #include <haproxy/channel.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/obj_type.h>
#include <haproxy/stream-t.h> #include <haproxy/stream-t.h>
#include <haproxy/stream_interface-t.h> #include <haproxy/stream_interface-t.h>

55
src/conn_stream.c Normal file
View File

@ -0,0 +1,55 @@
/*
* Conn-stream management functions
*
* Copyright 2021 Christopher Faulet <cfaulet@haproxy.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#include <haproxy/api.h>
#include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/pool.h>
//#include <haproxy/stream_interface.h>
DECLARE_POOL(pool_head_connstream, "conn_stream", sizeof(struct conn_stream));
/* Tries to allocate a new conn_stream and initialize its main fields. If
* <conn> is NULL, then a new connection is allocated on the fly, initialized,
* and assigned to cs->conn ; this connection will then have to be released
* using pool_free() or conn_free(). The conn_stream is initialized and added
* to the mux's stream list on success, then returned. On failure, nothing is
* allocated and NULL is returned.
*/
struct conn_stream *cs_new(struct connection *conn, void *target)
{
struct conn_stream *cs;
cs = pool_alloc(pool_head_connstream);
if (unlikely(!cs))
return NULL;
if (!conn) {
conn = conn_new(target);
if (unlikely(!conn)) {
cs_free(cs);
return NULL;
}
}
cs_init(cs, conn);
return cs;
}
/* Releases a conn_stream previously allocated by cs_new(), as well as any
* buffer it would still hold.
*/
void cs_free(struct conn_stream *cs)
{
pool_free(pool_head_connstream, cs);
}

View File

@ -17,6 +17,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/cfgparse.h> #include <haproxy/cfgparse.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/fd.h> #include <haproxy/fd.h>
#include <haproxy/frontend.h> #include <haproxy/frontend.h>
#include <haproxy/hash.h> #include <haproxy/hash.h>
@ -26,14 +27,14 @@
#include <haproxy/net_helper.h> #include <haproxy/net_helper.h>
#include <haproxy/proto_tcp.h> #include <haproxy/proto_tcp.h>
#include <haproxy/sample.h> #include <haproxy/sample.h>
#include <haproxy/ssl_sock.h> #include <haproxy/session.h>
#include <haproxy/stream_interface.h> #include <haproxy/stream_interface.h>
#include <haproxy/ssl_sock.h>
#include <haproxy/tools.h> #include <haproxy/tools.h>
#include <haproxy/xxhash.h> #include <haproxy/xxhash.h>
DECLARE_POOL(pool_head_connection, "connection", sizeof(struct connection)); DECLARE_POOL(pool_head_connection, "connection", sizeof(struct connection));
DECLARE_POOL(pool_head_connstream, "conn_stream", sizeof(struct conn_stream));
DECLARE_POOL(pool_head_conn_hash_node, "conn_hash_node", sizeof(struct conn_hash_node)); DECLARE_POOL(pool_head_conn_hash_node, "conn_hash_node", sizeof(struct conn_hash_node));
DECLARE_POOL(pool_head_sockaddr, "sockaddr", sizeof(struct sockaddr_storage)); DECLARE_POOL(pool_head_sockaddr, "sockaddr", sizeof(struct sockaddr_storage));
DECLARE_POOL(pool_head_authority, "authority", PP2_AUTHORITY_MAX); DECLARE_POOL(pool_head_authority, "authority", PP2_AUTHORITY_MAX);
@ -559,42 +560,6 @@ void sockaddr_free(struct sockaddr_storage **sap)
*sap = NULL; *sap = NULL;
} }
/* Releases a conn_stream previously allocated by cs_new(), as well as any
* buffer it would still hold.
*/
void cs_free(struct conn_stream *cs)
{
pool_free(pool_head_connstream, cs);
}
/* Tries to allocate a new conn_stream and initialize its main fields. If
* <conn> is NULL, then a new connection is allocated on the fly, initialized,
* and assigned to cs->conn ; this connection will then have to be released
* using pool_free() or conn_free(). The conn_stream is initialized and added
* to the mux's stream list on success, then returned. On failure, nothing is
* allocated and NULL is returned.
*/
struct conn_stream *cs_new(struct connection *conn, void *target)
{
struct conn_stream *cs;
cs = pool_alloc(pool_head_connstream);
if (unlikely(!cs))
return NULL;
if (!conn) {
conn = conn_new(target);
if (unlikely(!conn)) {
cs_free(cs);
return NULL;
}
}
cs_init(cs, conn);
return cs;
}
/* Try to add a handshake pseudo-XPRT. If the connection's first XPRT is /* Try to add a handshake pseudo-XPRT. If the connection's first XPRT is
* raw_sock, then just use the new XPRT as the connection XPRT, otherwise * raw_sock, then just use the new XPRT as the connection XPRT, otherwise
* call the xprt's add_xprt() method. * call the xprt's add_xprt() method.

View File

@ -18,6 +18,7 @@
#include <haproxy/buf.h> #include <haproxy/buf.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/dynbuf.h> #include <haproxy/dynbuf.h>
#include <haproxy/h3.h> #include <haproxy/h3.h>
#include <haproxy/http.h> #include <haproxy/http.h>

View File

@ -17,6 +17,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/cfgparse.h> #include <haproxy/cfgparse.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/errors.h> #include <haproxy/errors.h>
#include <haproxy/fcgi-app.h> #include <haproxy/fcgi-app.h>
#include <haproxy/fcgi.h> #include <haproxy/fcgi.h>

View File

@ -15,6 +15,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/cfgparse.h> #include <haproxy/cfgparse.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/h1.h> #include <haproxy/h1.h>
#include <haproxy/h1_htx.h> #include <haproxy/h1_htx.h>
#include <haproxy/h2.h> #include <haproxy/h2.h>

View File

@ -15,6 +15,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/cfgparse.h> #include <haproxy/cfgparse.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/h2.h> #include <haproxy/h2.h>
#include <haproxy/hpack-dec.h> #include <haproxy/hpack-dec.h>
#include <haproxy/hpack-enc.h> #include <haproxy/hpack-enc.h>

View File

@ -13,6 +13,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/buf.h> #include <haproxy/buf.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/pipe-t.h> #include <haproxy/pipe-t.h>
#include <haproxy/stream.h> #include <haproxy/stream.h>
#include <haproxy/task.h> #include <haproxy/task.h>

View File

@ -4,6 +4,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/dynbuf.h> #include <haproxy/dynbuf.h>
#include <haproxy/htx.h> #include <haproxy/htx.h>
#include <haproxy/pool.h> #include <haproxy/pool.h>

View File

@ -18,6 +18,7 @@
#include <haproxy/arg.h> #include <haproxy/arg.h>
#include <haproxy/channel.h> #include <haproxy/channel.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/htx.h> #include <haproxy/htx.h>
#include <haproxy/net_helper.h> #include <haproxy/net_helper.h>
#include <haproxy/pattern.h> #include <haproxy/pattern.h>

View File

@ -25,6 +25,7 @@
#include <haproxy/arg.h> #include <haproxy/arg.h>
#include <haproxy/base64.h> #include <haproxy/base64.h>
#include <haproxy/buf-t.h> #include <haproxy/buf-t.h>
#include <haproxy/conn_stream.h>
#include <haproxy/obj_type.h> #include <haproxy/obj_type.h>
#include <haproxy/openssl-compat.h> #include <haproxy/openssl-compat.h>
#include <haproxy/sample.h> #include <haproxy/sample.h>

View File

@ -39,6 +39,7 @@
#include <haproxy/check.h> #include <haproxy/check.h>
#include <haproxy/chunk.h> #include <haproxy/chunk.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/conn_stream.h>
#include <haproxy/errors.h> #include <haproxy/errors.h>
#include <haproxy/global.h> #include <haproxy/global.h>
#include <haproxy/h1.h> #include <haproxy/h1.h>