mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-09 20:12:54 +02:00
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:
102
include/haproxy/conn_stream-t.h
Normal file
102
include/haproxy/conn_stream-t.h
Normal 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 */
|
||||
165
include/haproxy/conn_stream.h
Normal file
165
include/haproxy/conn_stream.h
Normal 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 */
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <haproxy/api-t.h>
|
||||
#include <haproxy/buf-t.h>
|
||||
#include <haproxy/conn_stream-t.h>
|
||||
#include <haproxy/obj_type-t.h>
|
||||
#include <haproxy/port_range-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 */
|
||||
};
|
||||
|
||||
/* 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
|
||||
* 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
|
||||
@@ -446,18 +403,6 @@ struct mux_stopping_data {
|
||||
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 {
|
||||
uint16_t source;
|
||||
uint16_t dest;
|
||||
@@ -480,19 +425,6 @@ struct conn_src {
|
||||
#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
|
||||
* CAUTION! Always update CONN_HASH_PARAMS_TYPE_COUNT when adding a new entry.
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <haproxy/applet.h>
|
||||
#include <haproxy/channel.h>
|
||||
#include <haproxy/connection.h>
|
||||
#include <haproxy/conn_stream.h>
|
||||
#include <haproxy/obj_type.h>
|
||||
#include <haproxy/stream-t.h>
|
||||
#include <haproxy/stream_interface-t.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user