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

@@ -27,6 +27,7 @@
#include <haproxy/api.h>
#include <haproxy/buf.h>
#include <haproxy/connection-t.h>
#include <haproxy/conn_stream-t.h>
#include <haproxy/fd.h>
#include <haproxy/list.h>
#include <haproxy/listener-t.h>
@@ -37,16 +38,15 @@
#include <haproxy/task-t.h>
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_sockaddr;
extern struct pool_head *pool_head_authority;
extern struct pool_head *pool_head_uniqueid;
extern struct xprt_ops *registered_xprt[XPRT_ENTRIES];
extern struct mux_proto_list mux_proto_list;
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_CS(cs) (IS_HTX_CONN((cs)->conn))
/* receive a PROXY protocol header over a connection */
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 sockaddr_storage *sockaddr_alloc(struct sockaddr_storage **sap, const struct sockaddr_storage *orig, socklen_t len);
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 */
@@ -246,58 +244,6 @@ static inline void conn_xprt_shutw_hard(struct connection *c)
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 */
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;
}
/*
* 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 1 indicating it's a backend connection. And uninitialized connection
* 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)
{
if (!conn->subs)
@@ -391,39 +310,6 @@ static inline void conn_force_unsubscribe(struct connection *conn)
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 */
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
}
/* 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)
{
if (!wl->tasklet->process) {
@@ -597,13 +476,6 @@ static inline const char *conn_get_mux_name(const struct connection *conn)
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_*) */
static inline void xprt_register(int id, struct xprt_ops *xprt)
{